[Fetch API] Add support for iterating over Headers
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Feb 2016 17:43:05 +0000 (17:43 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Feb 2016 17:43:05 +0000 (17:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153787

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Relanding.

* web-platform-tests/fetch/api/headers/headers-basic-expected.txt:
* web-platform-tests/fetch/api/headers/headers-basic.html:
* web-platform-tests/fetch/api/headers/headers-structure-expected.txt:
* web-platform-tests/fetch/api/request/request-clone.sub-expected.txt:
* web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt:
* web-platform-tests/fetch/api/resources/utils.js:
(checkRequest):
(readTextStream):

Source/WebCore:

Relanding, updating bindings/js/JSKeyValueIterator.h for Windows bots.

Covered by updated tests.
Introducing template class (JSKeyValueIterator) to support key-value iterators in DOM classes.
Using JSKeyValueIterator to implement Headers entries(), keys() and values() as custom methods.
Binding generator should be updated to generate directly these custom methods and handle iterator Symbol.

* CMakeLists.txt:
* Modules/fetch/FetchHeaders.cpp:
(WebCore::FetchHeaders::Iterator::next):
(WebCore::FetchHeaders::Iterator::Iterator):
* Modules/fetch/FetchHeaders.h:
(WebCore::FetchHeaders::createIterator):
* Modules/fetch/FetchHeaders.idl:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSDOMBinding.h:
(WebCore::jsPair):
* bindings/js/JSFetchHeadersCustom.cpp: Added.
(WebCore::JSFetchHeaders::entries):
(WebCore::JSFetchHeaders::keys):
(WebCore::JSFetchHeaders::values):
* bindings/js/JSKeyValueIterator.h: Added.
(WebCore::JSKeyValueIteratorPrototype::create):
(WebCore::JSKeyValueIteratorPrototype::createStructure):
(WebCore::JSKeyValueIteratorPrototype::JSKeyValueIteratorPrototype):
(WebCore::createIterator):
(WebCore::DOMWrapped>::destroy):
(WebCore::DOMWrapped>::next):
(WebCore::DOMWrapped>::finishCreation):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196128 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-basic-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-basic.html
LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-structure-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-clone.sub-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/utils.js
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchHeaders.cpp
Source/WebCore/Modules/fetch/FetchHeaders.h
Source/WebCore/Modules/fetch/FetchHeaders.idl
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSFetchHeadersCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSKeyValueIterator.h [new file with mode: 0644]

index 8553560..ca417fd 100644 (file)
@@ -1,3 +1,21 @@
+2016-02-04  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Fetch API] Add support for iterating over Headers
+        https://bugs.webkit.org/show_bug.cgi?id=153787
+
+        Reviewed by Darin Adler.
+
+        Relanding.
+
+        * web-platform-tests/fetch/api/headers/headers-basic-expected.txt:
+        * web-platform-tests/fetch/api/headers/headers-basic.html:
+        * web-platform-tests/fetch/api/headers/headers-structure-expected.txt:
+        * web-platform-tests/fetch/api/request/request-clone.sub-expected.txt:
+        * web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt:
+        * web-platform-tests/fetch/api/resources/utils.js:
+        (checkRequest):
+        (readTextStream):
+
 2016-02-04  Chris Dumez  <cdumez@apple.com>
 
         Merge DOMTokenList and DOMSettableTokenList
index be2bc74..6db69ce 100644 (file)
@@ -12,4 +12,7 @@ PASS Check set method
 PASS Check has method 
 PASS Check delete method 
 PASS Check get method 
+PASS Check keys method 
+PASS Check values method 
+PASS Check entries method 
 
index c39545d..51ac89c 100644 (file)
 
         assert_equals(headers.get("nameNotInHeaders"), null, "header: nameNotInHeaders has no value");
       }, "Check get method");
