[Webkit-unassigned] [Bug 65546] function statements are evaluated even if enclosed in a not-executed code block (see #27226)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Aug 3 13:18:47 PDT 2011


https://bugs.webkit.org/show_bug.cgi?id=65546


Oliver Hunt <oliver at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID




--- Comment #1 from Oliver Hunt <oliver at apple.com>  2011-08-03 13:18:47 PST ---
Okay, so the basic problem here is that ES3 states (quite clearly) that a function statement is not allowed anywhere other than the root scope of a function/global code/eval code block, and yet for compatibility reasons we acquired it.  Couple this with the spec defined behavior of hoisting all function statements (rather than just the declarations) and you get our current behavior.  For the most part this matches IE, I believe V8 also takes this approach.

So in the world of ES3 we got into this awkward situation.  We tried to rectify this in ES5, but it turns out that there are sites that depend on our current behavior in some browsers, and depend on firefox's behavior in others.  It turned out to be such a mess that we determined it impossible to spec a standard behavior for this that would ever be adopted.  ES implementations that currently perform function hoisting can't change to not hoist, because we will break content that currently works in them.  Likewise ES implementations that currently don't hoist for exactly the same reason.

The ES5 spec actually goes out of its way to acknowledge this:
"NOTE Several widely used implementations of ECMAScript are known to support the use of FunctionDeclaration as a Statement. However there are significant and irreconcilable variations among the implementations in the semantics applied to such FunctionDeclarations. Because of these irreconcilable differences, the use of a FunctionDeclaration as a Statement results in code that is not reliably portable among implementations. It is recommended that ECMAScript implementations either disallow this usage of FunctionDeclaration or issue a warning when such a usage is encountered. Future editions of ECMAScript may define alternative portable means for declaring functions in a Statement context." (Section 12 of ES5)

JSC explicitly prevents nested function declarations entirely in strict mode.

TLDR; yes this is an annoying incompatibility, but we can change our behavior or we break existing content.  Yes it sucks.  Use strict mode.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list