This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28978 - The order of forEach() parameters for iterable declaration is inconsistent with other definitions
Summary: The order of forEach() parameters for iterable declaration is inconsistent wi...
Status: RESOLVED WORKSFORME
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-20 20:40 UTC by David Dorwin
Modified: 2019-02-28 14:28 UTC (History)
4 users (show)

See Also:


Attachments

Description David Dorwin 2015-07-20 20:40:32 UTC
In the forEach section [1], Step 9.3 of the “If the interface has a maplike declaration or setlike declaration...” algorithm says “Call the [[Call]] internal method of callbackFn with thisArg as thisArgument and v, k and object as argumentsList.” This value followed by key ordering is consistent with ES6 Map [2] and Array [3].

However, step 4.2 of the “If the interface has an iterable declaration...” algorithm says to “Invoke callback with thisArg as the callback this value and k and value as its arguments.” This would appear to cause the opposite order of parameters being passed to the callback. Is this intentional?

Also, [4] says “If two type parameters are given, then the interface has a pair iterator and provides value pairs, where the first value is a key and the second is the value associated with the key.” Thus, the “value” passed to the interface is [key, value], which is similarly inconsistent.

My interpretation of the current text is that forEach() callbacks would receive the following parameters based on the declaration type:
* For maplike declarations: (somevalue, somekey)
* For iterable declarations with a single type parameter: (index_k, somevalue)
* For iterable declarations with two type parameters: (index_k, [somekey, somevalue])

It would seem more consistent (and correct for ECMAScript language binding?) for the callback for iterable’s forEach() to receive the following instead:
* For iterable declarations with a single type parameter: (somevalue, index_k)
* For iterable declarations with two type parameters: ([somevalue, somekey], index_k).

[1] http://heycam.github.io/webidl/#es-forEach
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach#Description
[3] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
[4] https://heycam.github.io/webidl/#dfn-pair-iterator
Comment 1 Mark Watson 2016-05-31 15:10:41 UTC
It looks like this issue has been solved in the draft at https://heycam.github.io/webidl/#es-forEach.

Should this bug be closed ?
Comment 2 David Dorwin 2016-06-02 19:21:15 UTC
These issues were discussed in https://lists.w3.org/Archives/Public/public-script-coord/2015OctDec/0039.html. For pair iterators, there was agreement to use "value, key, this".

I believe the "If the interface has an iterable declaration..." text has been replaced with "If the interface has a pair iterator..."

The corresponding algorithm now says, "Invoke callback with thisArg (or undefined, if the argument was not supplied) as the callback this value and value, key and O as its arguments."
Comment 3 Ms2ger 2019-02-28 14:28:58 UTC
Current status:

* For iterable declarations with a single type parameter (interface defines an indexed property getter): uses Array.prototype.forEach => (value, index, object).
* For iterable declarations with two type parameters: (value, key, object).
* For maplike declarations: uses Map.prototype.forEach => (value, key, object).
* For setlike declarations: uses Set.prototype.forEach => (value, value, object).