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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>17296</bug_id>
          
          <creation_ts>2008-02-10 15:07:46 -0800</creation_ts>
          <short_desc>forEach does not work with document.querySelectorAll</short_desc>
          <delta_ts>2024-03-17 09:30:05 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</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>0</everconfirmed>
          <reporter name="Richard York">richard</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>70143</commentid>
    <comment_count>0</comment_count>
    <who name="Richard York">richard</who>
    <bug_when>2008-02-10 15:07:46 -0800</bug_when>
    <thetext>forEach does not work with document.querySelectorAll().

The following,

document.querySelectorAll(&apos;body&apos;).forEach(
  function ($node) {

  }
);

Throws:

Value undefined (result of expression document.querySelectorAll(&quot;body&quot;).forEach) is not object.

Tried this today in the latest nightly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70146</commentid>
    <comment_count>1</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2008-02-10 15:14:57 -0800</bug_when>
    <thetext>This is not expected to work as querySelectorAll returns a StaticNodeList, not an Array.  StaticNodeList does not have a forEach method.  A work around would be to use Array.prototype.forEach.call.

Richard, why did you expect this to work?  Does it work in other implementations?  Should we consider adding it?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70152</commentid>
    <comment_count>2</comment_count>
    <who name="Richard York">richard</who>
    <bug_when>2008-02-10 15:35:30 -0800</bug_when>
    <thetext>Thanks for explaining that.

It&apos;s a pretty common thing to do with JavaScript frameworks.  Makes it easier to enumerate over elements.

I use Dean Edwards&apos;s Base2... which allows this kind of traversal, and it seems like I&apos;ve seen similar code in use with other more popular frameworks, but I&apos;m not sure about that.

Dean shows how document.querySelectorAll can be used with forEach here:
http://dean.edwards.name/weblog/2007/03/yet-another/

Though, reading that again, he made that distinction clear too, so I understand why it isn&apos;t expected to work, but I think it&apos;d be pretty useful.  I use that all over the place in my apps, makes the code more readable and compact.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2021656</commentid>
    <comment_count>3</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2024-03-17 09:30:05 -0700</bug_when>
    <thetext>Unfortunately adding this to NodeList has proven difficult. Happy to reconsider if it gets standardized somehow.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>