-    </script>
+
+      var headerEntriesDict = {"name1": "value1",
+                               "Name2": "value2",
+                               "name": "value3",
+                               "content-Type": "value4",
+                               "Content-Typ": "value5",
+                               "Content-Types": "value6"
+      };
+      var sortedHeaderDict = {};
+      var sortedHeaderKeys = Object.keys(headerEntriesDict).map(function(value) {
+        sortedHeaderDict[value.toLowerCase()] = headerEntriesDict[value];
+        return value.toLowerCase();
+      }).sort();
+
+      test(function() {
+        var headers = new Headers(headerEntriesDict);
+        var actual = headers.keys();
+        sortedHeaderKeys.forEach(function(key) {
+            entry = actual.next();
+            assert_false(entry.done);
+            assert_equals(entry.value, key);
+        });
+        assert_true(actual.next().done);
+        assert_true(actual.next().done);
+      }, "Check keys method");
+
+      test(function() {
+        var headers = new Headers(headerEntriesDict);
+        var actual = headers.values();
+
+        sortedHeaderKeys.forEach(function(key) {
+            entry = actual.next();
+            assert_false(entry.done);
+            assert_equals(entry.value, sortedHeaderDict[key]);
+        });
+        assert_true(actual.next().done);
+        assert_true(actual.next().done);
+      }, "Check values method");
+
+      test(function() {
+        var headers = new Headers(headerEntriesDict);
+        var actual = headers.entries();
+
+        sortedHeaderKeys.forEach(function(key) {
+            entry = actual.next();
+            assert_false(entry.done);
+            assert_equals(entry.value[0], key);
+            assert_equals(entry.value[1], sortedHeaderDict[key]);
+        });
+        assert_true(actual.next().done);
+        assert_true(actual.next().done);
+      }, "Check entries method");
+   </script>
   </body>
 </html>
index 856732f..0ef6d1b 100644 (file)
@@ -4,7 +4,7 @@ PASS Headers has delete method
 PASS Headers has get method 
 PASS Headers has has method 
 PASS Headers has set method 
-FAIL Headers has entries method assert_true: headers has entries method expected true got false
-FAIL Headers has keys method assert_true: headers has keys method expected true got false
-FAIL Headers has values method assert_true: headers has values method expected true got false
+PASS Headers has entries method 
+PASS Headers has keys method 
+PASS Headers has values method 
 
index 6cbd077..eeacf8a 100644 (file)
@@ -1,4 +1,4 @@
 
-FAIL Check cloning a request ExpectedValuesDict["headers"].keys is not a function. (In 'ExpectedValuesDict["headers"].keys()', 'ExpectedValuesDict["headers"].keys' is undefined)
+PASS Check cloning a request 
 PASS Check cloning a request copies the headers 
 
index 2abe756..fcce29c 100644 (file)
@@ -1,6 +1,6 @@
 
-FAIL Check request values when initialized from Request ExpectedValuesDict["headers"].keys is not a function. (In 'ExpectedValuesDict["headers"].keys()', 'ExpectedValuesDict["headers"].keys' is undefined)
-FAIL Check request values when initialized from Request and init values ExpectedValuesDict["headers"].keys is not a function. (In 'ExpectedValuesDict["headers"].keys()', 'ExpectedValuesDict["headers"].keys' is undefined)
+PASS Check request values when initialized from Request 
+PASS Check request values when initialized from Request and init values 
 FAIL Check request values when initialized from url string assert_equals: Check url attribute expected "http://url.test:1234/path/subpath?query=true" but got "http://url.test:1234/path/subpath?query=true#fragment"
-FAIL Check request values when initialized from url and init values ExpectedValuesDict["headers"].keys is not a function. (In 'ExpectedValuesDict["headers"].keys()', 'ExpectedValuesDict["headers"].keys' is undefined)
+FAIL Check request values when initialized from url and init values assert_equals: Check url attribute expected "http://url.test:1234/path/subpath?query=true" but got "http://url.test:1234/path/subpath?query=true#fragment"
 
index 4492935..6f8cdfa 100644 (file)
@@ -15,7 +15,7 @@ function checkRequest(request, ExpectedValuesDict) {
   for (var attribute in ExpectedValuesDict) {
     switch(attribute) {
       case "headers":
-          for (var key of ExpectedValuesDict["headers"].keys())
+          for (var key in ExpectedValuesDict["headers"].keys())
             assert_equals(request["headers"].get(key), ExpectedValuesDict["headers"].get(key),
               "Check headers attribute has " + key + ":" + ExpectedValuesDict["headers"].get(key));
         break;
@@ -63,4 +63,4 @@ function readTextStream(reader, asyncTest, expectedValue, retrievedText) {
       asyncTest.done();
     });
   });
