Side navigation
#6788 closed bug (invalid)
Opened July 13, 2010 10:29AM UTC
Closed October 26, 2010 05:26PM UTC
Last modified November 12, 2010 02:05AM UTC
getWH is a function declared as a statement
Reported by: | saurik | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.4.3 |
Component: | css | Version: | 1.4.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In css() there is a function, getWH, that is defined using a "function statement" (it isn't a normal function declaration as it is declared inside of an if statement, which the ECMA specification doesn't directly allow). The behavior in this situation is undefined (but, of course, every implementation of JavaScript does something reasonably sane, so you don't normally notice, which sucks).
That said, implementations do handle this situation differently: while most treat them as declarations from the enclosing function/program scope (and thereby get the somewhat weird behavior that the last one, even if never "executed", is the one that is bound to the name), FireFox treats them as part of the control flow (and thereby will rebind the name as it runs into these statements while executing, which is also surprising as this is not how declarations normally work).
So, while jQuery's usage happens to not trigger any of these behavior differences, it seems weird not to just move the function to the enclosing scope and just be clear of these issues (and also not get warnings with tools designed to detect these types of ECMA compliance bugs).
Attachments (0)
Change History (2)
Changed October 26, 2010 05:26PM UTC by comment:1
priority: | → undecided |
---|---|
resolution: | → invalid |
status: | new → closed |
Changed November 12, 2010 02:05AM UTC by comment:2
As I explain at https://mail.mozilla.org/pipermail/es-discuss/2010-November/012146.html, this will break on those ES5/strict implementations that follow the best practice explained at http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls , as, for example, the WebKit nightlies already do (Safari Version 5.0.1 (5533.17.8, r71806)).
getWH() is a function declaration on line 269 of src/css.js