What does "as if by the expression" mean in ES3?
On Jun 19, 2008, at 5:14 PM, Mark S. Miller wrote:
For example, in ES3
11.1.4 Array Initializer ...
- Create a new array as if by the expression new Array(). ...
The phrase "as if by the expression" followed by a literal snippet of code occurs repeatedly in ES3.
Did you see my message of 16 June, 10:50am?
mail.mozilla.org/pipermail/es4-discuss/2008-June/003020.html
I know that ES4 prevents assignment to the various global variable names used by such code, but what about shadowing lexical variable definitions?
The wiki page, again, is:
ES4 has gone with memoized original values and immutable type
bindings, not name lookup with shadowing hazards, for a long time now.
FF 2.0.0.14 on squarefree does seem to obey the literal reading of the ES3 spec -- that shadowing affects array and object literals:
(function foo(){ function Array(){return Date;} function Object(){return window;} return new window.Array([1,2],{bar:3}); })(); function Date() { [native code] },[object Window]
Yes, SpiderMonkey followed ES3, as did other implementations, for
many years. Try Firefox 3, it's out now and it uses the memoized
original value. :-)
Safari literals are not affected by such shadowing definitions. Which behavior does ES4 consider correct?
Lars wrote a spec and iterated on it in this list. Here's the third
and (AFAIK) stable draft:
mail.mozilla.org/pipermail/es4-discuss/2008-April/002668.html
It too says
Unlike the case in ES3, the program can't shadow the binding for
Object in order to invoke an alternative object constructor for
object initializers.
NOTE Though ES4 is incompatible with ES3 here, most real-world
implementations of ES3 do not respect shadowing binding for Object
when evaluating object initializers, and the incompatibility is of no
consequence. See [8].
I know there's a lot of material to go through, between ES3, ES4
drafts, and so on -- but it seems like we've been over this topic a
lot, and recently too. In particular in my reply to you of three days
ago :-/.
On Thu, Jun 19, 2008 at 5:36 PM, Brendan Eich <brendan at mozilla.org> wrote:
On Jun 19, 2008, at 5:14 PM, Mark S. Miller wrote:
For example, in ES3
11.1.4 Array Initializer ...
- Create a new array as if by the expression new Array(). ...
The phrase "as if by the expression" followed by a literal snippet of code occurs repeatedly in ES3.
Did you see my message of 16 June, 10:50am?
mail.mozilla.org/pipermail/es4-discuss/2008-June/003020.html
I did see that message, but it doesn't bear on lexical shadowing. Your example there replaces the global binding rather than shadowing it. Did I miss something?
I know that ES4 prevents assignment to the various global variable names used by such code, but what about shadowing lexical variable definitions?
The wiki page, again, is:
Yup, that's what I missed. Thanks. That page nowhere says "lexical", "nest", or "shadow" so it hadn't occurred to me that it bore on this issue.
ES4 has gone with memoized original values and immutable type bindings, not name lookup with shadowing hazards, for a long time now.
Good. That's what I was hoping you'd say ;).
FF 2.0.0.14 on squarefree does seem to obey the literal reading of the ES3 spec -- that shadowing affects array and object literals:
(function foo(){ function Array(){return Date;} function Object(){return window;} return new window.Array([1,2],{bar:3}); })(); function Date() { [native code] },[object Window]
Yes, SpiderMonkey followed ES3, as did other implementations, for many years. Try Firefox 3, it's out now and it uses the memoized original value. :-)
Wonderful!
Safari literals are not affected by such shadowing definitions. Which behavior does ES4 consider correct?
Lars wrote a spec and iterated on it in this list. Here's the third and (AFAIK) stable draft:
mail.mozilla.org/pipermail/es4-discuss/2008-April/002668.html
It too says
Unlike the case in ES3, the program can't shadow the binding for Object in order to invoke an alternative object constructor for object initializers.
NOTE Though ES4 is incompatible with ES3 here, most real-world implementations of ES3 do not respect shadowing binding for Object when evaluating object initializers, and the incompatibility is of no consequence. See [8].
I know there's a lot of material to go through, between ES3, ES4 drafts, and so on -- but it seems like we've been over this topic a lot, and recently too. In particular in my reply to you of three days ago :-/.
Thanks for your patience. And thanks especially for arriving at the right decision on this matter. I agree that the resulting incompatibilities in this case are unlikely to be of any consequence.
On Jun 19, 2008, at 8:00 PM, Mark S. Miller wrote:
Yup, that's what I missed. Thanks. That page nowhere says "lexical", "nest", or "shadow" so it hadn't occurred to me that it bore on this issue.
The issue came up when discussing the "origin value of
Object.prototype" vs. "as if by the expression new Object", etc., but
I failed to note it in the "which prototype" page -- sorry, I thought
I had done that. Shadowing is mentioned in several places, including
this ticket:
bugs.ecmascript.org/ticket/164
And of course the Object Literals spec.
For example, in ES3
11.1.4 Array Initializer ...
The phrase "as if by the expression" followed by a literal snippet of code occurs repeatedly in ES3. I know that ES4 prevents assignment to the various global variable names used by such code, but what about shadowing lexical variable definitions? FF 2.0.0.14 on squarefree does seem to obey the literal reading of the ES3 spec -- that shadowing affects array and object literals:
(function foo(){ function Array(){return Date;} function Object(){return window;} return new window.Array([1,2],{bar:3}); })(); function Date() { [native code] },[object Window]
Safari literals are not affected by such shadowing definitions. Which behavior does ES4 consider correct?