[Fetch API] Implement Fetch API Response
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Feb 2016 21:41:51 +0000 (21:41 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Feb 2016 21:41:51 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154536

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

New tests covering fetch API.

* web-platform-tests/fetch/api/response/response-clone-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-clone.html: Added.
* web-platform-tests/fetch/api/response/response-consume-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-consume.html: Added.
* web-platform-tests/fetch/api/response/response-error-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-error.html: Added.
* web-platform-tests/fetch/api/response/response-idl-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-idl.html: Added.
* web-platform-tests/fetch/api/response/response-init-001-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-init-001.html: Added.
* web-platform-tests/fetch/api/response/response-init-002-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-init-002.html: Added.
* web-platform-tests/fetch/api/response/response-static-error-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-static-error.html: Added.
* web-platform-tests/fetch/api/response/response-static-redirect-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-static-redirect.html: Added.

Source/WebCore:

Tests: imported/w3c/web-platform-tests/fetch/api/response/response-clone.html
       imported/w3c/web-platform-tests/fetch/api/response/response-consume.html
       imported/w3c/web-platform-tests/fetch/api/response/response-error.html
       imported/w3c/web-platform-tests/fetch/api/response/response-idl.html
       imported/w3c/web-platform-tests/fetch/api/response/response-init-001.html
       imported/w3c/web-platform-tests/fetch/api/response/response-init-002.html
       imported/w3c/web-platform-tests/fetch/api/response/response-static-error.html
       imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect.html

Adding Fetch Response as FetchResponse class.
Constructor uses a built-in to pre-process the parameters.
Support of body as ReadableStream is missing.

* CMakeLists.txt:
* DerivedSources.make:
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::empty):
* Modules/fetch/FetchResponse.cpp: Added.
(WebCore::JSFetchResponse::body):
(WebCore::isRedirectStatus):
(WebCore::isNullBodyStatus):
(WebCore::FetchResponse::error):
(WebCore::FetchResponse::redirect):
(WebCore::FetchResponse::initializeWith):
(WebCore::FetchResponse::FetchResponse):
(WebCore::FetchResponse::clone):
(WebCore::FetchResponse::type):
* Modules/fetch/FetchResponse.h: Added.
(WebCore::FetchResponse::create):
(WebCore::FetchResponse::redirect):
(WebCore::FetchResponse::url):
(WebCore::FetchResponse::redirected):
(WebCore::FetchResponse::status):
(WebCore::FetchResponse::ok):
(WebCore::FetchResponse::statusText):
(WebCore::FetchResponse::headers):
(WebCore::FetchResponse::isDisturbed):
(WebCore::FetchResponse::arrayBuffer):
(WebCore::FetchResponse::formData):
(WebCore::FetchResponse::blob):
(WebCore::FetchResponse::json):
(WebCore::FetchResponse::text):
* Modules/fetch/FetchResponse.idl: Added.
* Modules/fetch/FetchResponse.js: Added.
(initializeFetchResponse):
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreJSBuiltins.cpp:
* bindings/js/WebCoreJSBuiltins.h:
(WebCore::JSBuiltinFunctions::JSBuiltinFunctions):
(WebCore::JSBuiltinFunctions::fetchResponseBuiltins):

LayoutTests:

Adding Response as constructor in global and worker scopes.

* js/dom/global-constructors-attributes-dedicated-worker-expected.txt:
* js/dom/global-constructors-attributes-expected.txt:
* platform/efl/js/dom/global-constructors-attributes-dedicated-worker-expected.txt:
* platform/efl/js/dom/global-constructors-attributes-expected.txt:
* platform/gtk/js/dom/global-constructors-attributes-expected.txt:
* platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt:
* platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt:
* platform/mac/js/dom/global-constructors-attributes-expected.txt:
* platform/win/js/dom/global-constructors-attributes-expected.txt:

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

39 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-idl-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-idl.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-001-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-001.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-error-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-error.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect.html [new file with mode: 0644]
LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
LayoutTests/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/efl/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
LayoutTests/platform/efl/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/gtk/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/win/js/dom/global-constructors-attributes-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.cpp
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchResponse.cpp [new file with mode: 0644]
Source/WebCore/Modules/fetch/FetchResponse.h [new file with mode: 0644]
Source/WebCore/Modules/fetch/FetchResponse.idl [new file with mode: 0644]
Source/WebCore/Modules/fetch/FetchResponse.js [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/WebCoreJSBuiltins.cpp
Source/WebCore/bindings/js/WebCoreJSBuiltins.h

index 042a38c..fbd4de2 100644 (file)
@@ -1,3 +1,22 @@
+2016-02-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Fetch API] Implement Fetch API Response
+        https://bugs.webkit.org/show_bug.cgi?id=154536
+
+        Reviewed by Alex Christensen.
+
+        Adding Response as constructor in global and worker scopes.
+
+        * js/dom/global-constructors-attributes-dedicated-worker-expected.txt:
+        * js/dom/global-constructors-attributes-expected.txt:
+        * platform/efl/js/dom/global-constructors-attributes-dedicated-worker-expected.txt:
+        * platform/efl/js/dom/global-constructors-attributes-expected.txt:
+        * platform/gtk/js/dom/global-constructors-attributes-expected.txt:
+        * platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt:
+        * platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt:
+        * platform/mac/js/dom/global-constructors-attributes-expected.txt:
+        * platform/win/js/dom/global-constructors-attributes-expected.txt:
+
 2016-02-24  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r197033.
index edb99b1..661998c 100644 (file)
@@ -1,5 +1,31 @@
 2016-02-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
