blog
discuss
releases
documentation

Development Blog

javascript.options.strict and performance

I fought another javascript.options.strict problem:

  • Issue 2288: FB hangs and raises CPU to 100% due to getStyleSheetByHref

In case you don’t know, javascript.options.strict is supposed to warn you about problems in your code.  Unfortunately it also warns you about non-problems in you code.  In the particular case above, this line of Firebug code was causing the warning:

return context.styleSheetMap[url];

The intent of this line is clear: return the entry of the styleSheetMap at the key url and if the map has no entry there, return undefined. But the strict option does not like this javascript idiom and reports a warning if the function returns undefined.

(The line above is dubious but for a completely different reason: if the url were accidentally equal to a built-in property of javascript objects, then the function would return an incorrect value).

The bug here is that the strict option has no scope controls and no selection controls: once you turn it on, it applies to the entire browser and all of its rules are active.  So all of Firebug’s warnings and all warnings from other AJAX pages get mixed with the warnings from your web page. And the overhead of processing these warnings can be quite high. I recommend that you set javascript.options.strict false using url about:config or Firebug Console panel option “Strict Warnings” (unchecked).

If you like these kinds of extra checks on your code, take a look at JSLint.  It is well supported, well documented, has lots of options and different ways of setting them, and it can be applied to just the code in your page.

jjb

Please post followups in the newsgroup.

Comments are closed.