Title: [248283] trunk
Revision
248283
Author
[email protected]
Date
2019-08-05 17:36:09 -0700 (Mon, 05 Aug 2019)

Log Message

LayoutTests/imported/w3c:
Response constructor doesn't throw on disturbed ReadableStream
https://bugs.webkit.org/show_bug.cgi?id=200130
<rdar://problem/53550351>

Reviewed by Alex Christensen.

Update test to use promise_rejects instead of assert_throws.

* web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt:
* web-platform-tests/fetch/api/request/request-init-stream.any.js:
(async.assert_request):
(promise_test.async):
* web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt:
* web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt:
* web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt:

Source/WebCore:
Response constructor doesn't throw on disturbed ReadableStream
https://bugs.webkit.org/show_bug.cgi?id=200130
<rdar://problem/53550351>

Reviewed by Alex Christensen.

Make FetchBody::extract return an exception in error cases.
Update call sites accordingly.
Add the error case as per https://fetch.spec.whatwg.org/#concept-bodyinit-extract, ReadableStream handling.

Covered by updated and rebased tests.

* Modules/beacon/NavigatorBeacon.cpp:
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract):
* Modules/fetch/FetchBody.h:
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::extractBody):
* Modules/fetch/FetchBodyOwner.h:
* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::initializeWith):
(WebCore::FetchRequest::setBody):
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::create):
* Modules/streams/ReadableStreamInternals.js:
(readableStreamPipeTo): fix a case where the promise would be unhandled and would show up in
unhandledrejectionhandler.

LayoutTests:
Support RTCRtpSender.dtmf
https://bugs.webkit.org/show_bug.cgi?id=200431
<rdar://problem/53924833>

Reviewed by Alex Christensen.

Removed cache storage test which is no longer valid.
Removed WK1 expectation that is no longer needed.

* http/wpt/cache-storage/cache-put-stream.https.any.html: Removed.
* http/wpt/cache-storage/cache-put-stream.https.any.js: Removed.
* http/wpt/cache-storage/cache-put-stream.https.any.worker.html: Removed.
* platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt: Removed.
* platform/mac-wk2/TestExpectations:

Modified Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (248282 => 248283)


--- trunk/LayoutTests/ChangeLog	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/ChangeLog	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,3 +1,20 @@
+2019-08-05  Youenn Fablet  <[email protected]>
+
+        Support RTCRtpSender.dtmf
+        https://bugs.webkit.org/show_bug.cgi?id=200431
+        <rdar://problem/53924833>
+
+        Reviewed by Alex Christensen.
+
+        Removed cache storage test which is no longer valid.
+        Removed WK1 expectation that is no longer needed.
+
+        * http/wpt/cache-storage/cache-put-stream.https.any.html: Removed.
+        * http/wpt/cache-storage/cache-put-stream.https.any.js: Removed.
+        * http/wpt/cache-storage/cache-put-stream.https.any.worker.html: Removed.
+        * platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt: Removed.
+        * platform/mac-wk2/TestExpectations:
+
 2019-08-05  Devin Rousso  <[email protected]>
 
         Web Inspector: Styles: variable swatch not shown for var() with a fallback

Deleted: trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.html (248282 => 248283)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.html	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.html	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1 +0,0 @@
-<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Deleted: trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.js (248282 => 248283)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.js	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.js	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,31 +0,0 @@
-// META: script=/service-workers/cache-storage/resources/test-helpers.js
-
-var test_url = 'https://example.com/foo';
-var test_body = 'Hello world!';
-
-cache_test(function(cache) {
-    var stream = new ReadableStream();
-    stream.getReader();
-    var response = new Response(stream);
-    return cache.put(new Request(''), response).then(assert_unreached, (e) => {
-        assert_throws(new TypeError, function() { throw e });
-    });
-}, 'Cache.put should throw if response stream is locked')
-
-cache_test(function(cache) {
-    var stream = new ReadableStream({start: (c) => {
-        c.enqueue(new Uint8Array(1));
-        c.enqueue(new Uint8Array(1));
-        c.close();
-    }});
-    var reader = stream.getReader();
-    return reader.read().then(() => {
-        reader.releaseLock();
-        var response = new Response(stream);
-        return cache.put(new Request(''), response).then(assert_unreached, (e) => {
-            assert_throws(new TypeError, function() { throw e });
-        });
-    });
-}, 'Cache.put should throw if response stream is disturbed')
-
-done();

