Changeset 248283 in webkit


Ignore:
Timestamp:
Aug 5, 2019 5:36:09 PM (5 years ago)
Author:
youenn@apple.com
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:
Location:
trunk
Files:
4 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r248279 r248283  
     12019-08-05  Youenn Fablet  <youenn@apple.com>
     2
     3        Support RTCRtpSender.dtmf
     4        https://bugs.webkit.org/show_bug.cgi?id=200431
     5        <rdar://problem/53924833>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Removed cache storage test which is no longer valid.
     10        Removed WK1 expectation that is no longer needed.
     11
     12        * http/wpt/cache-storage/cache-put-stream.https.any.html: Removed.
     13        * http/wpt/cache-storage/cache-put-stream.https.any.js: Removed.
     14        * http/wpt/cache-storage/cache-put-stream.https.any.worker.html: Removed.
     15        * platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt: Removed.
     16        * platform/mac-wk2/TestExpectations:
     17
    1182019-08-05  Devin Rousso  <drousso@apple.com>
    219
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r248282 r248283  
     12019-08-05  Youenn Fablet  <youenn@apple.com>
     2
     3        Response constructor doesn't throw on disturbed ReadableStream
     4        https://bugs.webkit.org/show_bug.cgi?id=200130
     5        <rdar://problem/53550351>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Update test to use promise_rejects instead of assert_throws.
     10
     11        * web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt:
     12        * web-platform-tests/fetch/api/request/request-init-stream.any.js:
     13        (async.assert_request):
     14        (promise_test.async):
     15        * web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt:
     16        * web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt:
     17        * web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt:
     18
    1192019-08-05  Youenn Fablet  <youenn@apple.com>
    220
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any-expected.txt

    r239693 r248283  
    11
    2 FAIL Constructing a Request with a stream on which getReader() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
    3 FAIL Constructing a Request with a stream on which read() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
    4 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
    5 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
    6 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
    7 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
     2PASS Constructing a Request with a stream on which getReader() is called
     3PASS Constructing a Request with a stream on which read() is called
     4PASS Constructing a Request with a stream on which read() and releaseLock() are called
     5PASS Constructing a Request with a Request on which body.getReader() is called
     6PASS Constructing a Request with a Request on which body.getReader().read() is called
     7PASS Constructing a Request with a Request on which read() and releaseLock() are called
    88
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.js

    r239693 r248283  
    33"use strict";
    44
    5 async function assert_request(input, init) {
     5async function assert_request(t, input, init) {
    66  assert_throws(new TypeError(), () => new Request(input, init), "new Request()");
    7   assert_throws(new TypeError(), async () => await fetch(input, init), "fetch()");
     7  await promise_rejects(t, new TypeError(), fetch(input, init));
    88}
    99
    10 promise_test(async () => {
     10promise_test(async (t) => {
    1111  const stream = new ReadableStream();
    1212  stream.getReader();
    13   await assert_request("...", { method:"POST", body: stream });
     13  await assert_request(t, "...", { method:"POST", body: stream });
    1414}, "Constructing a Request with a stream on which getReader() is called");
    1515
    16 promise_test(async () => {
     16promise_test(async (t) => {
    1717  const stream = new ReadableStream();
    1818  stream.getReader().read();
    19   await assert_request("...", { method:"POST", body: stream });
     19  await assert_request(t, "...", { method:"POST", body: stream });
    2020}, "Constructing a Request with a stream on which read() is called");
    2121
    22 promise_test(async () => {
     22promise_test(async (t) => {
    2323  const stream = new ReadableStream({ pull: c => c.enqueue(new Uint8Array()) }),
    2424        reader = stream.getReader();
    2525  await reader.read();
    2626  reader.releaseLock();
    27   await assert_request("...", { method:"POST", body: stream });
     27  await assert_request(t, "...", { method:"POST", body: stream });
    2828}, "Constructing a Request with a stream on which read() and releaseLock() are called");
    2929
    30 promise_test(async () => {
     30promise_test(async (t) => {
    3131  const request = new Request("...", { method: "POST", body: "..." });
    3232  request.body.getReader();
    33   await assert_request(request);
     33  await assert_request(t, request);
    3434  assert_class_string(new Request(request, { body: "..." }), "Request");
    3535}, "Constructing a Request with a Request on which body.getReader() is called");
    3636
    37 promise_test(async () => {
     37promise_test(async (t) => {
    3838  const request = new Request("...", { method: "POST", body: "..." });
    3939  request.body.getReader().read();
    40   await assert_request(request);
     40  await assert_request(t, request);
    4141  assert_class_string(new Request(request, { body: "..." }), "Request");
    4242}, "Constructing a Request with a Request on which body.getReader().read() is called");
    4343
    44 promise_test(async () => {
     44promise_test(async (t) => {
    4545  const request = new Request("...", { method: "POST", body: "..." }),
    4646        reader = request.body.getReader();
    4747  await reader.read();
    4848  reader.releaseLock();
    49   await assert_request(request);
     49  await assert_request(t, request);
    5050  assert_class_string(new Request(request, { body: "..." }), "Request");
    5151}, "Constructing a Request with a Request on which read() and releaseLock() are called");
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-stream.any.worker-expected.txt

    r239693 r248283  
    11
    2 FAIL Constructing a Request with a stream on which getReader() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
    3 FAIL Constructing a Request with a stream on which read() is called assert_throws: new Request() function "() => new Request(input, init)" did not throw
    4 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
    5 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
    6 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
    7 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
     2PASS Constructing a Request with a stream on which getReader() is called
     3PASS Constructing a Request with a stream on which read() is called
     4PASS Constructing a Request with a stream on which read() and releaseLock() are called
     5PASS Constructing a Request with a Request on which body.getReader() is called
     6PASS Constructing a Request with a Request on which body.getReader().read() is called
     7PASS Constructing a Request with a Request on which read() and releaseLock() are called
    88
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any-expected.txt

    r239693 r248283  
    11
    2 FAIL Constructing a Response with a stream on which getReader() is called assert_throws: function "() => new Response(stream)" did not throw
    3 FAIL Constructing a Response with a stream on which read() is called assert_throws: function "() => new Response(stream)" did not throw
    4 FAIL Constructing a Response with a stream on which read() and releaseLock() are called assert_throws: function "() => new Response(stream)" did not throw
     2PASS Constructing a Response with a stream on which getReader() is called
     3PASS Constructing a Response with a stream on which read() is called
     4PASS Constructing a Response with a stream on which read() and releaseLock() are called
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-from-stream.any.worker-expected.txt

    r239693 r248283  
    11
    2 FAIL Constructing a Response with a stream on which getReader() is called assert_throws: function "() => new Response(stream)" did not throw
    3 FAIL Constructing a Response with a stream on which read() is called assert_throws: function "() => new Response(stream)" did not throw
    4 FAIL Constructing a Response with a stream on which read() and releaseLock() are called assert_throws: function "() => new Response(stream)" did not throw
     2PASS Constructing a Response with a stream on which getReader() is called
     3PASS Constructing a Response with a stream on which read() is called
     4PASS Constructing a Response with a stream on which read() and releaseLock() are called
    55
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r248273 r248283  
    830830webkit.org/b/181167 imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https.html [ Pass Failure ]
    831831
    832 http/wpt/cache-storage/cache-put-stream.https.any.html [ Slow ]
    833832http/wpt/cache-storage/cache-put-keys.https.any.html [ Slow ]
    834833http/wpt/cache-storage/a-cache-open.https.html [ Slow ]
    835 http/wpt/cache-storage/cache-put-stream.https.any.worker.html [ Slow ]
    836834http/wpt/cache-storage/cache-quota.any.html [ Slow ]
    837835http/wpt/cache-storage/cache-put-keys.https.any.worker.html [ Slow ]
  • trunk/Source/WebCore/ChangeLog

    r248282 r248283  
     12019-08-05  Youenn Fablet  <youenn@apple.com>
     2
     3        Response constructor doesn't throw on disturbed ReadableStream
     4        https://bugs.webkit.org/show_bug.cgi?id=200130
     5        <rdar://problem/53550351>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Make FetchBody::extract return an exception in error cases.
     10        Update call sites accordingly.
     11        Add the error case as per https://fetch.spec.whatwg.org/#concept-bodyinit-extract, ReadableStream handling.
     12
     13        Covered by updated and rebased tests.
     14
     15        * Modules/beacon/NavigatorBeacon.cpp:
     16        (WebCore::NavigatorBeacon::sendBeacon):
     17        * Modules/fetch/FetchBody.cpp:
     18        (WebCore::FetchBody::extract):
     19        * Modules/fetch/FetchBody.h:
     20        * Modules/fetch/FetchBodyOwner.cpp:
     21        (WebCore::FetchBodyOwner::extractBody):
     22        * Modules/fetch/FetchBodyOwner.h:
     23        * Modules/fetch/FetchRequest.cpp:
     24        (WebCore::FetchRequest::initializeWith):
     25        (WebCore::FetchRequest::setBody):
     26        * Modules/fetch/FetchResponse.cpp:
     27        (WebCore::FetchResponse::create):
     28        * Modules/streams/ReadableStreamInternals.js:
     29        (readableStreamPipeTo): fix a case where the promise would be unhandled and would show up in
     30        unhandledrejectionhandler.
     31
    1322019-08-05  Youenn Fablet  <youenn@apple.com>
    233
  • trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp

    r245344 r248283  
    133133        options.mode = FetchOptions::Mode::Cors;
    134134        String mimeType;
    135         auto fetchBody = FetchBody::extract(document, WTFMove(body.value()), mimeType);
    136 
     135        auto result = FetchBody::extract(WTFMove(body.value()), mimeType);
     136        if (result.hasException())
     137            return result.releaseException();
     138        auto fetchBody = result.releaseReturnValue();
    137139        if (fetchBody.hasReadableStream())
    138140            return Exception { TypeError, "Beacons cannot send ReadableStream body"_s };
  • trunk/Source/WebCore/Modules/fetch/FetchBody.cpp

    r248139 r248283  
    4141namespace WebCore {
    4242
    43 FetchBody FetchBody::extract(ScriptExecutionContext&, Init&& value, String& contentType)
    44 {
    45     return WTF::switchOn(value, [&](RefPtr<Blob>& value) mutable {
     43ExceptionOr<FetchBody> FetchBody::extract(Init&& value, String& contentType)
     44{
     45    return WTF::switchOn(value, [&](RefPtr<Blob>& value) mutable -> ExceptionOr<FetchBody> {
    4646        Ref<const Blob> blob = value.releaseNonNull();
    4747        if (!blob->type().isEmpty())
    4848            contentType = blob->type();
    4949        return FetchBody(WTFMove(blob));
    50     }, [&](RefPtr<DOMFormData>& value) mutable {
     50    }, [&](RefPtr<DOMFormData>& value) mutable -> ExceptionOr<FetchBody> {
    5151        Ref<DOMFormData> domFormData = value.releaseNonNull();
    5252        auto formData = FormData::createMultiPart(domFormData.get());
    5353        contentType = makeString("multipart/form-data; boundary=", formData->boundary().data());
    5454        return FetchBody(WTFMove(formData));
    55     }, [&](RefPtr<URLSearchParams>& value) mutable {
     55    }, [&](RefPtr<URLSearchParams>& value) mutable -> ExceptionOr<FetchBody> {
    5656        Ref<const URLSearchParams> params = value.releaseNonNull();
    5757        contentType = HTTPHeaderValues::formURLEncodedContentType();
    5858        return FetchBody(WTFMove(params));
    59     }, [&](RefPtr<ArrayBuffer>& value) mutable {
     59    }, [&](RefPtr<ArrayBuffer>& value) mutable -> ExceptionOr<FetchBody> {
    6060        Ref<const ArrayBuffer> buffer = value.releaseNonNull();
    6161        return FetchBody(WTFMove(buffer));
    62     }, [&](RefPtr<ArrayBufferView>& value) mutable {
     62    }, [&](RefPtr<ArrayBufferView>& value) mutable -> ExceptionOr<FetchBody> {
    6363        Ref<const ArrayBufferView> buffer = value.releaseNonNull();
    6464        return FetchBody(WTFMove(buffer));
    65     }, [&](RefPtr<ReadableStream>& stream) mutable {
     65    }, [&](RefPtr<ReadableStream>& stream) mutable -> ExceptionOr<FetchBody> {
     66        if (stream->isDisturbed())
     67            return Exception { TypeError, "Input body is disturbed."_s };
     68        if (stream->isLocked())
     69            return Exception { TypeError, "Input body is locked."_s };
     70
    6671        return FetchBody(stream.releaseNonNull());
    67     }, [&](String& value) {
     72    }, [&](String& value) -> ExceptionOr<FetchBody> {
    6873        contentType = HTTPHeaderValues::textPlainContentType();
    6974        return FetchBody(WTFMove(value));
  • trunk/Source/WebCore/Modules/fetch/FetchBody.h

    r239644 r248283  
    3030
    3131#include "DOMFormData.h"
     32#include "ExceptionOr.h"
    3233#include "FetchBodyConsumer.h"
    3334#include "FormData.h"
     
    5657
    5758    using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, RefPtr<ReadableStream>, String>;
    58     static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
     59    static ExceptionOr<FetchBody> extract(Init&&, String&);
    5960    FetchBody() = default;
    6061
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp

    r240237 r248283  
    146146}
    147147
    148 void FetchBodyOwner::extractBody(ScriptExecutionContext& context, FetchBody::Init&& value)
    149 {
    150     m_body = FetchBody::extract(context, WTFMove(value), m_contentType);
     148ExceptionOr<void> FetchBodyOwner::extractBody(FetchBody::Init&& value)
     149{
     150    auto result = FetchBody::extract(WTFMove(value), m_contentType);
     151    if (result.hasException())
     152        return result.releaseException();
     153    m_body = result.releaseReturnValue();
     154    return { };
    151155}
    152156
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h

    r239644 r248283  
    7878    void cloneBody(FetchBodyOwner&);
    7979
    80     void extractBody(ScriptExecutionContext&, FetchBody::Init&&);
     80    ExceptionOr<void> extractBody(FetchBody::Init&&);
    8181    void updateContentType();
    8282    void consumeOnceLoadingFinished(FetchBodyConsumer::Type, Ref<DeferredPromise>&&);
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r247213 r248283  
    223223        m_signal->follow(input.m_signal.get());
    224224
    225     if (init.headers) {
    226         auto fillResult = m_headers->fill(*init.headers);
    227         if (fillResult.hasException())
    228             return fillResult.releaseException();
    229     } else {
    230         auto fillResult = m_headers->fill(input.headers());
    231         if (fillResult.hasException())
    232             return fillResult.releaseException();
    233     }
    234 
    235     if (init.body) {
    236         auto setBodyResult = setBody(WTFMove(*init.body));
    237         if (setBodyResult.hasException())
    238             return setBodyResult.releaseException();
    239     } else {
    240         if (input.isDisturbedOrLocked())
    241             return Exception { TypeError, "Request input is disturbed or locked."_s };
    242 
    243         auto setBodyResult = setBody(input);
    244         if (setBodyResult.hasException())
    245             return setBodyResult.releaseException();
    246     }
     225    auto fillResult = init.headers ? m_headers->fill(*init.headers) : m_headers->fill(input.headers());
     226    if (fillResult.hasException())
     227        return fillResult;
     228
     229    auto setBodyResult = init.body ? setBody(WTFMove(*init.body)) : setBody(input);
     230    if (setBodyResult.hasException())
     231        return setBodyResult;
    247232
    248233    updateContentType();
     
    256241
    257242    ASSERT(scriptExecutionContext());
    258     extractBody(*scriptExecutionContext(), WTFMove(body));
     243    auto result = extractBody(WTFMove(body));
     244    if (result.hasException())
     245        return result;
    259246
    260247    if (m_options.keepAlive && hasReadableStreamBody())
     
    265252ExceptionOr<void> FetchRequest::setBody(FetchRequest& request)
    266253{
     254    if (request.isDisturbedOrLocked())
     255        return Exception { TypeError, "Request input is disturbed or locked."_s };
     256
    267257    if (!request.isBodyNull()) {
    268258        if (!methodCanHaveBody(m_request))
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r247087 r248283  
    104104
    105105        // 8.3 Set r’s response’s body and Content-Type to the result of extracting body.
    106         extractedBody = FetchBody::extract(context, WTFMove(*body), contentType);
     106        auto result = FetchBody::extract(WTFMove(*body), contentType);
     107        if (result.hasException())
     108            return result.releaseException();
     109        extractedBody = result.releaseReturnValue();
    107110
    108111        // 8.4 If Content-Type is non-null and r’s response’s header list does not contain `Content-Type`, then append
  • trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js

    r242365 r248283  
    114114            }
    115115            doPipe();
     116        }, function(e) {
     117            sink.error(e);
    116118        });
    117119    }
Note: See TracChangeset for help on using the changeset viewer.