-}
\ No newline at end of file
+}
index ce6b4bc..4a027b9 100644 (file)
@@ -1164,6 +1164,7 @@ set(WebCore_SOURCES
     bindings/js/JSEventListener.cpp
     bindings/js/JSEventTargetCustom.cpp
     bindings/js/JSExceptionBase.cpp
+    bindings/js/JSFetchHeadersCustom.cpp
     bindings/js/JSFileReaderCustom.cpp
     bindings/js/JSGeolocationCustom.cpp
     bindings/js/JSHTMLAllCollectionCustom.cpp
index 5476932..54069c3 100644 (file)
@@ -1,3 +1,41 @@
+2016-02-04  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Fetch API] Add support for iterating over Headers
+        https://bugs.webkit.org/show_bug.cgi?id=153787
+
+        Reviewed by Darin Adler.
+
+        Relanding, updating bindings/js/JSKeyValueIterator.h for Windows bots.
+
+        Covered by updated tests.
+        Introducing template class (JSKeyValueIterator) to support key-value iterators in DOM classes.
+        Using JSKeyValueIterator to implement Headers entries(), keys() and values() as custom methods.
+        Binding generator should be updated to generate directly these custom methods and handle iterator Symbol.
+
+        * CMakeLists.txt:
+        * Modules/fetch/FetchHeaders.cpp:
+        (WebCore::FetchHeaders::Iterator::next):
+        (WebCore::FetchHeaders::Iterator::Iterator):
+        * Modules/fetch/FetchHeaders.h:
+        (WebCore::FetchHeaders::createIterator):
+        * Modules/fetch/FetchHeaders.idl:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::jsPair):
+        * bindings/js/JSFetchHeadersCustom.cpp: Added.
+        (WebCore::JSFetchHeaders::entries):
+        (WebCore::JSFetchHeaders::keys):
+        (WebCore::JSFetchHeaders::values):
+        * bindings/js/JSKeyValueIterator.h: Added.
+        (WebCore::JSKeyValueIteratorPrototype::create):
+        (WebCore::JSKeyValueIteratorPrototype::createStructure):
+        (WebCore::JSKeyValueIteratorPrototype::JSKeyValueIteratorPrototype):
+        (WebCore::createIterator):
+        (WebCore::DOMWrapped>::destroy):
+        (WebCore::DOMWrapped>::next):
+        (WebCore::DOMWrapped>::finishCreation):
+
 2016-02-04  Chris Dumez  <cdumez@apple.com>
 
         Merge DOMTokenList and DOMSettableTokenList
index 3051634..8123e86 100644 (file)
@@ -179,6 +179,31 @@ void FetchHeaders::fill(const FetchHeaders* headers)
     }
 }
 
+bool FetchHeaders::Iterator::next(String& nextKey, String& nextValue)
+{
+    while (m_currentIndex < m_keys.size()) {
+        auto& key = m_keys[m_currentIndex++];
+        String value = m_headers->m_headers.get(key);
+        if (!value.isNull()) {
+            nextKey = key;
+            nextValue = WTFMove(value);
+            return false;
+        }
+    }
+    m_keys.clear();
+    return true;
+}
+
+FetchHeaders::Iterator::Iterator(FetchHeaders& headers)
+    : m_headers(headers)
+{
+    m_keys.reserveInitialCapacity(headers.m_headers.size());
+    for (auto& header : headers.m_headers)
+        m_keys.uncheckedAppend(header.key.convertToASCIILowercase());
+
+    std::sort(m_keys.begin(), m_keys.end(), WTF::codePointCompareLessThan);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(FETCH_API)
index 5368628..f3581d3 100644 (file)
@@ -62,6 +62,23 @@ public:
     String fastGet(HTTPHeaderName name) const { return m_headers.get(name); }
     void fastSet(HTTPHeaderName name, const String& value) { m_headers.set(name, value); }
 
+    class Iterator {
+    public:
+        explicit Iterator(FetchHeaders&);
+
+        // FIXME: Binding generator should be able to generate iterator key and value types.
+        using Key = String;
+        using Value = String;
+
+        bool next(String& nextKey, String& nextValue);
+
+    private:
+        Ref<FetchHeaders> m_headers;
+        size_t m_currentIndex = 0;
+        Vector<String> m_keys;
+    };
+    Iterator createIterator() { return Iterator(*this); }
+
 private:
     FetchHeaders(Guard guard) : m_guard(guard) { }
     FetchHeaders(Guard guard, const HTTPHeaderMap& headers) : m_guard(guard), m_headers(headers) { }
index 7d9f5fb..f633397 100644 (file)
@@ -40,8 +40,11 @@ interface FetchHeaders {
     [RaisesException] boolean has(DOMString name);
     [RaisesException] void set(DOMString name, DOMString value);
 
-    // FIXME: Support iterable.
+    // FIXME: Support iterable within binding generator.
     //iterable<DOMString, DOMString>;
+    [Custom] any entries();
+    [Custom] any keys();
+    [Custom] any values();
 
     [Private, RaisesException, ImplementedAs=append] void appendFromJS(DOMString name, DOMString value);
     [Private, RaisesException] void initializeWith(FetchHeaders headers);
index d46fcac..1f30a90 100644 (file)
                41D015CB0F4B5C71004A662F /* ContentType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41D015C90F4B5C71004A662F /* ContentType.cpp */; };
                41E1B1D00FF5986900576B3B /* AbstractWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41E1B1CA0FF5986900576B3B /* AbstractWorker.cpp */; };
                41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 41E1B1CB0FF5986900576B3B /* AbstractWorker.h */; };
