On Aug 9, 2015, at 2:34 PM, Yusuke SUZUKI wrote:

> Hi forks,
> 
> Recently, we implemented Reflect.enumerate in WebKit JSC.
> At that time, the question is raised "When are the enumerated keys 
> determined?"[1]
> 
> For example,
> 
> var object = ...;
> var iterator = Reflect.enumerate(object);
> object.newKey = "hello";
> // At that time, iterator.next() is not called yet.
> for (var key of iterator) {
>     print(key);   // Here, "newKey" should be produced or not?
> }
> 
> Seeing the spec, I think it's a little bit ambiguous. (correct?)

The ES6 spec. text for ordinary object [[Enumerate]] [2] was directly derived 
from the ES5.1 spec. text for the for-in statement [3]. The  ES5.1 spec. text 
is a minor elaboration upon the corresponding text in the E3 spec. In ES3 and 
ES5 many details of for-in processing were left unspecified (ie, implementation 
dependent) because that reflected the reality of web browsers and it did not 
seem feasible at that time to force browsers to change their for-in 
implementations.

ES6 moved part of the for-in enumeration into the [[Enumerate]] internal method 
and and added some additional semantic requirements.  But it also did not 
change the policy established in the previous editions of not fully specifying 
the semantics.  This decisions could certainly be revisited for future 
editions. My sense is that a fully specified for-in/[[Enumerate]] would have a 
better chance of finding acceptance today, than it would have in the past.

> In the current WebKit implementation, keys are cached when the iterator is 
> created.
> 
> Does this violate the spec behavior, "The iterator’s next method processes 
> object properties to determine whether the property key should be returned as 
> an iterator value. "?

This sounds like it is a valid implementation.  The quoted sentence was not 
intended to imply that nothing happens until the first `next` method call.

> 
> Or, is it implementation dependent because "If new properties are added to 
> the target object during enumeration, the newly added properties are not 
> guaranteed to be processed in the active enumeration."?
> 
> And is the creation of the iterator by calling [[Enumerate]] included in 
> "active enumeration"?

The "active enumeration" was intended to start with the the call to 
[[Enumerate]].  
> 
> 
> [1]: https://bugs.webkit.org/show_bug.cgi?id=147677
> 
> Best regards,
> Yusuke Suzuki

Allen

[2]: 
http://ecma-international.org/ecma-262/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-enumerate
 
[3]: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4 

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to