Bug Tracker

Modify

Ticket #6788 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

Change History

comment:1 Changed 3 years ago by rwaldron

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to invalid

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

comment:2 Changed 3 years ago by erights@…

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.