+               41E910A71C60FD6C007A453F /* JSFetchHeadersCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41E910A61C60FD6C007A453F /* JSFetchHeadersCustom.cpp */; };
                41F062140F5F192600A07EAC /* InspectorDatabaseResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F062120F5F192600A07EAC /* InspectorDatabaseResource.h */; };
                41F062150F5F192600A07EAC /* InspectorDatabaseResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41F062130F5F192600A07EAC /* InspectorDatabaseResource.cpp */; };
                41F066E40F64BCF600A07EAC /* ScriptGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F066E20F64BCF600A07EAC /* ScriptGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41E1B1CA0FF5986900576B3B /* AbstractWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractWorker.cpp; sourceTree = "<group>"; };
                41E1B1CB0FF5986900576B3B /* AbstractWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractWorker.h; sourceTree = "<group>"; };
                41E1B1CC0FF5986900576B3B /* AbstractWorker.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AbstractWorker.idl; sourceTree = "<group>"; };
+               41E910A61C60FD6C007A453F /* JSFetchHeadersCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchHeadersCustom.cpp; sourceTree = "<group>"; };
                41F062120F5F192600A07EAC /* InspectorDatabaseResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorDatabaseResource.h; sourceTree = "<group>"; };
                41F062130F5F192600A07EAC /* InspectorDatabaseResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorDatabaseResource.cpp; sourceTree = "<group>"; };
                41F066E20F64BCF600A07EAC /* ScriptGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptGlobalObject.h; sourceTree = "<group>"; };
                                BC2ED5540C6B9BD300920BFF /* JSElementCustom.cpp */,
                                ADEC78F718EE5308001315C2 /* JSElementCustom.h */,
                                BCEFAF4D0C317E6900FA81F6 /* JSEventCustom.cpp */,
+                               41E910A61C60FD6C007A453F /* JSFetchHeadersCustom.cpp */,
                                2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */,
                                FE80D7A60E9C1ED2000D6F75 /* JSGeolocationCustom.cpp */,
                                BCE7B1920D4E86960075A539 /* JSHistoryCustom.cpp */,
                                97B38E28151C4273004622E9 /* DOMWindowNotifications.cpp in Sources */,
                                97D2AD0314B823A60093DF32 /* DOMWindowProperty.cpp in Sources */,
                                AA2A5AD716A4861A00975A25 /* DOMWindowSpeechSynthesis.cpp in Sources */,
+                               41E910A71C60FD6C007A453F /* JSFetchHeadersCustom.cpp in Sources */,
                                A8CCBB48151F831600AB7CE9 /* DOMWindowWebDatabase.cpp in Sources */,
                                BC53DA481143134D000D817E /* DOMWrapperWorld.cpp in Sources */,
                                1A1D13810A5325520064BF5F /* DOMXPath.mm in Sources */,
index dd47901..7e23f05 100644 (file)
@@ -77,6 +77,7 @@
 #include "JSEventListener.cpp"
 #include "JSEventTargetCustom.cpp"
 #include "JSExceptionBase.cpp"
+#include "JSFetchHeadersCustom.cpp"
 #include "JSFileReaderCustom.cpp"
 #include "JSGeolocationCustom.cpp"
 #include "JSHTMLAllCollectionCustom.cpp"