+        [Fetch API] Implement Fetch API Response
+        https://bugs.webkit.org/show_bug.cgi?id=154536
+
+        Reviewed by Alex Christensen.
+
+        New tests covering fetch API.
+
+        * web-platform-tests/fetch/api/response/response-clone-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-clone.html: Added.
+        * web-platform-tests/fetch/api/response/response-consume-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-consume.html: Added.
+        * web-platform-tests/fetch/api/response/response-error-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-error.html: Added.
+        * web-platform-tests/fetch/api/response/response-idl-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-idl.html: Added.
+        * web-platform-tests/fetch/api/response/response-init-001-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-init-001.html: Added.
+        * web-platform-tests/fetch/api/response/response-init-002-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-init-002.html: Added.
+        * web-platform-tests/fetch/api/response/response-static-error-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-static-error.html: Added.
+        * web-platform-tests/fetch/api/response/response-static-redirect-expected.txt: Added.
+        * web-platform-tests/fetch/api/response/response-static-redirect.html: Added.
+
+2016-02-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
         W3C importer should generate all web-platform-tests submodules descriptions
         https://bugs.webkit.org/show_bug.cgi?id=154587
 
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt
new file mode 100644 (file)
index 0000000..5fa8fa4
--- /dev/null
@@ -0,0 +1,7 @@
+
+PASS Check Response's clone with default values, without body 
+PASS Check Response's clone has the expected attribute values 
+FAIL Check orginal response's body after cloning null is not an object (evaluating 'response.body.getReader')
+FAIL Check cloned response's body null is not an object (evaluating 'clonedResponse.body.getReader')
+FAIL Cannot clone a disturbed response assert_true: response is disturbed expected true got false
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html
new file mode 100644 (file)
index 0000000..fd323e6
--- /dev/null
@@ -0,0 +1,66 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response clone</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script src="../resources/utils.js"></script>
+    <script>
+      var defaultValues = { "type" : "default",
+                            "url" : "",
+                            "ok" : true,
+                            "status" : 200,
+                            "statusText" : "OK"
+      };
+
+      var response = new Response();
+      var clonedResponse = response.clone();
+      test(function() {
+        for (var attributeName in defaultValues) {
+            var expectedValue = defaultValues[attributeName];
+            assert_equals(clonedResponse[attributeName], expectedValue,
+              "Expect default response." + attributeName + " is " + expectedValue);
+        }
+      }, "Check Response's clone with default values, without body");
+
+      var body = "This is response body";
+      var headersInit = { "name" : "value" };
+      var responseInit  = { "status" : 200,
+                            "statusText" : "GOOD",
+                            "headers" : headersInit
+      };
+      var response = new Response(body, responseInit);
+      var clonedResponse = response.clone();
+      test(function() {
+        assert_equals(clonedResponse.status, responseInit["status"],
+          "Expect response.status is " + responseInit["status"]);
+        assert_equals(clonedResponse.statusText, responseInit["statusText"],
+          "Expect response.statusText is " + responseInit["statusText"]);
+        assert_equals(response.headers.get("name"), "value",
+          "Expect response.headers has name:value header");
+      }, "Check Response's clone has the expected attribute values");
+
+      async_test(function(test) {
+        readTextStream(response.body.getReader(), test, body);
+      }, "Check orginal response's body after cloning");
+
+      async_test(function(test) {
+        readTextStream(clonedResponse.body.getReader(), test, body);
+      }, "Check cloned response's body");
+
+      promise_test(function(test) {
+        var disturbedResponse = new Response();
+        return disturbedResponse.text().then(function() {
+            assert_true(disturbedResponse.bodyUsed, "response is disturbed");
+            assert_throws(new TypeError() , function() { disturbedResponse.clone(); },
+              "Expect TypeError exception");
+        });
+      }, "Cannot clone a disturbed response");
+    </script>
+  </body>
+</html>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt
new file mode 100644 (file)
index 0000000..66c8f86
--- /dev/null
@@ -0,0 +1,7 @@
+
+PASS Consume response's body as text 
+FAIL Consume response's body as blob promise_test: Unhandled rejection with value: undefined
+FAIL Consume response's body as arrayBuffer promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: TextDecoder"
+PASS Consume response's body as json 
+FAIL Consume response's body as formData promise_test: Unhandled rejection with value: undefined
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html
new file mode 100644 (file)
index 0000000..1de0321
--- /dev/null
@@ -0,0 +1,82 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response consume</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script>
+    function checkBodyText(response, expectedBody) {
+      return response.text().then( function(bodyAsText) {
+        assert_equals(bodyAsText, expectedBody, "Retrieve and verify response's body");
+        assert_true(response.bodyUsed === true, "body as text: bodyUsed turned true");
+      });
+    }
+
+    function checkBodyBlob(response, expectedBody) {
+      return response.blob().then(function(bodyAsBlob) {
+        var promise = new Promise( function (resolve, reject) {
+          var reader = new FileReader();
+          reader.onload = function(evt) {
+            resolve(reader.result)
+          };
+          reader.onerror = function () {
+            reject("Blob's reader failed");
+          };
+          reader.readAsText(bodyAsBlob);
+        });
+        return promise.then(function(body) {
+          assert_equals(body, expectedBody, "Retrieve and verify response's body");
+          assert_true(response.bodyUsed === true, "body as blob: bodyUsed turned true");
+        });
+      });
+    }
+
+    function checkBodyArrayBuffer(response, expectedBody) {
+      return response.arrayBuffer().then( function(bodyAsArrayBuffer) {
+        var decoder = new TextDecoder("utf-8");
+        var strBody = decoder.decode(bodyAsArrayBuffer);
+        assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
+        assert_true(response.bodyUsed === true, "body as arrayBuffer: bodyUsed turned true");
+      });
+    }
+
+    function checkBodyJson(response, expectedBody) {
+      return response.json().then(function(bodyAsJson) {
+        var strBody = JSON.stringify(bodyAsJson)
+        assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
+        assert_true(response.bodyUsed === true, "body as json: bodyUsed turned true");
+      });
+    }
+
+    function checkBodyFormData(response, expectedBody) {
+      return response.formData().then(function(bodyAsFormData) {
+        for (var name of expectedBody.keys())
+          assert_equals(bodyAsFormData.get(name), expectedBody.get(name) , "Retrieve and verify response's body" );
+        assert_true(response.bodyUsed === true, "body as formData: bodyUsed turned true");
+     });
+    }
+
+    function checkResponseBody(body, bodyType, checkFunction) {
+      promise_test(function(test) {
+        var response = new Response(body);
+        assert_true(response.bodyUsed === false, "bodyUsed is false at init");
+        return checkFunction(response, body);
+      }, "Consume response's body as " + bodyType);
+    }
+
+    var formData = new FormData();
+    formData.append("name", "value")
+    checkResponseBody("This is response's body", "text", checkBodyText);
+    checkResponseBody("This is response's body", "blob", checkBodyBlob);
+    checkResponseBody("This is response's body", "arrayBuffer", checkBodyArrayBuffer);
+    checkResponseBody(JSON.stringify("This is response's body"), "json", checkBodyJson);
+    checkResponseBody(formData, "formData", checkBodyFormData);
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-expected.txt
new file mode 100644 (file)
index 0000000..55c5710
--- /dev/null
@@ -0,0 +1,6 @@
+
+PASS Throws RangeError when responseInit's status is invalid 
+FAIL Throws TypeError when responseInit's statusText is invalid assert_throws: Expect TypeError exception 
+ function "function () { new Response("", { "statusText" : statusTex..." did not throw
+PASS Throws TypeError when building a response with body and a null body status 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error.html
new file mode 100644 (file)
index 0000000..1302452
--- /dev/null
@@ -0,0 +1,39 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response error</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script>
+      test(function() {
+        var invalidStatus = [0, 100, 199, 600, 1000];
+        invalidStatus.forEach(function(status) {
+          assert_throws(new RangeError() , function() { new Response("", { "status" : status }); },
+            "Expect RangeError exception when status is " + status);
+        });
+      },"Throws RangeError when responseInit's status is invalid");
+
+      test(function() {
+        var invalidStatusText = ["\n", "Ā"];
+        invalidStatusText.forEach(function(statusText) {
+          assert_throws(new TypeError() , function() { new Response("", { "statusText" : statusText }); },
+            "Expect TypeError exception " + statusText);
+        });
+      },"Throws TypeError when responseInit's statusText is invalid");
+
+      test(function() {
+        var nullBodyStatus = [204, 205, 304];
+        nullBodyStatus.forEach(function(status) {
+          assert_throws(new TypeError() ,
+            function() { new Response("body", { "status" : status }); },
+            "Expect TypeError exception ");
+        });
+      },"Throws TypeError when building a response with body and a null body status");
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-idl-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-idl-expected.txt
new file mode 100644 (file)
index 0000000..43037a0
--- /dev/null
@@ -0,0 +1,47 @@
+
+PASS Response interface: existence and properties of interface object 
+PASS Response interface object length 
+PASS Response interface object name 
+PASS Response interface: existence and properties of interface prototype object 
+PASS Response interface: existence and properties of interface prototype object's "constructor" property 
+PASS Response interface: operation error() 
+PASS Response interface: operation redirect(USVString,unsigned short) 
+PASS Response interface: attribute type 
+PASS Response interface: attribute url 
+PASS Response interface: attribute status 
+PASS Response interface: attribute ok 
+PASS Response interface: attribute statusText 
+PASS Response interface: attribute headers 
+PASS Response interface: attribute body 
+PASS Response interface: operation clone() 
+PASS Response interface: attribute bodyUsed 
+FAIL Response interface: operation arrayBuffer() assert_throws: calling operation with this = null didn't throw TypeError function "function () {
+                memberHolderObject[member.n..." did not throw
+FAIL Response interface: operation blob() assert_throws: calling operation with this = null didn't throw TypeError function "function () {
+                memberHolderObject[member.n..." did not throw
+FAIL Response interface: operation formData() assert_throws: calling operation with this = null didn't throw TypeError function "function () {
+                memberHolderObject[member.n..." did not throw
+FAIL Response interface: operation json() assert_throws: calling operation with this = null didn't throw TypeError function "function () {
+                memberHolderObject[member.n..." did not throw
+FAIL Response interface: operation text() assert_throws: calling operation with this = null didn't throw TypeError function "function () {
+                memberHolderObject[member.n..." did not throw
+PASS Response must be primary interface of new Response() 
+PASS Stringification of new Response() 
+PASS Response interface: new Response() must inherit property "error" with the proper type (0) 
+PASS Response interface: new Response() must inherit property "redirect" with the proper type (1) 
+PASS Response interface: calling redirect(USVString,unsigned short) on new Response() with too few arguments must throw TypeError 
+PASS Response interface: new Response() must inherit property "type" with the proper type (2) 
+PASS Response interface: new Response() must inherit property "url" with the proper type (3) 
+PASS Response interface: new Response() must inherit property "status" with the proper type (4) 
+PASS Response interface: new Response() must inherit property "ok" with the proper type (5) 
+PASS Response interface: new Response() must inherit property "statusText" with the proper type (6) 
+PASS Response interface: new Response() must inherit property "headers" with the proper type (7) 
+PASS Response interface: new Response() must inherit property "body" with the proper type (8) 
+PASS Response interface: new Response() must inherit property "clone" with the proper type (9) 
+PASS Response interface: new Response() must inherit property "bodyUsed" with the proper type (10) 
+PASS Response interface: new Response() must inherit property "arrayBuffer" with the proper type (11) 
+PASS Response interface: new Response() must inherit property "blob" with the proper type (12) 
+PASS Response interface: new Response() must inherit property "formData" with the proper type (13) 
+PASS Response interface: new Response() must inherit property "json" with the proper type (14) 
+PASS Response interface: new Response() must inherit property "text" with the proper type (15) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-idl.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-idl.html
new file mode 100644 (file)
index 0000000..79ddf75
--- /dev/null
@@ -0,0 +1,69 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response idl interface</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/resources/WebIDLParser.js"></script>
+    <script src="/resources/idlharness.js"></script>
+  </head>
+  <body>
+    <script id="body-idl" type="text/plain">
+      typedef any JSON;
+      typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;
+
+      [NoInterfaceObject,
+      Exposed=(Window,Worker)]
+      interface Body {
+        readonly attribute boolean bodyUsed;
+        [NewObject] Promise<ArrayBuffer> arrayBuffer();
+        [NewObject] Promise<Blob> blob();
+        [NewObject] Promise<FormData> formData();
+        [NewObject] Promise<JSON> json();
+        [NewObject] Promise<USVString> text();
+      };
+    </script>
+    <script id="response-idl" type="text/plain">
+      [Constructor(optional BodyInit body, optional ResponseInit init),
+      Exposed=(Window,Worker)]
+      interface Response {
+        [NewObject] static Response error();
+        [NewObject] static Response redirect(USVString url, optional unsigned short status = 302);
+
+        readonly attribute ResponseType type;
+
+        readonly attribute USVString url;
+        readonly attribute unsigned short status;
+        readonly attribute boolean ok;
+        readonly attribute ByteString statusText;
+        [SameObject] readonly attribute Headers headers;
+        [SameObject] readonly attribute ReadableStream body;
+
+        [NewObject] Response clone();
+      };
+      Response implements Body;
+
+      dictionary ResponseInit {
+        unsigned short status = 200;
+        ByteString statusText = "OK";
+        HeadersInit headers;
+      };
+
+      enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };
+    </script>
+    <script>
+      var idlsArray = new IdlArray();
+      var idl = document.getElementById("body-idl").innerHTML
+      idl += document.getElementById("response-idl").innerHTML
+
+      idlsArray.add_idls(idl);
+      idlsArray.add_untested_idls("interface Headers {};");
+      idlsArray.add_untested_idls("interface ReadableStream {};");
+      idlsArray.add_objects({ Response: ['new Response()'] });
+      idlsArray.test();
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-001-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-001-expected.txt
new file mode 100644 (file)
index 0000000..97de405
--- /dev/null
@@ -0,0 +1,10 @@
+
+PASS Check default value for type attribute 
+PASS Check default value for url attribute 
+PASS Check default value for ok attribute 
+PASS Check default value for status attribute 
+PASS Check default value for statusText attribute 
+PASS Check default value for body attribute 
+PASS Check status init values and associated getter 
+PASS Check statusText init values and associated getter 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-001.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-001.html
new file mode 100644 (file)
index 0000000..e36f90e
--- /dev/null
@@ -0,0 +1,63 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response init: simple cases</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="help" href="https://fetch.spec.whatwg.org/#concept-response">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script>
+      var defaultValues = { "type" : "default",
+                            "url" : "",
+                            "ok" : true,
+                            "status" : 200,
+                            "statusText" : "OK",
+                            "body" : null
+      };
+
+      var statusCodes = { "givenValues" : [200, 300, 400, 500, 599],
+                       "expectedValues" : [200, 300, 400, 500, 599]
+      };
+      var statusTexts = { "givenValues" : ["OK", "with space", String.fromCharCode(0x80)],
+                       "expectedValues" : ["OK", "with space", String.fromCharCode(0x80)]
+      };
+      var initValuesDict = { "status" : statusCodes,
+                             "statusText" : statusTexts
+      };
+
+      function isOkStatus(status) {
+        return 200 <= status &&  299 >= status;
+      }
+
+      var response = new Response();
+      for (var attributeName in defaultValues) {
+        test(function() {
+          var expectedValue = defaultValues[attributeName];
+          assert_equals(response[attributeName], expectedValue,
+            "Expect default response." + attributeName + " is " + expectedValue);
+        }, "Check default value for " + attributeName + " attribute");
+      }
+
+      for (var attributeName in initValuesDict)
+        test(function() {
+          var valuesToTest = initValuesDict[attributeName];
+          for (var valueIdx in valuesToTest["givenValues"]) {
+            var givenValue = valuesToTest["givenValues"][valueIdx];
+            var expectedValue = valuesToTest["expectedValues"][valueIdx];
+            var responseInit = {};
+            responseInit[attributeName] = givenValue;
+            var response = new Response("", responseInit);
+            assert_equals(response[attributeName], expectedValue,
+              "Expect response." + attributeName + " is " + expectedValue +
+              " when initialized with " + givenValue);
+            assert_equals(response.ok, isOkStatus(response.status),
+              "Expect response.ok is " + isOkStatus(response.status));
+          }
+        }, "Check " + attributeName + " init values and associated getter");
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt
new file mode 100644 (file)
index 0000000..ab60ee1
--- /dev/null
@@ -0,0 +1,8 @@
+
+PASS Initialize Response with headers values 
+FAIL Initialize Response's body with application/octet-binary promise_test: Unhandled rejection with value: undefined
+FAIL Initialize Response's body with multipart/form-data promise_test: Unhandled rejection with value: undefined
+FAIL Initialize Response's body with application/x-www-form-urlencoded;charset=UTF-8 assert_true: Content-Type header should be "application/x-www-form-urlencoded;charset=UTF-8"  expected true got false
+PASS Initialize Response's body with text/plain;charset=UTF-8 
+FAIL Read Response's body as readableStream null is not an object (evaluating 'response.body.getReader')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002.html
new file mode 100644 (file)
index 0000000..1baf7fb
--- /dev/null
@@ -0,0 +1,62 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response init: body and headers</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="help" href="https://fetch.spec.whatwg.org/#concept-response">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script src="../resources/utils.js"></script>
+    <script>
+      test(function() {
+        var headerDict = {"name1": "value1",
+                          "name2": "value2",
+                          "name3": "value3"
+        };
+        var headers = new Headers(headerDict);
+        var response = new Response("", { "headers" : headers })
+        for (var name in headerDict) {
+          assert_equals(response.headers.get(name), headerDict[name],
+           "response's headers has " + name + " : " + headerDict[name]);
+        }
+      }, "Initialize Response with headers values");
+
+      function checkResponseInit(body, bodyType, expectedTextBody) {
+        promise_test(function(test) {
+          var response = new Response(body);
+          var resHeaders = response.headers;
+          var mime = resHeaders.get("Content-Type");
+          assert_true(mime && mime.search(bodyType) > -1, "Content-Type header should be \"" + bodyType + "\" ");
+          return response.text().then(function(bodyAsText) {
+            //not equals: cannot guess formData exact value
+            assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify response body");
+          });
+        }, "Initialize Response's body with " + bodyType);
+      }
+
+      var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
+      var formaData = new FormData();
+      formaData.append("name", "value");
+      var urlSearchParams = "URLSearchParams are not supported";
+      //avoid test timeout if not implemented
+      if (window.URLSearchParams)
+        urlSearchParams = new URLSearchParams("name=value");
+      var usvString = "This is a USVString"
+
+      checkResponseInit(blob, "application/octet-binary", "This is a blob");
+      checkResponseInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
+      checkResponseInit(urlSearchParams, "application/x-www-form-urlencoded;charset=UTF-8", "name=value");
+      checkResponseInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
+
+      async_test(function(test) {
+        var body = "This is response body";
+        var response = new Response(body);
+        readTextStream(response.body.getReader(), test, body);
+      }, "Read Response's body as readableStream");
+    </script>
+  </body>
+</html>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-error-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-error-expected.txt
new file mode 100644 (file)
index 0000000..0a5c85e
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Check response returned by static method error() 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-error.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-error.html
new file mode 100644 (file)
index 0000000..d63bd5e
--- /dev/null
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response: error static method</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="help" href="https://fetch.spec.whatwg.org/#concept-network-error">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script>
+      test(function() {
+        var responseError = Response.error();
+        assert_equals(responseError.type, "error", "Network error response's type is error");
+        assert_equals(responseError.status, 0, "Network error response's status is 0");
+        assert_equals(responseError.statusText, "", "Network error response's statusText is empty");
+        assert_equals(responseError.body, null, "Network error response's body is null");
+      }, "Check response returned by static method error()");
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect-expected.txt
new file mode 100644 (file)
index 0000000..7fd27fd
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS Check response returned by static method redirect() 
+FAIL Check error returned when giving invalid parameters to redirect() assert_throws: Expect RangeError exception function "function () { Response.redirect("", invalidStatus); }" threw object "TypeError: Type error" ("TypeError") expected object "RangeError" ("RangeError")
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect.html
new file mode 100644 (file)
index 0000000..1dc092f
--- /dev/null
@@ -0,0 +1,41 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Response: redirect static method</title>
+    <meta name="help" href="https://fetch.spec.whatwg.org/#response">
+    <meta name="help" href="https://fetch.spec.whatwg.org/#redirect-status">
+    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script>
+      test(function() {
+        var redirectStatus = [301, 302, 303, 307, 308];
+        var url = "http://test.url:1234/";
+        redirectResponse = Response.redirect(url);
+        assert_equals(redirectResponse.status, 302, "Default redictect status is 302");
+        assert_equals(redirectResponse.headers.get("Location"), url,
+          "redirected response has Location header with the correct url");
+        for (var i in redirectStatus) {
+          var status = redirectStatus[i];
+          redirectResponse = Response.redirect(url, status);
+          assert_equals(redirectResponse.status, status, "Redictect status is " + status);
+        }
+      }, "Check response returned by static method redirect()");
+
+      test(function() {
+        var invalidRedirectStatus = [200, 309, 400, 500];
+        var invalidUrl = "This is not an url";
+        for (var i in invalidRedirectStatus) {
+          var invalidStatus = invalidRedirectStatus[i];
+          assert_throws(new RangeError() , function() { Response.redirect("", invalidStatus); },
+            "Expect RangeError exception");
+        }
+        assert_throws(new TypeError(), function() { Response.redirect(invalidUrl); },
+          "Expect TypeError exception");
+      }, "Check error returned when giving invalid parameters to redirect()");
+    </script>
+  </body>
+</html>
\ No newline at end of file
index ffd9531..e058cff 100644 (file)
@@ -169,6 +169,11 @@ PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty(
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Set').value is Set
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Set').hasOwnProperty('get') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Set').hasOwnProperty('set') is false
index 15a4aea..b0078e3 100644 (file)
@@ -993,6 +993,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index fc7204f..2cc9ac3 100644 (file)
@@ -69,6 +69,11 @@ PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty(
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS [Worker] Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'URL').value is URL
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'URL').hasOwnProperty('get') is false
 PASS [Worker] Object.getOwnPropertyDescriptor(global, 'URL').hasOwnProperty('set') is false
index 012bf08..08e4f5c 100644 (file)
@@ -1063,6 +1063,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index c4e5c4c..5d88e5d 100644 (file)
@@ -1083,6 +1083,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index e60e455..25b73f7 100644 (file)
@@ -1073,6 +1073,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index 774478e..03c2f8a 100644 (file)
@@ -1198,6 +1198,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index bda4165..77d488b 100644 (file)
@@ -1198,6 +1198,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index 540f9a5..c2a9551 100644 (file)
@@ -913,6 +913,11 @@ PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('get') is
 PASS Object.getOwnPropertyDescriptor(global, 'Request').hasOwnProperty('set') is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').enumerable is false
 PASS Object.getOwnPropertyDescriptor(global, 'Request').configurable is true
+PASS Object.getOwnPropertyDescriptor(global, 'Response').value is Response
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('get') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').hasOwnProperty('set') is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').enumerable is false
+PASS Object.getOwnPropertyDescriptor(global, 'Response').configurable is true
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').value is SQLException
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('get') is false
 PASS Object.getOwnPropertyDescriptor(global, 'SQLException').hasOwnProperty('set') is false
index c6fdad4..74014d3 100644 (file)
@@ -166,6 +166,7 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/fetch/FetchBody.idl
     Modules/fetch/FetchHeaders.idl
     Modules/fetch/FetchRequest.idl
+    Modules/fetch/FetchResponse.idl
 
     Modules/geolocation/Coordinates.idl
     Modules/geolocation/Geolocation.idl
@@ -813,6 +814,7 @@ set(WebCore_SOURCES
     Modules/fetch/FetchBody.cpp
     Modules/fetch/FetchHeaders.cpp
     Modules/fetch/FetchRequest.cpp
+    Modules/fetch/FetchResponse.cpp
 
     Modules/geolocation/Coordinates.cpp
     Modules/geolocation/GeoNotifier.cpp
@@ -3665,6 +3667,7 @@ GENERATE_BINDINGS(WebCoreTestSupport_SOURCES
 
 set(WebCore_BUILTINS_SOURCES
     ${WEBCORE_DIR}/Modules/fetch/FetchHeaders.js
+    ${WEBCORE_DIR}/Modules/fetch/FetchResponse.js
     ${WEBCORE_DIR}/Modules/mediastream/MediaDevices.js
     ${WEBCORE_DIR}/Modules/mediastream/NavigatorUserMedia.js
     ${WEBCORE_DIR}/Modules/mediastream/RTCPeerConnection.js
index 05cdffa..525359b 100644 (file)
@@ -1,3 +1,61 @@
+2016-02-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Fetch API] Implement Fetch API Response
+        https://bugs.webkit.org/show_bug.cgi?id=154536
+
+        Reviewed by Alex Christensen.
+
+        Tests: imported/w3c/web-platform-tests/fetch/api/response/response-clone.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-consume.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-error.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-idl.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-init-001.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-init-002.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-static-error.html
+               imported/w3c/web-platform-tests/fetch/api/response/response-static-redirect.html
+
+        Adding Fetch Response as FetchResponse class.
+        Constructor uses a built-in to pre-process the parameters.
+        Support of body as ReadableStream is missing.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::empty):
+        * Modules/fetch/FetchResponse.cpp: Added.
+        (WebCore::JSFetchResponse::body):
+        (WebCore::isRedirectStatus):
+        (WebCore::isNullBodyStatus):
+        (WebCore::FetchResponse::error):
+        (WebCore::FetchResponse::redirect):
+        (WebCore::FetchResponse::initializeWith):
+        (WebCore::FetchResponse::FetchResponse):
+        (WebCore::FetchResponse::clone):
+        (WebCore::FetchResponse::type):
+        * Modules/fetch/FetchResponse.h: Added.
+        (WebCore::FetchResponse::create):
+        (WebCore::FetchResponse::redirect):
+        (WebCore::FetchResponse::url):
+        (WebCore::FetchResponse::redirected):
+        (WebCore::FetchResponse::status):
+        (WebCore::FetchResponse::ok):
+        (WebCore::FetchResponse::statusText):
+        (WebCore::FetchResponse::headers):
+        (WebCore::FetchResponse::isDisturbed):
+        (WebCore::FetchResponse::arrayBuffer):
+        (WebCore::FetchResponse::formData):
+        (WebCore::FetchResponse::blob):
+        (WebCore::FetchResponse::json):
+        (WebCore::FetchResponse::text):
+        * Modules/fetch/FetchResponse.idl: Added.
+        * Modules/fetch/FetchResponse.js: Added.
+        (initializeFetchResponse):
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreJSBuiltins.cpp:
+        * bindings/js/WebCoreJSBuiltins.h:
+        (WebCore::JSBuiltinFunctions::JSBuiltinFunctions):
+        (WebCore::JSBuiltinFunctions::fetchResponseBuiltins):
+
 2016-02-24  Ryosuke Niwa  <rniwa@webkit.org>
 
         A function named canTakeNextToken executing blocking scripts is misleading
index 38078d8..a4a48e2 100644 (file)
 #include "JSFetchBody.cpp"
 #include "JSFetchHeaders.cpp"
 #include "JSFetchRequest.cpp"
+#include "JSFetchResponse.cpp"
 #include "JSFile.cpp"
 #include "JSFileError.cpp"
 #include "JSFileException.cpp"
index 46a19db..dc7c8d9 100644 (file)
@@ -82,6 +82,7 @@ NON_SVG_BINDING_IDLS = \
     $(WebCore)/Modules/fetch/FetchBody.idl \
     $(WebCore)/Modules/fetch/FetchHeaders.idl \
     $(WebCore)/Modules/fetch/FetchRequest.idl \
+    $(WebCore)/Modules/fetch/FetchResponse.idl \
     $(WebCore)/Modules/gamepad/Gamepad.idl \
     $(WebCore)/Modules/gamepad/GamepadButton.idl \
     $(WebCore)/Modules/gamepad/GamepadEvent.idl \
@@ -1271,6 +1272,7 @@ WebReplayInputs.h : $(INPUT_GENERATOR_SPECIFICATIONS) $(INPUT_GENERATOR_SCRIPTS)
 
 WebCore_BUILTINS_SOURCES = \
     $(WebCore)/Modules/fetch/FetchHeaders.js \
+    $(WebCore)/Modules/fetch/FetchResponse.js \
     $(WebCore)/Modules/mediastream/MediaDevices.js \
     $(WebCore)/Modules/mediastream/NavigatorUserMedia.js \
     $(WebCore)/Modules/mediastream/RTCPeerConnection.js \
index 43627a2..49f10d5 100644 (file)
@@ -70,6 +70,7 @@ public:
 
     static FetchBody fromJSValue(JSC::ExecState&, JSC::JSValue);
     static FetchBody fromRequestBody(FetchBody*);
+    static FetchBody empty() { return FetchBody(); }
 
 private:
     template<typename T> bool processIfEmptyOrDisturbed(DOMPromise<T, ExceptionCode>&);
diff --git a/Source/WebCore/Modules/fetch/FetchResponse.cpp b/Source/WebCore/Modules/fetch/FetchResponse.cpp
new file mode 100644 (file)
index 0000000..4e3262f
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * 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 "FetchResponse.h"
+
+#if ENABLE(FETCH_API)
+
+#include "Dictionary.h"
+#include "ExceptionCode.h"
+#include "JSFetchResponse.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+static inline bool isRedirectStatus(int status)
+{
+    return status == 301 || status == 302 || status == 303 || status == 307 || status == 308;
+}
+
+static inline bool isNullBodyStatus(int status)
+{
+    return status == 101 || status == 204 || status == 205 || status == 304;
+}
+
+Ref<FetchResponse> FetchResponse::error()
+{
+    return adoptRef(*new FetchResponse(Type::Error, FetchBody::empty(), FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
+}
+
+RefPtr<FetchResponse> FetchResponse::redirect(ScriptExecutionContext* context, const String& url, int status, ExceptionCode& ec)
+{
+    // FIXME: Tighten the URL parsing algorithm according https://url.spec.whatwg.org/#concept-url-parser.
+    URL requestURL = context->completeURL(url);
+    if (!requestURL.isValid() || !requestURL.user().isEmpty() || !requestURL.pass().isEmpty()) {
+        ec = TypeError;
+        return nullptr;
+    }
+    if (!isRedirectStatus(status)) {
+        ec = TypeError;
+        return nullptr;
+    }
+    RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(Type::Default, FetchBody::empty(), FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
+    redirectResponse->m_response.setHTTPStatusCode(status);
+    redirectResponse->m_headers->fastSet(HTTPHeaderName::Location, requestURL.string());
+    return redirectResponse;
+}
+
+void FetchResponse::initializeWith(const Dictionary& init, ExceptionCode& ec)
+{
+    int status;
+    if (!init.get("status", status)) {
+        ec = TypeError;
+        return;
+    }
+    if (status < 200 || status > 599) {
+        ec = RangeError;
+        return;
+    }
+
+    // FIXME: Validate reason phrase (https://tools.ietf.org/html/rfc7230#section-3.1.2).
+    String statusText;
+    if (!init.get("statusText", statusText)) {
+        ec = TypeError;
+        return;
+    }
+    m_response.setHTTPStatusCode(status);
+    m_response.setHTTPStatusText(statusText);
+
+    RefPtr<FetchHeaders> initialHeaders;
+    if (init.get("headers", initialHeaders))
+        m_headers->fill(initialHeaders.get());
+
+    JSC::JSValue body;
+    if (init.get("body", body)) {
+        if (isNullBodyStatus(status)) {
+            ec = TypeError;
+            return;
+        }
+        m_body = FetchBody::fromJSValue(*init.execState(), body);
+        if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty())
+            m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType());
+    }
+}
+
+FetchResponse::FetchResponse(Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
+    : m_type(type)
+    , m_response(WTFMove(response))
+    , m_body(WTFMove(body))
+    , m_headers(WTFMove(headers))
+{
+}
+
+RefPtr<FetchResponse> FetchResponse::clone(ExceptionCode& ec)
+{
+    if (m_body.isDisturbed() || m_isLocked) {
+        ec = TypeError;
+        return nullptr;
+    }
+    RefPtr<FetchResponse> cloned = adoptRef(*new FetchResponse(m_type, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
+    cloned->m_isRedirected = m_isRedirected;
+    return cloned;
+}
+
+String FetchResponse::type() const
+{
+    switch (m_type) {
+    case Type::Basic:
+        return ASCIILiteral("basic");
+    case Type::Cors:
+        return ASCIILiteral("cors");
+    case Type::Default:
+        return ASCIILiteral("default");
+    case Type::Error:
+        return ASCIILiteral("error");
+    case Type::Opaque:
+        return ASCIILiteral("opaque");
+    case Type::OpaqueRedirect:
+        return ASCIILiteral("opaqueredirect");
+    };
+    ASSERT_NOT_REACHED();
+    return String();
+}
+
+// FIXME: Implement this, as a custom or through binding generator.
+JSC::JSValue JSFetchResponse::body(JSC::ExecState&) const
+{
+    return JSC::jsNull();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FETCH_API)
diff --git a/Source/WebCore/Modules/fetch/FetchResponse.h b/Source/WebCore/Modules/fetch/FetchResponse.h
new file mode 100644 (file)
index 0000000..01692ef
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef FetchResponse_h
+#define FetchResponse_h
+
+#if ENABLE(FETCH_API)
+
+#include "FetchBody.h"
+#include "FetchHeaders.h"
+#include "ResourceResponse.h"
+
+namespace JSC {
+class ArrayBuffer;
+};
+
+namespace WebCore {
+
+class Dictionary;
+
+typedef int ExceptionCode;
+
+class FetchResponse : public RefCounted<FetchResponse> {
+public:
+    static Ref<FetchResponse> create() { return adoptRef(*new FetchResponse(Type::Default, FetchBody::empty(), FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
+    static Ref<FetchResponse> error();
+    static RefPtr<FetchResponse> redirect(ScriptExecutionContext*, const String&, int, ExceptionCode&);
+    // FIXME: Binding generator should not require below method to handle optional status parameter.
+    static RefPtr<FetchResponse> redirect(ScriptExecutionContext* context, const String& url, ExceptionCode& ec) { return redirect(context, url, 302, ec); }
+
+    void initializeWith(const Dictionary&, ExceptionCode&);
+
+    String type() const;
+    const String& url() const { return m_response.url().string(); }
+    bool redirected() const { return m_isRedirected; }
+    int status() const { return m_response.httpStatusCode(); }
+    bool ok() const { return status() >= 200 && status() <= 299; }
+    const String& statusText() const { return m_response.httpStatusText(); }
+
+    FetchHeaders& headers() { return m_headers; }
+    RefPtr<FetchResponse> clone(ExceptionCode&);
+
+    // Body API
+    bool isDisturbed() const { return m_body.isDisturbed(); }
+    void arrayBuffer(FetchBody::ArrayBufferPromise&& promise) { m_body.arrayBuffer(WTFMove(promise)); }
+    void formData(FetchBody::FormDataPromise&& promise) { m_body.formData(WTFMove(promise)); }
+    void blob(FetchBody::BlobPromise&& promise) { m_body.blob(WTFMove(promise)); }
+    void json(JSC::ExecState& state, FetchBody::JSONPromise&& promise) { m_body.json(state, WTFMove(promise)); }
+    void text(FetchBody::TextPromise&& promise) { m_body.text(WTFMove(promise)); }
+
+private:
+    enum class Type { Basic, Cors, Default, Error, Opaque, OpaqueRedirect };
+
+    FetchResponse(Type, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
+
+    Type m_type;
+    ResourceResponse m_response;
+    FetchBody m_body;
+    Ref<FetchHeaders> m_headers;
+    bool m_isLocked = false;
+    bool m_isRedirected = false;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FETCH_API)
+
+#endif // FetchResponse_h
diff --git a/Source/WebCore/Modules/fetch/FetchResponse.idl b/Source/WebCore/Modules/fetch/FetchResponse.idl
new file mode 100644 (file)
index 0000000..e70f4b9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };
+
+[
+    Conditional=FETCH_API,
+    GlobalContext=DOMWindow&WorkerGlobalScope,
+    ImplementationLacksVTable,
+    InterfaceName=Response,
+    JSBuiltinConstructor
+]
+interface FetchResponse {
+    // FIXME: NewObject does not seem to be supported for static methods.
+    static FetchResponse error();
+    [RaisesException, CallWith=ScriptExecutionContext] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
+
+    readonly attribute ResponseType type;
+
+    readonly attribute DOMString url;
+    readonly attribute boolean redirected;
+    readonly attribute unsigned short status;
+    readonly attribute boolean ok;
+    readonly attribute DOMString statusText;
+    // FIXME: Add support for SameObject keyword for headers
+    readonly attribute FetchHeaders headers;
+    [Custom, RaisesException] readonly attribute ReadableStream? body;
+
+    [NewObject, RaisesException] FetchResponse clone();
+
+    [Private, RaisesException] void initializeWith(Dictionary parameters);
+};
+FetchResponse implements FetchBody;
diff --git a/Source/WebCore/Modules/fetch/FetchResponse.js b/Source/WebCore/Modules/fetch/FetchResponse.js
new file mode 100644 (file)
index 0000000..f2b534e
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 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.
+ */
+
+// @conditional=ENABLE(FETCH_API)
+
+function initializeFetchResponse(body, init)
+{
+    "use strict";
+
+    let parameters = { };
+    if (init !== @undefined) {
+        if (!@isObject(init))
+            throw new @TypeError("Response init must be an object");
+        parameters.status = init.status;
+        parameters.statusText = init.statusText;
+        // FIXME: Shield this from user scripts.
+        if (init.headers)
+            parameters.headers = (this.headers.constructor === init.headers.constructor) ? init.headers : new this.headers.constructor(init.headers);
+    }
+    if (parameters.status === @undefined)
+        parameters.status = 200;
+    if (parameters.statusText === @undefined)
+        parameters.statusText = "OK";
+
+    if (body !== @undefined && body !== null)
+         parameters.body = body;
+
+    this.@initializeWith(parameters);
+    return this;
+}
index 21562fc..d360897 100644 (file)
                4127D5370F8AAB1D00E424F5 /* ScriptState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */; };
                4129DF851BB5B80700322A16 /* JSReadableStreamPrivateConstructors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4129DF831BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.cpp */; };
                4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               413015D91C7B571400091C6E /* FetchResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413015D51C7B570400091C6E /* FetchResponse.cpp */; };
                4138D3351244054800323D33 /* EventContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4138D3331244054800323D33 /* EventContext.h */; };
                4138D3361244054800323D33 /* EventContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4138D3341244054800323D33 /* EventContext.cpp */; };
                413C2C341BC29A8F0075204C /* JSDOMConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 413C2C331BC29A7B0075204C /* JSDOMConstructor.h */; };
                7E474E1E12494DC900235364 /* SQLiteDatabaseTrackerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E474E1B12494DC900235364 /* SQLiteDatabaseTrackerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7E474E1F12494DC900235364 /* SQLiteDatabaseTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E474E1C12494DC900235364 /* SQLiteDatabaseTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7E474E2012494DC900235364 /* SQLiteDatabaseTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E474E1D12494DC900235364 /* SQLiteDatabaseTracker.cpp */; };
-               7E4C96DC1AD4483500365A50 /* JSFetchRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A50 /* JSFetchRequest.cpp */; };
                7E4C96DD1AD4483500365A50 /* JSFetchRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4C96D91AD4483500365A50 /* JSFetchRequest.h */; };
+               7E4C96DC1AD4483500365A50 /* JSFetchRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A50 /* JSFetchRequest.cpp */; };
+               8E4C96DD1AD4483500365A50 /* JSFetchResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E4C96D91AD4483500365A50 /* JSFetchResponse.h */; };
+               8E4C96DC1AD4483500365A50 /* JSFetchResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8E4C96D81AD4483500365A50 /* JSFetchResponse.cpp */; };
                7E4DE10D198B10B60051CB02 /* DiskCacheMonitorCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7E4DE10C198B10B60051CB02 /* DiskCacheMonitorCocoa.mm */; };
                7E5D7A76161D3F8F00896C34 /* OESElementIndexUint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E5D7A73161D3F8F00896C34 /* OESElementIndexUint.cpp */; };
                7E5D7A77161D3F8F00896C34 /* OESElementIndexUint.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E5D7A74161D3F8F00896C34 /* OESElementIndexUint.h */; };
                4129DF821BB5B7A600322A16 /* ReadableStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamReader.h; sourceTree = "<group>"; };
                4129DF831BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamPrivateConstructors.cpp; sourceTree = "<group>"; };
                4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSReadableStreamPrivateConstructors.h; sourceTree = "<group>"; };
+               413015D51C7B570400091C6E /* FetchResponse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchResponse.cpp; sourceTree = "<group>"; };
+               413015D61C7B570400091C6E /* FetchResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchResponse.h; sourceTree = "<group>"; };
+               413015D71C7B570400091C6E /* FetchResponse.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchResponse.idl; sourceTree = "<group>"; };
+               413015D81C7B570400091C6E /* FetchResponse.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = FetchResponse.js; sourceTree = "<group>"; };
                4138D3331244054800323D33 /* EventContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventContext.h; sourceTree = "<group>"; };
                4138D3341244054800323D33 /* EventContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventContext.cpp; sourceTree = "<group>"; };
                413C2C331BC29A7B0075204C /* JSDOMConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMConstructor.h; sourceTree = "<group>"; };
                7E474E1D12494DC900235364 /* SQLiteDatabaseTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SQLiteDatabaseTracker.cpp; sourceTree = "<group>"; };
                7E4C96D81AD4483500365A50 /* JSFetchRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchRequest.cpp; sourceTree = "<group>"; };
                7E4C96D91AD4483500365A50 /* JSFetchRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFetchRequest.h; sourceTree = "<group>"; };
+               8E4C96D81AD4483500365A50 /* JSFetchResponse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchResponse.cpp; sourceTree = "<group>"; };
+               8E4C96D91AD4483500365A50 /* JSFetchResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFetchResponse.h; sourceTree = "<group>"; };
                7E4DE10C198B10B60051CB02 /* DiskCacheMonitorCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DiskCacheMonitorCocoa.mm; sourceTree = "<group>"; };
                7E5D7A73161D3F8F00896C34 /* OESElementIndexUint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OESElementIndexUint.cpp; sourceTree = "<group>"; };
                7E5D7A74161D3F8F00896C34 /* OESElementIndexUint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OESElementIndexUint.h; sourceTree = "<group>"; };
                                41F54F871C50C4F600338488 /* FetchRequest.cpp */,
                                41F54F881C50C4F600338488 /* FetchRequest.h */,
                                41F54F891C50C4F600338488 /* FetchRequest.idl */,
