for-of loops, IteratorClose and the rest of the iterations in the spec

Boris Zbarsky bzbarsky at mit.edu
Wed Sep 10 13:23:23 PDT 2014


On 9/10/14, 4:11 PM, Allen Wirfs-Brock wrote:
> In practice (because of for-of semantics) Iterators need to be Iterables
> that return themselves as the associated iterator.  All built-in
> iterators in ES have this characteristic

Ah, I see.  But that's observably different from just doing the loop 
manually, since someone can change things like %ArrayIteratorPrototype% 
[@@iterator], right?

> For example, Array.from does that kind of argument discrimination:
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from

Yes, I'm aware.  I was looking at that earlier today while writing up 
<https://github.com/heycam/webidl/pull/18>.

It slightly differs from what the outcome of the Web IDL discussion was 
in that it commits to an iterator if CheckIterable returns anything 
other than undefined, whereas the outcome of the thread I linked earlier 
was that we want to commit if CheckIterable returns a callable...  It 
_would_ make some sense to align the two; at this point I can't recall 
why it was we decided to do the callable check in the IDL version, nor 
do I know why the ES spec decided to not do a callable check in this 
situation.

Other than that, I basically copied what Array.from/TypedArrayFrom does, 
yes.  Including the not calling IteratorClose bit.  ;)

-Boris


More information about the es-discuss mailing list