Deleted: trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.worker.html (248282 => 248283)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.worker.html	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-stream.https.any.worker.html	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1 +0,0 @@
-<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (248282 => 248283)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,5 +1,23 @@
 2019-08-05  Youenn Fablet  <[email protected]>
 
+        Response constructor doesn't throw on disturbed ReadableStream
+        https://bugs.webkit.org/show_bug.cgi?id=200130
+        <rdar://problem/53550351>
+
+        Reviewed by Alex Christensen.
+
+        Update test to use promise_rejects instead of assert_throws.
+
+        * web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt:
+        * web-platform-tests/fetch/api/request/request-init-stream.any.js:
+        (async.assert_request):
+        (promise_test.async):
+        * web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt:
+        * web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt:
+        * web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt:
+
+2019-08-05  Youenn Fablet  <[email protected]>
+
         Support RTCRtpSender.dtmf
         https://bugs.webkit.org/show_bug.cgi?id=200431
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt (248282 => 248283)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,8 +1,8 @@
 
-FAIL Constructing a Request with a stream on which getReader() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a stream on which read() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a stream on which read() and releaseLock() are called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a Request on which body.getReader() is called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-FAIL Constructing a Request with a Request on which body.getReader().read() is called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-FAIL Constructing a Request with a Request on which read() and releaseLock() are called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
+PASS Constructing a Request with a stream on which getReader() is called 
+PASS Constructing a Request with a stream on which read() is called 
+PASS Constructing a Request with a stream on which read() and releaseLock() are called 
+PASS Constructing a Request with a Request on which body.getReader() is called 
+PASS Constructing a Request with a Request on which body.getReader().read() is called 
+PASS Constructing a Request with a Request on which read() and releaseLock() are called 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.js (248282 => 248283)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.js	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.js	2019-08-06 00:36:09 UTC (rev 248283)
@@ -2,50 +2,50 @@
 
 "use strict";
 
