[Fetch] Use @isArray instead of `instanceof @Array`
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2016 08:01:07 +0000 (08:01 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2016 08:01:07 +0000 (08:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156682

Reviewed by Alex Christensen.

Source/WebCore:

Currently, we query whether the given value is Array by using `instanceof @Array`.
But it is not enough; Array from the other realm should be accepted. And Array
not inheriting @Array should be also accepted.

Test: fetch/header-constructor-is-array.html

* Modules/fetch/FetchHeaders.js:
(initializeFetchHeaders):

LayoutTests:

* fetch/header-constructor-is-array-expected.txt: Added.
* fetch/header-constructor-is-array.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fetch/header-constructor-is-array-expected.txt [new file with mode: 0644]
LayoutTests/fetch/header-constructor-is-array.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchHeaders.js

index 92fc3ba..d17713d 100644 (file)
@@ -1,3 +1,13 @@
+2016-04-18  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [Fetch] Use @isArray instead of `instanceof @Array`
+        https://bugs.webkit.org/show_bug.cgi?id=156682
+
+        Reviewed by Alex Christensen.
+
+        * fetch/header-constructor-is-array-expected.txt: Added.
+        * fetch/header-constructor-is-array.html: Added.
+
 2016-04-17  Yoav Weiss  <yoav@yoav.ws>
 
         Initial Link preload support
diff --git a/LayoutTests/fetch/header-constructor-is-array-expected.txt b/LayoutTests/fetch/header-constructor-is-array-expected.txt
new file mode 100644 (file)
index 0000000..aa218e3
--- /dev/null
@@ -0,0 +1,11 @@
+This test should create a Headers with strange Array, but the constructor should recognize it as an Array.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS headers.get('hello') is "world"
+PASS headers.get('hello') is "world"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fetch/header-constructor-is-array.html b/LayoutTests/fetch/header-constructor-is-array.html
new file mode 100644 (file)
index 0000000..46ab0bd
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<iframe></iframe>
+<script>
+description("This test should create a Headers with strange Array, but the constructor should recognize it as an Array.");
+
+{
+    let array = [ [ 'hello', 'world' ] ];
+    array.__proto__ = null;
+    var headers = new Headers(array);
+    shouldBeEqualToString("headers.get('hello')", "world");
+}
+
+{
+    // From the other realm.
+    let frame = frames[0];
+    let array = new frame.Array();
+    array.push([ 'hello', 'world' ]);
+    var headers = new Headers(array);
+    shouldBeEqualToString("headers.get('hello')", "world");
+}
+
+</script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
index 3256e15..ec8afc5 100644 (file)
@@ -1,3 +1,19 @@
+2016-04-18  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [Fetch] Use @isArray instead of `instanceof @Array`
+        https://bugs.webkit.org/show_bug.cgi?id=156682
+
+        Reviewed by Alex Christensen.
+
+        Currently, we query whether the given value is Array by using `instanceof @Array`.
+        But it is not enough; Array from the other realm should be accepted. And Array
+        not inheriting @Array should be also accepted.
+
+        Test: fetch/header-constructor-is-array.html
+
+        * Modules/fetch/FetchHeaders.js:
+        (initializeFetchHeaders):
+
 2016-04-17  Yoav Weiss  <yoav@yoav.ws>
 
         Initial Link preload support
index cc7b958..7c35014 100644 (file)
@@ -40,7 +40,7 @@ function initializeFetchHeaders(headersInit)
         return this;
     }
 
-    if (headersInit instanceof @Array) {
+    if (@isArray(headersInit)) {
         for (let i = 0; i < headersInit.length; i++) {
             let header = headersInit[i];
             if (header.length !== 2)