Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6788 closed bug (invalid)

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:


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).

Change History (2)

comment:1 Changed 12 years ago by Rick Waldron

Priority: undecided
Resolution: invalid
Status: newclosed

getWH() is a function declaration on line 269 of src/css.js

comment:2 Changed 12 years ago by [email protected]

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)).

Note: See TracTickets for help on using tickets.