-async function assert_request(input, init) {
+async function assert_request(t, input, init) {
   assert_throws(new TypeError(), () => new Request(input, init), "new Request()");
-  assert_throws(new TypeError(), async () => await fetch(input, init), "fetch()");
+  await promise_rejects(t, new TypeError(), fetch(input, init));
 }
 
-promise_test(async () => {
+promise_test(async (t) => {
   const stream = new ReadableStream();
   stream.getReader();
-  await assert_request("...", { method:"POST", body: stream });
+  await assert_request(t, "...", { method:"POST", body: stream });
 }, "Constructing a Request with a stream on which getReader() is called");
 
-promise_test(async () => {
+promise_test(async (t) => {
   const stream = new ReadableStream();
   stream.getReader().read();
-  await assert_request("...", { method:"POST", body: stream });
+  await assert_request(t, "...", { method:"POST", body: stream });
 }, "Constructing a Request with a stream on which read() is called");
 
-promise_test(async () => {
+promise_test(async (t) => {
   const stream = new ReadableStream({ pull: c => c.enqueue(new Uint8Array()) }),
         reader = stream.getReader();
   await reader.read();
   reader.releaseLock();
-  await assert_request("...", { method:"POST", body: stream });
+  await assert_request(t, "...", { method:"POST", body: stream });
 }, "Constructing a Request with a stream on which read() and releaseLock() are called");
 
-promise_test(async () => {
+promise_test(async (t) => {
   const request = new Request("...", { method: "POST", body: "..." });
   request.body.getReader();
-  await assert_request(request);
+  await assert_request(t, request);
   assert_class_string(new Request(request, { body: "..." }), "Request");
 }, "Constructing a Request with a Request on which body.getReader() is called");
 
-promise_test(async () => {
+promise_test(async (t) => {
   const request = new Request("...", { method: "POST", body: "..." });
   request.body.getReader().read();
-  await assert_request(request);
+  await assert_request(t, request);
   assert_class_string(new Request(request, { body: "..." }), "Request");
 }, "Constructing a Request with a Request on which body.getReader().read() is called");
 
-promise_test(async () => {
+promise_test(async (t) => {
   const request = new Request("...", { method: "POST", body: "..." }),
         reader = request.body.getReader();
   await reader.read();
   reader.releaseLock();
-  await assert_request(request);
+  await assert_request(t, request);
   assert_class_string(new Request(request, { body: "..." }), "Request");
 }, "Constructing a Request with a Request on which read() and releaseLock() are called");

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt (248282 => 248283)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,8 +1,8 @@
 
-FAIL Constructing a Request with a stream on which getReader() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a stream on which read() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a stream on which read() and releaseLock() are called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a Request on which body.getReader() is called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-FAIL Constructing a Request with a Request on which body.getReader().read() is called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-FAIL Constructing a Request with a Request on which read() and releaseLock() are called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
+PASS Constructing a Request with a stream on which getReader() is called 
+PASS Constructing a Request with a stream on which read() is called 
+PASS Constructing a Request with a stream on which read() and releaseLock() are called 
+PASS Constructing a Request with a Request on which body.getReader() is called 
+PASS Constructing a Request with a Request on which body.getReader().read() is called 
+PASS Constructing a Request with a Request on which read() and releaseLock() are called 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt (248282 => 248283)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,5 +1,5 @@
 
-FAIL Constructing a Response with a stream on which getReader() is called assert_throws: function "() => new Response(stream)" did not throw
-FAIL Constructing a Response with a stream on which read() is called assert_throws: function "() => new Response(stream)" did not throw
-FAIL Constructing a Response with a stream on which read() and releaseLock() are called assert_throws: function "() => new Response(stream)" did not throw
+PASS Constructing a Response with a stream on which getReader() is called 
+PASS Constructing a Response with a stream on which read() is called 
+PASS Constructing a Response with a stream on which read() and releaseLock() are called 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt (248282 => 248283)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,5 +1,5 @@
 
-FAIL Constructing a Response with a stream on which getReader() is called assert_throws: function "() => new Response(stream)" did not throw
-FAIL Constructing a Response with a stream on which read() is called assert_throws: function "() => new Response(stream)" did not throw
-FAIL Constructing a Response with a stream on which read() and releaseLock() are called assert_throws: function "() => new Response(stream)" did not throw
+PASS Constructing a Response with a stream on which getReader() is called 
+PASS Constructing a Response with a stream on which read() is called 
+PASS Constructing a Response with a stream on which read() and releaseLock() are called 
 

Deleted: trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt (248282 => 248283)


--- trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,8 +0,0 @@
-
-FAIL Constructing a Request with a stream on which getReader() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a stream on which read() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a stream on which read() and releaseLock() are called assert_throws: new Request() function "() => new Request(input, init)" did not throw
-FAIL Constructing a Request with a Request on which body.getReader() is called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-FAIL Constructing a Request with a Request on which body.getReader().read() is called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-FAIL Constructing a Request with a Request on which read() and releaseLock() are called assert_throws: fetch() function "async () => await fetch(input, init)" did not throw
-

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (248282 => 248283)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2019-08-06 00:36:09 UTC (rev 248283)
@@ -829,10 +829,8 @@
 
 webkit.org/b/181167 imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https.html [ Pass Failure ]
 
-http/wpt/cache-storage/cache-put-stream.https.any.html [ Slow ]
 http/wpt/cache-storage/cache-put-keys.https.any.html [ Slow ]
 http/wpt/cache-storage/a-cache-open.https.html [ Slow ]
-http/wpt/cache-storage/cache-put-stream.https.any.worker.html [ Slow ]
 http/wpt/cache-storage/cache-quota.any.html [ Slow ]
 http/wpt/cache-storage/cache-put-keys.https.any.worker.html [ Slow ]
 http/wpt/cache-storage/cache-remove-twice.html [ Slow ]

Modified: trunk/Source/WebCore/ChangeLog (248282 => 248283)


--- trunk/Source/WebCore/ChangeLog	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/ChangeLog	2019-08-06 00:36:09 UTC (rev 248283)
@@ -1,5 +1,36 @@
 2019-08-05  Youenn Fablet  <[email protected]>
 
+        Response constructor doesn't throw on disturbed ReadableStream
+        https://bugs.webkit.org/show_bug.cgi?id=200130
+        <rdar://problem/53550351>
+
+        Reviewed by Alex Christensen.
+
+        Make FetchBody::extract return an exception in error cases.
+        Update call sites accordingly.
+        Add the error case as per https://fetch.spec.whatwg.org/#concept-bodyinit-extract, ReadableStream handling.
+
+        Covered by updated and rebased tests.
+
+        * Modules/beacon/NavigatorBeacon.cpp:
+        (WebCore::NavigatorBeacon::sendBeacon):
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::extract):
+        * Modules/fetch/FetchBody.h:
+        * Modules/fetch/FetchBodyOwner.cpp:
+        (WebCore::FetchBodyOwner::extractBody):
+        * Modules/fetch/FetchBodyOwner.h:
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::FetchRequest::initializeWith):
+        (WebCore::FetchRequest::setBody):
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::create):
+        * Modules/streams/ReadableStreamInternals.js:
+        (readableStreamPipeTo): fix a case where the promise would be unhandled and would show up in
+        unhandledrejectionhandler.
+
+2019-08-05  Youenn Fablet  <[email protected]>
+
         Support RTCRtpSender.dtmf
         https://bugs.webkit.org/show_bug.cgi?id=200431
 

Modified: trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp (248282 => 248283)


--- trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp	2019-08-06 00:36:09 UTC (rev 248283)
@@ -132,8 +132,10 @@
     if (body) {
         options.mode = FetchOptions::Mode::Cors;
         String mimeType;
-        auto fetchBody = FetchBody::extract(document, WTFMove(body.value()), mimeType);
-
+        auto result = FetchBody::extract(WTFMove(body.value()), mimeType);
+        if (result.hasException())
+            return result.releaseException();
+        auto fetchBody = result.releaseReturnValue();
         if (fetchBody.hasReadableStream())
             return Exception { TypeError, "Beacons cannot send ReadableStream body"_s };
 

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (248282 => 248283)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2019-08-06 00:36:09 UTC (rev 248283)
@@ -40,31 +40,36 @@
 
 namespace WebCore {
 
-FetchBody FetchBody::extract(ScriptExecutionContext&, Init&& value, String& contentType)
+ExceptionOr<FetchBody> FetchBody::extract(Init&& value, String& contentType)
 {
-    return WTF::switchOn(value, [&](RefPtr<Blob>& value) mutable {
+    return WTF::switchOn(value, [&](RefPtr<Blob>& value) mutable -> ExceptionOr<FetchBody> {
         Ref<const Blob> blob = value.releaseNonNull();
         if (!blob->type().isEmpty())
             contentType = blob->type();
         return FetchBody(WTFMove(blob));
-    }, [&](RefPtr<DOMFormData>& value) mutable {
+    }, [&](RefPtr<DOMFormData>& value) mutable -> ExceptionOr<FetchBody> {
         Ref<DOMFormData> domFormData = value.releaseNonNull();
         auto formData = FormData::createMultiPart(domFormData.get());
         contentType = makeString("multipart/form-data; boundary=", formData->boundary().data());
         return FetchBody(WTFMove(formData));
-    }, [&](RefPtr<URLSearchParams>& value) mutable {
+    }, [&](RefPtr<URLSearchParams>& value) mutable -> ExceptionOr<FetchBody> {
         Ref<const URLSearchParams> params = value.releaseNonNull();
         contentType = HTTPHeaderValues::formURLEncodedContentType();
         return FetchBody(WTFMove(params));
-    }, [&](RefPtr<ArrayBuffer>& value) mutable {
+    }, [&](RefPtr<ArrayBuffer>& value) mutable -> ExceptionOr<FetchBody> {
         Ref<const ArrayBuffer> buffer = value.releaseNonNull();
         return FetchBody(WTFMove(buffer));
-    }, [&](RefPtr<ArrayBufferView>& value) mutable {
+    }, [&](RefPtr<ArrayBufferView>& value) mutable -> ExceptionOr<FetchBody> {
         Ref<const ArrayBufferView> buffer = value.releaseNonNull();
         return FetchBody(WTFMove(buffer));
-    }, [&](RefPtr<ReadableStream>& stream) mutable {
+    }, [&](RefPtr<ReadableStream>& stream) mutable -> ExceptionOr<FetchBody> {
+        if (stream->isDisturbed())
+            return Exception { TypeError, "Input body is disturbed."_s };
+        if (stream->isLocked())
+            return Exception { TypeError, "Input body is locked."_s };
+
         return FetchBody(stream.releaseNonNull());
-    }, [&](String& value) {
+    }, [&](String& value) -> ExceptionOr<FetchBody> {
         contentType = HTTPHeaderValues::textPlainContentType();
         return FetchBody(WTFMove(value));
     });

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (248282 => 248283)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.h	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h	2019-08-06 00:36:09 UTC (rev 248283)
@@ -29,6 +29,7 @@
 #pragma once
 
 #include "DOMFormData.h"
+#include "ExceptionOr.h"
 #include "FetchBodyConsumer.h"
 #include "FormData.h"
 #include "JSDOMPromiseDeferred.h"
@@ -55,7 +56,7 @@
 #endif
 
     using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, RefPtr<ReadableStream>, String>;
-    static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
+    static ExceptionOr<FetchBody> extract(Init&&, String&);
     FetchBody() = default;
 
     WEBCORE_EXPORT static Optional<FetchBody> fromFormData(FormData&);

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (248282 => 248283)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2019-08-06 00:36:09 UTC (rev 248283)
@@ -145,9 +145,13 @@
     m_body = owner.m_body->clone();
 }
 
-void FetchBodyOwner::extractBody(ScriptExecutionContext& context, FetchBody::Init&& value)
+ExceptionOr<void> FetchBodyOwner::extractBody(FetchBody::Init&& value)
 {
-    m_body = FetchBody::extract(context, WTFMove(value), m_contentType);
+    auto result = FetchBody::extract(WTFMove(value), m_contentType);
+    if (result.hasException())
+        return result.releaseException();
+    m_body = result.releaseReturnValue();
+    return { };
 }
 
 void FetchBodyOwner::updateContentType()

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (248282 => 248283)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2019-08-06 00:36:09 UTC (rev 248283)
@@ -77,7 +77,7 @@
     bool isBodyNullOrOpaque() const { return !m_body || m_isBodyOpaque; }
     void cloneBody(FetchBodyOwner&);
 
-    void extractBody(ScriptExecutionContext&, FetchBody::Init&&);
+    ExceptionOr<void> extractBody(FetchBody::Init&&);
     void updateContentType();
     void consumeOnceLoadingFinished(FetchBodyConsumer::Type, Ref<DeferredPromise>&&);
 

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (248282 => 248283)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2019-08-06 00:36:09 UTC (rev 248283)
@@ -222,29 +222,14 @@
     } else
         m_signal->follow(input.m_signal.get());
 
-    if (init.headers) {
-        auto fillResult = m_headers->fill(*init.headers);
-        if (fillResult.hasException())
-            return fillResult.releaseException();
-    } else {
-        auto fillResult = m_headers->fill(input.headers());
-        if (fillResult.hasException())
-            return fillResult.releaseException();
-    }
+    auto fillResult = init.headers ? m_headers->fill(*init.headers) : m_headers->fill(input.headers());
+    if (fillResult.hasException())
+        return fillResult;
 
-    if (init.body) {
-        auto setBodyResult = setBody(WTFMove(*init.body));
-        if (setBodyResult.hasException())
-            return setBodyResult.releaseException();
-    } else {
-        if (input.isDisturbedOrLocked())
-            return Exception { TypeError, "Request input is disturbed or locked."_s };
+    auto setBodyResult = init.body ? setBody(WTFMove(*init.body)) : setBody(input);
+    if (setBodyResult.hasException())
+        return setBodyResult;
 
-        auto setBodyResult = setBody(input);
-        if (setBodyResult.hasException())
-            return setBodyResult.releaseException();
-    }
-
     updateContentType();
     return { };
 }
@@ -255,7 +240,9 @@
         return Exception { TypeError, makeString("Request has method '", m_request.httpMethod(), "' and cannot have a body") };
 
     ASSERT(scriptExecutionContext());
-    extractBody(*scriptExecutionContext(), WTFMove(body));
+    auto result = extractBody(WTFMove(body));
+    if (result.hasException())
+        return result;
 
     if (m_options.keepAlive && hasReadableStreamBody())
         return Exception { TypeError, "Request cannot have a ReadableStream body and keepalive set to true"_s };
@@ -264,6 +251,9 @@
 
 ExceptionOr<void> FetchRequest::setBody(FetchRequest& request)
 {
+    if (request.isDisturbedOrLocked())
+        return Exception { TypeError, "Request input is disturbed or locked."_s };
+
     if (!request.isBodyNull()) {
         if (!methodCanHaveBody(m_request))
             return Exception { TypeError, makeString("Request has method '", m_request.httpMethod(), "' and cannot have a body") };

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (248282 => 248283)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2019-08-06 00:36:09 UTC (rev 248283)
@@ -103,7 +103,10 @@
         String contentType;
 
         // 8.3 Set r’s response’s body and Content-Type to the result of extracting body.
-        extractedBody = FetchBody::extract(context, WTFMove(*body), contentType);
+        auto result = FetchBody::extract(WTFMove(*body), contentType);
+        if (result.hasException())
+            return result.releaseException();
+        extractedBody = result.releaseReturnValue();
 
         // 8.4 If Content-Type is non-null and r’s response’s header list does not contain `Content-Type`, then append
         //     `Content-Type`/Content-Type to r’s response’s header list.

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (248282 => 248283)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2019-08-06 00:34:14 UTC (rev 248282)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2019-08-06 00:36:09 UTC (rev 248283)
@@ -113,6 +113,8 @@
                 return;
             }
             doPipe();
+        }, function(e) {
+            sink.error(e);
         });
     }
     doPipe();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to