index 3a96b42..9d60b46 100644 (file)
@@ -514,6 +514,14 @@ template<typename T, size_t inlineCapacity> inline JSC::JSValue jsArray(JSC::Exe
     return jsArray(exec, globalObject, *vector);
 }
 
+template<typename Value1, typename Value2> inline JSC::JSValue jsPair(JSC::ExecState& state, JSDOMGlobalObject* globalObject, const Value1& value1, const Value2& value2)
+{
+    JSC::MarkedArgumentBuffer args;
+    args.append(toJS(&state, globalObject, value1));
+    args.append(toJS(&state, globalObject, value2));
+    return constructArray(&state, 0, globalObject, args);
+}
+
 WEBCORE_EXPORT JSC::JSValue jsArray(JSC::ExecState*, JSDOMGlobalObject*, PassRefPtr<DOMStringList>);
 
 inline PassRefPtr<JSC::ArrayBufferView> toArrayBufferView(JSC::JSValue value)
diff --git a/Source/WebCore/bindings/js/JSFetchHeadersCustom.cpp b/Source/WebCore/bindings/js/JSFetchHeadersCustom.cpp
new file mode 100644 (file)
index 0000000..cc64178
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2016 Canon Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Canon Inc. nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL CANON INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSFetchHeaders.h"
+
+#if ENABLE(FETCH_API)
+
+#include "JSKeyValueIterator.h"
+
+namespace WebCore {
+
+// FIXME: Move this code to JSFetchHeaders.
+using FetchHeadersIterator = JSKeyValueIterator<JSFetchHeaders, FetchHeaders>;
+using FetchHeadersIteratorPrototype = JSKeyValueIteratorPrototype<JSFetchHeaders, FetchHeaders>;
+
+template<>
+const JSC::ClassInfo FetchHeadersIterator::s_info = { "Headers Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(FetchHeadersIterator) };
+
+template<>
+const JSC::ClassInfo FetchHeadersIteratorPrototype::s_info = { "Headers Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(FetchHeadersIteratorPrototype) };
+
+JSC::JSValue JSFetchHeaders::entries(JSC::ExecState&)
+{
+    return createIterator<JSFetchHeaders, FetchHeaders>(*globalObject(), *this, IterationKind::KeyValue);
+}
+
+JSC::JSValue JSFetchHeaders::keys(JSC::ExecState&)
+{
+    return createIterator<JSFetchHeaders, FetchHeaders>(*globalObject(), *this, IterationKind::Key);
+}
+
+JSC::JSValue JSFetchHeaders::values(JSC::ExecState&)
+{
+    return createIterator<JSFetchHeaders, FetchHeaders>(*globalObject(), *this, IterationKind::Value);
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/bindings/js/JSKeyValueIterator.h b/Source/WebCore/bindings/js/JSKeyValueIterator.h
new file mode 100644 (file)
index 0000000..98e81e0
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2016 Canon, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CANON INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSKeyValueIterator_h
+#define JSKeyValueIterator_h
+
+#include "JSDOMBinding.h"
+#include <runtime/JSDestructibleObject.h>
+
+namespace WebCore {
+
+// FIXME: Update binding generator to allow getting DOMWrapped from JSWrapper.
+template<typename JSWrapper, typename DOMWrapped>
+class JSKeyValueIteratorPrototype : public JSC::JSNonFinalObject {
+public:
+    typedef JSC::JSNonFinalObject Base;
+
+    static JSKeyValueIteratorPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+    {
+        JSKeyValueIteratorPrototype* prototype = new (NotNull, JSC::allocateCell<JSKeyValueIteratorPrototype>(vm.heap)) JSKeyValueIteratorPrototype(vm, structure);
+        prototype->finishCreation(vm, globalObject);
+        return prototype;
+    }
+
+    DECLARE_INFO;
+
+    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+    {
+        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+    }
+
+    static JSC::EncodedJSValue JSC_HOST_CALL next(JSC::ExecState*);
+
+private:
+    JSKeyValueIteratorPrototype(JSC::VM& vm, JSC::Structure* structure) : Base(vm, structure) { }
+
+    void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+
+enum class IterationKind { Key, Value, KeyValue };
+
+template<typename JSWrapper, typename DOMWrapped>
+class JSKeyValueIterator: public JSDOMObject {
+public:
+    typedef JSDOMObject Base;
+
+    DECLARE_INFO;
+
+    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+    {
+        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+    }
+
+    static JSKeyValueIterator* create(JSC::VM& vm, JSC::Structure* structure, JSWrapper& iteratedObject, IterationKind kind)
+    {
+        JSKeyValueIterator* instance = new (NotNull, JSC::allocateCell<JSKeyValueIterator>(vm.heap)) JSKeyValueIterator(structure, iteratedObject, kind);
+        instance->finishCreation(vm);
+        return instance;
+    }
+
+    static JSKeyValueIteratorPrototype<JSWrapper, DOMWrapped>* createPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+    {
+        return JSKeyValueIteratorPrototype<JSWrapper, DOMWrapped>::create(vm, globalObject,
+            JSKeyValueIteratorPrototype<JSWrapper, DOMWrapped>::createStructure(vm, globalObject, globalObject->objectPrototype()));
+    }
+
+    bool next(JSC::ExecState&, JSC::JSValue&);
+
+private:
+    JSKeyValueIterator(JSC::Structure* structure, JSWrapper& iteratedObject, IterationKind kind)
+        : Base(structure, *iteratedObject.globalObject())
+        , m_iterator(iteratedObject.wrapped().createIterator())
+        , m_kind(kind)
+    {
+    }
+
+    static void destroy(JSC::JSCell*);
+
+    typename DOMWrapped::Iterator m_iterator;
+    IterationKind m_kind;
+};
+
+template<typename JSWrapper, typename DOMWrapped>
+JSKeyValueIterator<JSWrapper, DOMWrapped>* createIterator(JSDOMGlobalObject& globalObject, JSWrapper& wrapper, IterationKind kind)
+{
+    return JSKeyValueIterator<JSWrapper, DOMWrapped>::create(globalObject.vm(), getDOMStructure<JSKeyValueIterator<JSWrapper, DOMWrapped>>(globalObject.vm(), globalObject), wrapper, kind);
+}
+
+template<typename JSWrapper, typename DOMWrapped>
+void JSKeyValueIterator<JSWrapper, DOMWrapped>::destroy(JSCell* cell)
+{
+    JSKeyValueIterator<JSWrapper, DOMWrapped>* thisObject = JSC::jsCast<JSKeyValueIterator<JSWrapper, DOMWrapped>*>(cell);
+    thisObject->JSKeyValueIterator<JSWrapper, DOMWrapped>::~JSKeyValueIterator();
+}
+
+template<typename JSWrapper, typename DOMWrapped>
+bool JSKeyValueIterator<JSWrapper, DOMWrapped>::next(JSC::ExecState& state, JSC::JSValue& value)
+{
+    typename DOMWrapped::Iterator::Key nextKey;
+    typename DOMWrapped::Iterator::Value nextValue;
+    if (m_iterator.next(nextKey, nextValue)) {
+        value = JSC::jsUndefined();
+        return true;
+    }
+    if (m_kind == IterationKind::Value)
+        value = toJS(&state, globalObject(), nextValue);
+    else if (m_kind == IterationKind::Key)
+        value = toJS(&state, globalObject(), nextKey);
+    else
+        value = jsPair(state, globalObject(), nextKey, nextValue);
+    return false;
+}
+
+template<typename JSWrapper, typename DOMWrapped>
+JSC::EncodedJSValue JSC_HOST_CALL JSKeyValueIteratorPrototype<JSWrapper, DOMWrapped>::next(JSC::ExecState* state)
+{
+    JSKeyValueIterator<JSWrapper, DOMWrapped>* iterator = JSC::jsDynamicCast<JSKeyValueIterator<JSWrapper, DOMWrapped>*>(state->thisValue());
+    if (!iterator)
+        return JSC::JSValue::encode(throwTypeError(state, ASCIILiteral("Cannot call next() on a non-Iterator object")));
+
+    JSC::JSValue result;
+    bool isDone = iterator->next(*state, result);
+    return JSC::JSValue::encode(createIteratorResultObject(state, result, isDone));
+}
+
+template<typename JSWrapper, typename DOMWrapped>
+void JSKeyValueIteratorPrototype<JSWrapper, DOMWrapped>::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+    Base::finishCreation(vm);
+    ASSERT(inherits(info()));
+
+    JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->next, next, JSC::DontEnum, 0, JSC::NoIntrinsic);
+}
+
+}
+
+#endif // !defined(JSKeyValueIterator_h)