From 04beb4f455a5df1633f3816651cdbfe58b6f81d4 Mon Sep 17 00:00:00 2001
From: Cameron McCormack Copyright © 2016 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
- This document is the 18 January 2016 Editor’s Draft of the
+ This document is the 10 February 2016 Editor’s Draft of the
Web IDL (Second Edition) specification.
Please send comments about this document to
@@ -3604,7 +3604,7 @@ In the ECMAScript language binding, an interface that is iterable
- will have “entries”, “keys”, “values” and @@iterator
+ will have “entries”, “forEach”, “keys”, “values” and @@iterator
properties on its interface prototype object.
@@ -3617,31 +3617,49 @@
- Prose accompanying an interface with a value iterator
- MUST define what the
- list of values to iterate over is,
- unless the interface also
- supports indexed properties,
- in which case the values of the indexed properties are implicitly
- iterated over. Prose accompanying an interface with a
+ A value iterator
+ MUST only be declared on an interface
+ that supports indexed properties
+ and has an integer-typed
+ attribute named “length”.
+ The value-type of the value iterator
+ MUST be the same as the type returned by
+ the indexed property getter.
+ A value iterator is implicitly
+ defined to iterate over the object’s indexed properties.
+
+ A pair iterator
+ MUST NOT be declared on an interface
+ that supports indexed properties.
+ Prose accompanying an interface with a
pair iterator
MUST define what the list of
value pairs to iterate over
is.
Interfaces that support indexed properties
- need to have a “length” attribute for the iterator to work correctly.
+ The ECMAScript forEach method that is generated for a
+ value iterator
+ invokes its callback like Array.prototype.forEach does, and the forEach
+ method for a pair iterator
+ invokes its callback like Map.prototype.forEach does.
+
+ Since value iterators
+ are currently allowed only on interfaces that
+ support indexed properties,
+ it makes sense to use an Array-like forEach method.
+ There may be a need for value iterators
+ (a) on interfaces that do not
+ support indexed properties,
+ or (b) with a forEach method that instead invokes its callback like
+ Set.protoype.forEach (where the key is the same as the value).
+ If you’re creating an API that needs such a forEach method, please send a request to
+ public-script-coord@w3.org.
+
- The prose is responsible for defining that the list of values
- or value pairs to iterate over is snapshotted at the time
- iteration begins, if that is desired. To handle lists that
- can change during iteration, the behavior of an
- iterator defined to to loop through the items in order, starting
- at index 0, and advancing this index on each iteration. Iteration ends when
- the index has gone past the end of the list.
- This is how array iterator objects work.
For interfaces that support indexed properties,
@@ -3677,7 +3695,7 @@
The values to iterate over
- are a snapshot of the open Session objects
+ are the open Session objects
on the SessionManager sorted by username.
- If the SessionManager interface supported indexed properties
- and had an attribute named “length”
- that reflected the number of session objects, we could avoid defining the
- values to iterate over.
-
@@ -12018,7 +12030,11 @@
- If the interface has an iterable declaration,
+ If the interface defines an indexed property getter,
+ then the Function object is %ArrayProto_values% ([ECMA-262], section 6.1.7.4).
+
+ If the interface has a pair iterator,
then the Function, when invoked,
MUST behave as follows:
- If the interface does not have an iterable declaration
- but does define an indexed property getter,
- then the Function object is %ArrayProto_values% ([ECMA-262], section 6.1.7.4).
-
If the interface has a maplike declaration
or setlike declaration,
@@ -12121,26 +12132,36 @@
- If the interface has an iterable declaration,
+ If the interface defines an indexed property getter,
+ then the Function object is
+ the initial value of the “forEach” data property of %ArrayPrototype% ([ECMA-262], section 6.1.7.4).
+
+ If the interface has a pair iterator,
then the Function MUST
have the same behavior as one that would exist assuming the interface had
this operation instead of the
iterable declaration:
with the following prose definition:
- The Function, when invoked, MUST behave as follows:
+ If the interface has a value iterator,
+ then the Function object is
+ the initial value of the “entries” data property of %ArrayPrototype% ([ECMA-262], section 6.1.7.4).
+
+ If the interface has a pair iterator,
+ then the Function, when invoked, MUST behave as follows:
- The Function, when invoked, MUST behave as follows:
+ If the interface has a value iterator,
+ then the Function object is
+ the initial value of the “keys” data property of %ArrayPrototype% ([ECMA-262], section 6.1.7.4).
+
+ If the interface has a pair iterator,
+ then the Function, when invoked, MUST behave as follows:
+ Default iterator objects are only used for pair iterators;
+ value iterators, as they are currently
+ restricted to iterating over an object’s
+ supported indexed properties,
+ use standard ECMAScript Array iterator objects.
+
When a default iterator object is first created,
its index is set to 0.
@@ -12374,8 +12416,8 @@
The iterator prototype object
for a given interface
- is an object that exists for every interface that has an
- iterable declaration. It serves as the
+ is an object that exists for every interface that has a
+ pair iterator. It serves as the
prototype for default iterator objects
for the interface.
Depending on whether prose accompanying the interface defined this to be a snapshot at the time
- iteration begins, the list of values might be different from the previous time the Web IDL (Second Edition)
W3C Editor’s Draft 18 January 2016
Web IDL (Second Edition)
W3C Editor’s Draft 10 February 2016
@@ -72,7 +72,7 @@ Status of This Document
report can be found in the W3C technical
reports index at http://www.w3.org/TR/.
3.2.7. Iterable declarations
3.2.7. Iterable declarations
value associated with the key.
3.2.7. Iterable declarations
@@ -3715,12 +3733,6 @@ 3.2.7. Iterable declarations
for (let session of sm) {
window.alert(session.username);
}4.6.9.1. @@iterator
4.6.9.1. @@iterator
for interface with object as its target and iterator kind “value”.
4.6.9.2. forEach
void forEach(Function callback, optional any thisArg = undefined);
void forEach(Function callback, optional any thisArg);
-
@@ -12233,7 +12254,13 @@
-
4.6.10.1. entries
4.6.10.2. keys
+ 4.6.10.4. Default iterator objects
4.6.10.5. Iterator prototype object
4.6.10.5. Iterator prototype object
next
- method was called on this iterator object.
-
-
@@ -12438,8 +12476,9 @@ 4.6.10.5. Iterator prototype object
-
In the ECMAScript language binding, an interface that is iterable - will have “entries”, “keys”, “values” and @@iterator + will have “entries”, “forEach”, “keys”, “values” and @@iterator properties on its interface prototype object.
@@ -3597,31 +3597,49 @@ iterable<key-type, value-type>; value associated with the key.
- Prose accompanying an interface with a value iterator - MUST define what the - list of values to iterate over is, - unless the interface also - supports indexed properties, - in which case the values of the indexed properties are implicitly - iterated over. Prose accompanying an interface with a + A value iterator + MUST only be declared on an interface + that supports indexed properties + and has an integer-typed + attribute named “length”. + The value-type of the value iterator + MUST be the same as the type returned by + the indexed property getter. + A value iterator is implicitly + defined to iterate over the object’s indexed properties. +
++ A pair iterator + MUST NOT be declared on an interface + that supports indexed properties. + Prose accompanying an interface with a pair iterator MUST define what the list of value pairs to iterate over is.
-Interfaces that support indexed properties - need to have a “length” attribute for the iterator to work correctly.
++ The ECMAScript forEach method that is generated for a + value iterator + invokes its callback like Array.prototype.forEach does, and the forEach + method for a pair iterator + invokes its callback like Map.prototype.forEach does. +
++ Since value iterators + are currently allowed only on interfaces that + support indexed properties, + it makes sense to use an Array-like forEach method. + There may be a need for value iterators + (a) on interfaces that do not + support indexed properties, + or (b) with a forEach method that instead invokes its callback like + Set.protoype.forEach (where the key is the same as the value). + If you’re creating an API that needs such a forEach method, please send a request to + public-script-coord@w3.org. +
- The prose is responsible for defining that the list of values - or value pairs to iterate over is snapshotted at the time - iteration begins, if that is desired. To handle lists that - can change during iteration, the behavior of an - iterator defined to to loop through the items in order, starting - at index 0, and advancing this index on each iteration. Iteration ends when - the index has gone past the end of the list. -
This is how array iterator objects work. For interfaces that support indexed properties, @@ -3657,7 +3675,7 @@ interface Session {
@@ -3695,12 +3713,6 @@ for (;;) { for (let session of sm) { window.alert(session.username); } -The values to iterate over - are a snapshot of the open Session objects + are the open Session objects on the SessionManager sorted by username.
- If the SessionManager interface supported indexed properties - and had an attribute named “length” - that reflected the number of session objects, we could avoid defining the - values to iterate over. -
@@ -11887,7 +11899,11 @@ interface
- If the interface has an iterable declaration, + If the interface defines an indexed property getter, + then the Function object is %ArrayProto_values%. +
++ If the interface has a pair iterator, then the Function, when invoked, MUST behave as follows:
@@ -11911,11 +11927,6 @@ interface for interface with object as its target and iterator kind “value”.- If the interface does not have an iterable declaration - but does define an indexed property getter, - then the Function object is %ArrayProto_values%. -
If the interface has a maplike declaration or setlike declaration, @@ -11990,26 +12001,36 @@ interface
- If the interface has an iterable declaration, + If the interface defines an indexed property getter, + then the Function object is + the initial value of the “forEach” data property of %ArrayPrototype%. +
++ If the interface has a pair iterator, then the Function MUST have the same behavior as one that would exist assuming the interface had this operation instead of the iterable declaration:
-with the following prose definition:
- The Function, when invoked, MUST behave as follows: + If the interface has a value iterator, + then the Function object is + the initial value of the “entries” data property of %ArrayPrototype%. +
++ If the interface has a pair iterator, + then the Function, when invoked, MUST behave as follows:
- The Function, when invoked, MUST behave as follows: + If the interface has a value iterator, + then the Function object is + the initial value of the “keys” data property of %ArrayPrototype%. +
++ If the interface has a pair iterator, + then the Function, when invoked, MUST behave as follows:
+ Default iterator objects are only used for pair iterators; + value iterators, as they are currently + restricted to iterating over an object’s + supported indexed properties, + use standard ECMAScript Array iterator objects. +
+When a default iterator object is first created, its index is set to 0. @@ -12243,8 +12285,8 @@ interface
The iterator prototype object for a given interface - is an object that exists for every interface that has an - iterable declaration. It serves as the + is an object that exists for every interface that has a + pair iterator. It serves as the prototype for default iterator objects for the interface.
@@ -12277,29 +12319,25 @@ interfaceDepending on whether prose accompanying the interface defined this to be a snapshot at the time
- iteration begins, the list of values might be different from the previous time the next
- method was called on this iterator object.