+                               413015D51C7B570400091C6E /* FetchResponse.cpp */,
+                               413015D61C7B570400091C6E /* FetchResponse.h */,
+                               413015D71C7B570400091C6E /* FetchResponse.idl */,
+                               413015D81C7B570400091C6E /* FetchResponse.js */,
                        );
                        path = fetch;
                        sourceTree = "<group>";
                                7E4C96D91AD4483500365A50 /* JSFetchRequest.h */,
                                7D4C96D81AD4483500365A50 /* JSFetchHeaders.cpp */,
                                7D4C96D91AD4483500365A50 /* JSFetchHeaders.h */,
+                               8E4C96D81AD4483500365A50 /* JSFetchResponse.cpp */,
+                               8E4C96D91AD4483500365A50 /* JSFetchResponse.h */,
                        );
                        name = FetchAPI;
                        sourceTree = "<group>";
                                65DF320209D1CC60000BE325 /* JSRange.h in Headers */,
                                7F4C96DD1AD4483500365A50 /* JSFetchBody.h in Headers */,
                                7E4C96DD1AD4483500365A50 /* JSFetchRequest.h in Headers */,
+                               8E4C96DD1AD4483500365A50 /* JSFetchResponse.h in Headers */,
                                7D4C96DD1AD4483500365A50 /* JSFetchHeaders.h in Headers */,
                                7C4C96DD1AD4483500365A50 /* JSReadableStream.h in Headers */,
                                6C4C96DF1AD4483500365A50 /* JSReadableStreamController.h in Headers */,
                                7F4C96DC1AD4483500365A50 /* JSFetchBody.cpp in Sources */,
                                7D4C96DC1AD4483500365A50 /* JSFetchHeaders.cpp in Sources */,
                                7E4C96DC1AD4483500365A50 /* JSFetchRequest.cpp in Sources */,
+                               8E4C96DC1AD4483500365A50 /* JSFetchResponse.cpp in Sources */,
                                7C4C96DC1AD4483500365A50 /* JSReadableStream.cpp in Sources */,
                                6C4C96DE1AD4483500365A50 /* JSReadableStreamController.cpp in Sources */,
                                4129DF851BB5B80700322A16 /* JSReadableStreamPrivateConstructors.cpp in Sources */,
                                D3F3D3671A69B1A50059FC2B /* JSWebGLRenderingContextBase.cpp in Sources */,
                                D3F3D36B1A69B7C50059FC2B /* JSWebGLRenderingContextBaseCustom.cpp in Sources */,
                                49EED14F1051971A00099FAB /* JSWebGLRenderingContextCustom.cpp in Sources */,
+                               413015D91C7B571400091C6E /* FetchResponse.cpp in Sources */,
                                6F995A331A70833700A735F4 /* JSWebGLSampler.cpp in Sources */,
                                49C7B9A21042D2D30009D447 /* JSWebGLShader.cpp in Sources */,
                                A07D3355152B630E001B6393 /* JSWebGLShaderPrecisionFormat.cpp in Sources */,
index d109942..f712903 100644 (file)
@@ -29,6 +29,7 @@
 #include "ByteLengthQueuingStrategyBuiltins.cpp"
 #include "CountQueuingStrategyBuiltins.cpp"
 #include "FetchHeadersBuiltins.cpp"
+#include "FetchResponseBuiltins.cpp"
 #include "MediaDevicesBuiltins.cpp"
 #include "NavigatorUserMediaBuiltins.cpp"
 #include "RTCPeerConnectionBuiltins.cpp"
index 95f6b97..f5f1a52 100644 (file)
@@ -30,6 +30,7 @@
 #include "ByteLengthQueuingStrategyBuiltins.h"
 #include "CountQueuingStrategyBuiltins.h"
 #include "FetchHeadersBuiltins.h"
+#include "FetchResponseBuiltins.h"
 #include "MediaDevicesBuiltins.h"
 #include "NavigatorUserMediaBuiltins.h"
 #include "RTCPeerConnectionBuiltins.h"
@@ -51,6 +52,7 @@ public:
         : vm(v)
 #if ENABLE(FETCH_API)
         , m_fetchHeadersBuiltins(&vm)
+        , m_fetchResponseBuiltins(&vm)
 #endif
 #if ENABLE(STREAMS_API)
         , m_byteLengthQueuingStrategyBuiltins(&vm)
@@ -81,6 +83,7 @@ public:
     }
 #if ENABLE(FETCH_API)
     FetchHeadersBuiltinsWrapper& fetchHeadersBuiltins() { return m_fetchHeadersBuiltins; }
+    FetchResponseBuiltinsWrapper& fetchResponseBuiltins() { return m_fetchResponseBuiltins; }
 #endif
 #if ENABLE(STREAMS_API)
     ByteLengthQueuingStrategyBuiltinsWrapper& byteLengthQueuingStrategyBuiltins() { return m_byteLengthQueuingStrategyBuiltins; }
@@ -104,6 +107,7 @@ private:
     JSC::VM& vm;
 #if ENABLE(FETCH_API)
     FetchHeadersBuiltinsWrapper m_fetchHeadersBuiltins;
+    FetchResponseBuiltinsWrapper m_fetchResponseBuiltins;
 #endif
 #if ENABLE(STREAMS_API)
     ByteLengthQueuingStrategyBuiltinsWrapper m_byteLengthQueuingStrategyBuiltins;