No subject


Thu Feb 11 18:09:36 PST 2010


common pattern for using for-in uses the enumerated key to look up the
corresponding value on the object being enumerated (e.g., "obj[k]" above), I
think that the more useful interpretation is the one currently employed by
TraceMonkey and SES5/3.

I think a clarification of this issue be added to the ES5 errata. I propose
that this clarification adopt the more useful suppression behavior, and
suggest that ES5 implementations in progress switch to that behavior.
Whichever disambiguation is adopted, I'll be happy to file bugs against the
implementations with the non-conforming behavior. We should also add a test
for this to es5conform.

-- 
    Cheers,
    --MarkM

--0016e659f9f80b98150484e98915
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div><div>Mike Stay (cc&#39;ed) noticed the following ambiguity:</div><div>=
<br></div><div>What should the following print?</div><div><br></div><div>=
=A0=A0 =A0var base =3D {x:8};</div><div>=A0=A0 =A0function showProps(obj) {=
=A0</div><div>=A0=A0 =A0 =A0var result =3D [];=A0</div>
<div>=A0=A0 =A0 =A0for (var k in obj) {=A0</div><div>=A0=A0 =A0 =A0 =A0resu=
lt.push(k, &#39;: &#39;, &#39;&#39;+obj[k], &#39;\n&#39;);=A0</div><div>=A0=
=A0 =A0 =A0}=A0</div><div>=A0=A0 =A0 =A0return result.join(&#39;&#39;);=A0<=
/div><div>=A0=A0 =A0}</div><div>=A0=A0 =A0var derived =3D Object.create(bas=
e, {x: {value: 9, enumerable: false}});</div>
<div>=A0=A0 =A0showProps(derived);</div></div><div><br></div><div>Of curren=
t ES5 implementations in progress,</div><div><br></div><div>* TraceMonkey a=
nd SES5/3 (Mike Stay&#39;s emulation of the Secure subset of EcmaScript 5 s=
trict on current ES3R browsers) currently gives</div>
<div>=A0=A0 =A0 the empty string,=A0</div><div>=A0=A0meaning that the non-e=
numerable &quot;x&quot; in derived shadows the enumerable &quot;x&quot; fro=
m base.</div><div><br></div><div>* WebKit nightly and V8 currently gives</d=
iv><div>
=A0=A0 =A0&quot;x: 9&quot;</div><div>=A0=A0meaning that the enumerable &quo=
t;x&quot; from base shows through, causing the above loop to look up the va=
lue of the unenumerable shadowing &quot;x&quot; property.</div><div><br></d=
iv><div>
I have not tested any other partial ES5 implementations (Rhino, ObjectPasca=
l, ??).</div><div><br></div><div><br></div><div>The relevant test seems to =
be ES5 section 12.6.4 step 6.a (and likewise 7.a for the next production):<=
/div>
<div><br></div><div>=A0=A0 =A0 =A0Let P be the name of the next property of=
 obj whose [[Enumerable]] attribute is true.</div><div><br></div><div>From =
this text, I think either interpretation is possible. However, since a comm=
on pattern for using for-in uses the enumerated key to look up the correspo=
nding value on the object being enumerated (e.g., &quot;obj[k]&quot; above)=
, I think that the more useful interpretation is the one currently employed=
 by TraceMonkey and SES5/3.=A0</div>
<div><br></div><div>I think a clarification of this issue be added to the E=
S5 errata. I propose that this clarification adopt the more useful suppress=
ion behavior, and suggest that ES5 implementations in progress switch to th=
at behavior. Whichever disambiguation is adopted, I&#39;ll be happy to file=
 bugs against the implementations with the non-conforming behavior. We shou=
ld also add a test for this to es5conform.</div>
<br>-- <br>=A0 =A0 Cheers,<br>=A0 =A0 --MarkM<br>

--0016e659f9f80b98150484e98915--


More information about the es-discuss mailing list