JavaScript for-of does not work on a lot of collection types (e.g. HTMLCollection)
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Jan 2017 05:48:28 +0000 (05:48 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Jan 2017 05:48:28 +0000 (05:48 +0000)
commita531a2439b4ff914122307cd94cfe64f53c453c9
tree7538ac5ac1d5f3fe02f13625e87208be1f430e6a
parentdcb52be1f1f3a9eda1ca64e59991e7c103eda468
JavaScript for-of does not work on a lot of collection types (e.g. HTMLCollection)
https://bugs.webkit.org/show_bug.cgi?id=167091

Reviewed by Darin Adler.

Source/JavaScriptCore:

Update Array methods to throw a TypeError when (this === null || this === undefined)
instead of when (this == null). This is because (this == null) returns true for types
that masquerades as undefined (such as document.all) and this prevented use of the
Array API on such types. The specification only stays to use ToObject(), which throws
when the input is undefined or null.

The corresponding specification is at:
- https://www.ecma-international.org/ecma-262/7.0/index.html#sec-array.prototype.values
- https://www.ecma-international.org/ecma-262/7.0/index.html#sec-toobject

* builtins/ArrayPrototype.js:
(values):
(keys):
(entries):
(reduce):
(reduceRight):
(every):
(forEach):
(filter):
(map):
(some):
(fill):
(find):
(findIndex):
(includes):
(sort):
(concatSlowPath):
(copyWithin):

Source/WebCore:

As per the Web IDL specification [1], https://heycam.github.io/webidl/#es-iterator
an interface should get an iterator if it has:
- an indexed property getter and an integer-typed attribute named "length".

We now comply with this part of the Web IDL specification. This adds an iterator
to the following interfaces:
- AudioTrackList, ClientRectList, CSSRuleList, CSSStyleDeclaration, CSSValueList,
  MimeTypeArray, WebKitNamedFlowCollection, Plugin, PluginArray, DOMStringList,
  FileList, HTMLAllCollection, HTMLCollection, HTMLFormElement, HTMLOptionsCollection,
  HTMLSelectElement, MediaList, NamedNodeMap, SourceBufferList, StyleSheetList,
  TextTrackCueList, TextTrackList, TouchList, VideoTrackList, VTTRegionList.

As a result, it is now possible to use `for ... of` for those types.

Tests: fast/dom/FileList-iterator.html
       fast/dom/collection-iterators.html
       fast/dom/document-all-undefined.html
       fast/events/touch/ios/touchlist-iterator.html

* bindings/scripts/CodeGeneratorJS.pm:
(GetAttributeWithName):
(InterfaceNeedsIterator):
(GenerateImplementation):
(addIterableProperties):

LayoutTests:

* fast/dom/FileList-iterator-expected.txt: Added.
* fast/dom/FileList-iterator.html: Added.
* fast/dom/collection-iterators-expected.txt: Added.
* fast/dom/collection-iterators.html: Added.
* fast/events/touch/ios/touchlist-iterator-expected.txt: Added.
* fast/events/touch/ios/touchlist-iterator.html: Added.
Add layout test coverage for all types that gained an iterator.

* fast/dom/document-all-undefined-expected.txt: Added.
* fast/dom/document-all-undefined.html: Added.
Add layout test to cover the fact that HTMLAllCollection masquerades as
undefined, as per:
- https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-all

* inspector/model/remote-object-get-properties-expected.txt:
Rebaseline now that there is an extra Symbol.iterator property.

* platform/wk2/TestExpectations:
Skip that requires beginDragWithFiles() as this is unimplemented in
WebKitTestRunner.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211024 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/FileList-iterator-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/FileList-iterator.html [new file with mode: 0644]
LayoutTests/fast/dom/collection-iterators-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/collection-iterators.html [new file with mode: 0644]
LayoutTests/fast/dom/document-all-undefined-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/document-all-undefined.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/touchlist-iterator-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/touchlist-iterator.html [new file with mode: 0644]
LayoutTests/inspector/model/remote-object-get-properties-expected.txt
LayoutTests/platform/ios-simulator/fast/dom/collection-iterators-expected.txt [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/ArrayPrototype.js
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp