Title: [203235] trunk
Revision
203235
Author
[email protected]
Date
2016-07-14 12:32:24 -0700 (Thu, 14 Jul 2016)

Log Message

DOMIterators should be assigned a correct prototype
https://bugs.webkit.org/show_bug.cgi?id=159115

Patch by Youenn Fablet <[email protected]> on 2016-07-14
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/headers/headers-basic.html: Updating test (changes to be upstreamed to w3c wpt repo)

Source/WebCore:

Default iterator object internal prototype property is the Iterator prototype as defined in
http://heycam.github.io/webidl/#dfn-iterator-prototype-object.
Linking DOMIterator prototype to IteratorPrototype.
This allows adding @@iterator property to the result of entries, keys and values methods.
This in turns allow doing for-of loops on them.

Covered by updated test.

* ForwardingHeaders/runtime/IteratorPrototype.h: Added.
* bindings/js/JSDOMIterator.h: Setting correct prototype and marking next prototype property as enumerable.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (203234 => 203235)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-14 19:30:09 UTC (rev 203234)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-14 19:32:24 UTC (rev 203235)
@@ -1,5 +1,14 @@
 2016-07-14  Youenn Fablet  <[email protected]>
 
+        DOMIterators should be assigned a correct prototype
+        https://bugs.webkit.org/show_bug.cgi?id=159115
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/fetch/api/headers/headers-basic.html: Updating test (changes to be upstreamed to w3c wpt repo)
+
+2016-07-14  Youenn Fablet  <[email protected]>
+
         [Fetch API] Request and Response url getter should use URL serialization
         https://bugs.webkit.org/show_bug.cgi?id=159705
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-basic.html (203234 => 203235)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-basic.html	2016-07-14 19:30:09 UTC (rev 203234)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-basic.html	2016-07-14 19:32:24 UTC (rev 203235)
@@ -120,14 +120,29 @@
                                "Content-Types": "value6"
       };
       var sortedHeaderDict = {};
+      var headerValues = [];
       var sortedHeaderKeys = Object.keys(headerEntriesDict).map(function(value) {
         sortedHeaderDict[value.toLowerCase()] = headerEntriesDict[value];
+        headerValues.push(headerEntriesDict[value]);
         return value.toLowerCase();
       }).sort();
 
+      var iteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([].values()));
+      function checkIteratorProperties(iterator) {
+        var prototype = Object.getPrototypeOf(iterator);
+        assert_equals(Object.getPrototypeOf(prototype), iteratorPrototype);
+
+        var descriptor = Object.getOwnPropertyDescriptor(prototype, "next");
+        assert_true(descriptor.configurable, "configurable");
+        assert_true(descriptor.enumerable, "enumerable");
+        assert_true(descriptor.writable, "writable");
+      }
+
       test(function() {
         var headers = new Headers(headerEntriesDict);
         var actual = headers.keys();
+        checkIteratorProperties(actual);
+
         sortedHeaderKeys.forEach(function(key) {
             entry = actual.next();
             assert_false(entry.done);
@@ -135,11 +150,15 @@
         });
         assert_true(actual.next().done);
         assert_true(actual.next().done);
+
+        for (key of headers.keys())
+            assert_true(sortedHeaderKeys.indexOf(key) != -1);
       }, "Check keys method");
 
       test(function() {
         var headers = new Headers(headerEntriesDict);
         var actual = headers.values();
+        checkIteratorProperties(actual);
 
         sortedHeaderKeys.forEach(function(key) {
             entry = actual.next();
@@ -148,11 +167,15 @@
         });
         assert_true(actual.next().done);
         assert_true(actual.next().done);
+
+        for (value of headers.values())
+            assert_true(headerValues.indexOf(value) != -1);
       }, "Check values method");
 
       test(function() {
         var headers = new Headers(headerEntriesDict);
         var actual = headers.entries();
+        checkIteratorProperties(actual);
 
         sortedHeaderKeys.forEach(function(key) {
             entry = actual.next();
@@ -162,6 +185,9 @@
         });
         assert_true(actual.next().done);
         assert_true(actual.next().done);
+
+        for (entry of headers.entries())
+            assert_equals(entry[1], sortedHeaderDict[entry[0]]);
       }, "Check entries method");
 
       test(function() {

Modified: trunk/Source/WebCore/ChangeLog (203234 => 203235)


--- trunk/Source/WebCore/ChangeLog	2016-07-14 19:30:09 UTC (rev 203234)
+++ trunk/Source/WebCore/ChangeLog	2016-07-14 19:32:24 UTC (rev 203235)
@@ -1,5 +1,23 @@
 2016-07-14  Youenn Fablet  <[email protected]>
 
+        DOMIterators should be assigned a correct prototype
+        https://bugs.webkit.org/show_bug.cgi?id=159115
+
+        Reviewed by Chris Dumez.
+
+        Default iterator object internal prototype property is the Iterator prototype as defined in
+        http://heycam.github.io/webidl/#dfn-iterator-prototype-object.
+        Linking DOMIterator prototype to IteratorPrototype.
+        This allows adding @@iterator property to the result of entries, keys and values methods.
+        This in turns allow doing for-of loops on them.
+
+        Covered by updated test.
+
+        * ForwardingHeaders/runtime/IteratorPrototype.h: Added.
+        * bindings/js/JSDOMIterator.h: Setting correct prototype and marking next prototype property as enumerable.
+
+2016-07-14  Youenn Fablet  <[email protected]>
+
         Remove support for value iterators from JSDOMIterator
         https://bugs.webkit.org/show_bug.cgi?id=159293
 

Added: trunk/Source/WebCore/ForwardingHeaders/runtime/IteratorPrototype.h (0 => 203235)


--- trunk/Source/WebCore/ForwardingHeaders/runtime/IteratorPrototype.h	                        (rev 0)
+++ trunk/Source/WebCore/ForwardingHeaders/runtime/IteratorPrototype.h	2016-07-14 19:32:24 UTC (rev 203235)
@@ -0,0 +1,2 @@
+#pragma once
+#include <_javascript_Core/IteratorPrototype.h>

Modified: trunk/Source/WebCore/bindings/js/JSDOMIterator.h (203234 => 203235)


--- trunk/Source/WebCore/bindings/js/JSDOMIterator.h	2016-07-14 19:30:09 UTC (rev 203234)
+++ trunk/Source/WebCore/bindings/js/JSDOMIterator.h	2016-07-14 19:32:24 UTC (rev 203235)
@@ -27,6 +27,7 @@
 #define JSDOMIterator_h
 
 #include "JSDOMBinding.h"
+#include <runtime/IteratorPrototype.h>
 #include <runtime/JSDestructibleObject.h>
 #include <type_traits>
 
@@ -97,7 +98,7 @@
     static JSDOMIteratorPrototype<JSWrapper>* createPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
     {
         return JSDOMIteratorPrototype<JSWrapper>::create(vm, globalObject,
-            JSDOMIteratorPrototype<JSWrapper>::createStructure(vm, globalObject, globalObject->objectPrototype()));
+            JSDOMIteratorPrototype<JSWrapper>::createStructure(vm, globalObject, globalObject->iteratorPrototype()));
     }
 
     JSC::JSValue next(JSC::ExecState&);
@@ -238,7 +239,7 @@
     Base::finishCreation(vm);
     ASSERT(inherits(info()));
 
-    JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->next, next, JSC::DontEnum, 0, JSC::NoIntrinsic);
+    JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->next, next, 0, 0, JSC::NoIntrinsic);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to