<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>28978</bug_id>
          
          <creation_ts>2015-07-20 20:40:32 +0000</creation_ts>
          <short_desc>The order of forEach() parameters for iterable declaration is inconsistent with other definitions</short_desc>
          <delta_ts>2019-02-28 14:28:58 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>WebIDL</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="David Dorwin">ddorwin</reporter>
          <assigned_to name="Cameron McCormack">cam</assigned_to>
          <cc>mike</cc>
    
    <cc>Ms2ger</cc>
    
    <cc>public-script-coord</cc>
    
    <cc>watsonm</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>122237</commentid>
    <comment_count>0</comment_count>
    <who name="David Dorwin">ddorwin</who>
    <bug_when>2015-07-20 20:40:32 +0000</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126629</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2016-05-31 15:10:41 +0000</bug_when>
    <thetext>It looks like this issue has been solved in the draft at https://heycam.github.io/webidl/#es-forEach.

Should this bug be closed ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126650</commentid>
    <comment_count>2</comment_count>
    <who name="David Dorwin">ddorwin</who>
    <bug_when>2016-06-02 19:21:15 +0000</bug_when>
    <thetext>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 &quot;value, key, this&quot;.

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

The corresponding algorithm now says, &quot;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.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129581</commentid>
    <comment_count>3</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2019-02-28 14:28:58 +0000</bug_when>
    <thetext>Current status:

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

    </bug>

</bugzilla>