Skip to content

Commit

Permalink
Implement Request & Response's bytes() method
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274102

Reviewed by Youenn Fablet.

This accessor is nearly identical to arrayBuffer() except that it
yields a Uint8Array, which is strictly more useful.

Fetch change: whatwg/fetch#1753.

* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.serviceworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/serviceworker-intercepted.https-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.any.serviceworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-blob-realm.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-from-stream.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-from-stream.any.serviceworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-from-stream.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-error-from-stream.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-bad-chunk.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-bad-chunk.any.serviceworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-bad-chunk.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-bad-chunk.any.worker-expected.txt:
* Source/WebCore/Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::bytes):
* Source/WebCore/Modules/fetch/FetchBody.h:
* Source/WebCore/Modules/fetch/FetchBody.idl:
* Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::resolveWithTypeAndData):
(WebCore::FetchBodyConsumer::resolve):
* Source/WebCore/Modules/fetch/FetchBodyConsumer.h:
* Source/WebCore/Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::bytes):
* Source/WebCore/Modules/fetch/FetchBodyOwner.h:
* Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp:
(WebCore::fulfillPromiseWithUint8Array):
(WebCore::fulfillPromiseWithUint8ArrayFromSpan):
* Source/WebCore/bindings/js/JSDOMPromiseDeferred.h:

Canonical link: https://commits.webkit.org/279036@main
  • Loading branch information
annevk committed May 21, 2024
1 parent 9dce2ad commit a534f04
Show file tree
Hide file tree
Showing 27 changed files with 115 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PASS Already aborted signal rejects immediately
PASS Request is still 'used' if signal is aborted before fetching
PASS response.arrayBuffer() rejects if already aborted
PASS response.blob() rejects if already aborted
FAIL response.bytes() rejects if already aborted promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS response.bytes() rejects if already aborted
PASS response.formData() rejects if already aborted
PASS response.json() rejects if already aborted
PASS response.text() rejects if already aborted
Expand All @@ -42,7 +42,7 @@ PASS Underlying connection is closed when aborting after receiving response
PASS Underlying connection is closed when aborting after receiving response - no-cors
PASS Fetch aborted & connection closed when aborted after calling response.arrayBuffer()
PASS Fetch aborted & connection closed when aborted after calling response.blob()
FAIL Fetch aborted & connection closed when aborted after calling response.bytes() promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS Fetch aborted & connection closed when aborted after calling response.bytes()
PASS Fetch aborted & connection closed when aborted after calling response.formData()
PASS Fetch aborted & connection closed when aborted after calling response.json()
PASS Fetch aborted & connection closed when aborted after calling response.text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PASS Already aborted signal rejects immediately
PASS Request is still 'used' if signal is aborted before fetching
PASS response.arrayBuffer() rejects if already aborted
PASS response.blob() rejects if already aborted
FAIL response.bytes() rejects if already aborted promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS response.bytes() rejects if already aborted
PASS response.formData() rejects if already aborted
PASS response.json() rejects if already aborted
PASS response.text() rejects if already aborted
Expand All @@ -42,7 +42,7 @@ PASS Underlying connection is closed when aborting after receiving response
PASS Underlying connection is closed when aborting after receiving response - no-cors
PASS Fetch aborted & connection closed when aborted after calling response.arrayBuffer()
PASS Fetch aborted & connection closed when aborted after calling response.blob()
FAIL Fetch aborted & connection closed when aborted after calling response.bytes() promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS Fetch aborted & connection closed when aborted after calling response.bytes()
PASS Fetch aborted & connection closed when aborted after calling response.formData()
PASS Fetch aborted & connection closed when aborted after calling response.json()
PASS Fetch aborted & connection closed when aborted after calling response.text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PASS Already aborted signal rejects immediately
PASS Request is still 'used' if signal is aborted before fetching
PASS response.arrayBuffer() rejects if already aborted
PASS response.blob() rejects if already aborted
FAIL response.bytes() rejects if already aborted promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS response.bytes() rejects if already aborted
PASS response.formData() rejects if already aborted
PASS response.json() rejects if already aborted
PASS response.text() rejects if already aborted
Expand All @@ -42,7 +42,7 @@ PASS Underlying connection is closed when aborting after receiving response
PASS Underlying connection is closed when aborting after receiving response - no-cors
PASS Fetch aborted & connection closed when aborted after calling response.arrayBuffer()
PASS Fetch aborted & connection closed when aborted after calling response.blob()
FAIL Fetch aborted & connection closed when aborted after calling response.bytes() promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS Fetch aborted & connection closed when aborted after calling response.bytes()
PASS Fetch aborted & connection closed when aborted after calling response.formData()
PASS Fetch aborted & connection closed when aborted after calling response.json()
PASS Fetch aborted & connection closed when aborted after calling response.text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PASS Already aborted signal rejects immediately
PASS Request is still 'used' if signal is aborted before fetching
PASS response.arrayBuffer() rejects if already aborted
PASS response.blob() rejects if already aborted
FAIL response.bytes() rejects if already aborted promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS response.bytes() rejects if already aborted
PASS response.formData() rejects if already aborted
PASS response.json() rejects if already aborted
PASS response.text() rejects if already aborted
Expand All @@ -42,7 +42,7 @@ PASS Underlying connection is closed when aborting after receiving response
PASS Underlying connection is closed when aborting after receiving response - no-cors
PASS Fetch aborted & connection closed when aborted after calling response.arrayBuffer()
PASS Fetch aborted & connection closed when aborted after calling response.blob()
FAIL Fetch aborted & connection closed when aborted after calling response.bytes() promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS Fetch aborted & connection closed when aborted after calling response.bytes()
PASS Fetch aborted & connection closed when aborted after calling response.formData()
PASS Fetch aborted & connection closed when aborted after calling response.json()
PASS Fetch aborted & connection closed when aborted after calling response.text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Harness Error (TIMEOUT), message = null
PASS Already aborted request does not land in service worker
PASS response.arrayBuffer() rejects if already aborted
PASS response.blob() rejects if already aborted
FAIL response.bytes() rejects if already aborted promise_test: Unhandled rejection with value: object "TypeError: response[bodyMethod] is not a function. (In 'response[bodyMethod]()', 'response[bodyMethod]' is undefined)"
PASS response.bytes() rejects if already aborted
PASS response.formData() rejects if already aborted
PASS response.json() rejects if already aborted
PASS response.text() rejects if already aborted
PASS Stream errors once aborted.
FAIL fetch() rejects with abort reason promise_rejects_exactly: function "function() { throw e }" threw object "AbortError: Fetch is aborted" but we expected it to throw object "error1: error1"
FAIL fetch() response body has abort reason assert_unreached: Should have rejected: undefined Reached unreachable code
FAIL fetch() response body has abort reason promise_rejects_exactly: function "function() { throw e }" threw object "AbortError: Fetch is aborted" but we expected it to throw object "error1: error1"
TIMEOUT Service Worker can observe the fetch abort and associated abort reason Test timed out
NOTRUN Abort reason serialization happens on abort

Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
PASS Consume String request's body as text
PASS Consume String request's body as blob
PASS Consume String request's body as arrayBuffer
FAIL Consume String request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume String request's body as bytes
PASS Consume String request's body as JSON
PASS Consume ArrayBuffer request's body as text
PASS Consume ArrayBuffer request's body as blob
PASS Consume ArrayBuffer request's body as arrayBuffer
FAIL Consume ArrayBuffer request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume ArrayBuffer request's body as bytes
PASS Consume ArrayBuffer request's body as JSON
PASS Consume Uint8Array request's body as text
PASS Consume Uint8Array request's body as blob
PASS Consume Uint8Array request's body as arrayBuffer
FAIL Consume Uint8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Uint8Array request's body as bytes
PASS Consume Uint8Array request's body as JSON
PASS Consume Int8Array request's body as text
PASS Consume Int8Array request's body as blob
PASS Consume Int8Array request's body as arrayBuffer
FAIL Consume Int8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Int8Array request's body as bytes
PASS Consume Int8Array request's body as JSON
PASS Consume Float32Array request's body as text
PASS Consume Float32Array request's body as blob
PASS Consume Float32Array request's body as arrayBuffer
FAIL Consume Float32Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Float32Array request's body as bytes
PASS Consume Float32Array request's body as JSON
PASS Consume DataView request's body as text
PASS Consume DataView request's body as blob
PASS Consume DataView request's body as arrayBuffer
FAIL Consume DataView request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume DataView request's body as bytes
PASS Consume DataView request's body as JSON
PASS Consume FormData request's body as FormData
PASS Consume blob response's body as blob
PASS Consume blob response's body as text
PASS Consume blob response's body as json
PASS Consume blob response's body as arrayBuffer
FAIL Consume blob response's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume blob response's body as bytes
PASS Consume blob response's body as blob (empty blob as input)
PASS Consume JSON from text: '"null"'
PASS Consume JSON from text: '"1"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
PASS Consume String request's body as text
PASS Consume String request's body as blob
PASS Consume String request's body as arrayBuffer
FAIL Consume String request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume String request's body as bytes
PASS Consume String request's body as JSON
PASS Consume ArrayBuffer request's body as text
PASS Consume ArrayBuffer request's body as blob
PASS Consume ArrayBuffer request's body as arrayBuffer
FAIL Consume ArrayBuffer request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume ArrayBuffer request's body as bytes
PASS Consume ArrayBuffer request's body as JSON
PASS Consume Uint8Array request's body as text
PASS Consume Uint8Array request's body as blob
PASS Consume Uint8Array request's body as arrayBuffer
FAIL Consume Uint8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Uint8Array request's body as bytes
PASS Consume Uint8Array request's body as JSON
PASS Consume Int8Array request's body as text
PASS Consume Int8Array request's body as blob
PASS Consume Int8Array request's body as arrayBuffer
FAIL Consume Int8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Int8Array request's body as bytes
PASS Consume Int8Array request's body as JSON
PASS Consume Float32Array request's body as text
PASS Consume Float32Array request's body as blob
PASS Consume Float32Array request's body as arrayBuffer
FAIL Consume Float32Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Float32Array request's body as bytes
PASS Consume Float32Array request's body as JSON
PASS Consume DataView request's body as text
PASS Consume DataView request's body as blob
PASS Consume DataView request's body as arrayBuffer
FAIL Consume DataView request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume DataView request's body as bytes
PASS Consume DataView request's body as JSON
PASS Consume FormData request's body as FormData
PASS Consume blob response's body as blob
PASS Consume blob response's body as text
PASS Consume blob response's body as json
PASS Consume blob response's body as arrayBuffer
FAIL Consume blob response's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume blob response's body as bytes
PASS Consume blob response's body as blob (empty blob as input)
PASS Consume JSON from text: '"null"'
PASS Consume JSON from text: '"1"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
PASS Consume String request's body as text
PASS Consume String request's body as blob
PASS Consume String request's body as arrayBuffer
FAIL Consume String request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume String request's body as bytes
PASS Consume String request's body as JSON
PASS Consume ArrayBuffer request's body as text
PASS Consume ArrayBuffer request's body as blob
PASS Consume ArrayBuffer request's body as arrayBuffer
FAIL Consume ArrayBuffer request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume ArrayBuffer request's body as bytes
PASS Consume ArrayBuffer request's body as JSON
PASS Consume Uint8Array request's body as text
PASS Consume Uint8Array request's body as blob
PASS Consume Uint8Array request's body as arrayBuffer
FAIL Consume Uint8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Uint8Array request's body as bytes
PASS Consume Uint8Array request's body as JSON
PASS Consume Int8Array request's body as text
PASS Consume Int8Array request's body as blob
PASS Consume Int8Array request's body as arrayBuffer
FAIL Consume Int8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Int8Array request's body as bytes
PASS Consume Int8Array request's body as JSON
PASS Consume Float32Array request's body as text
PASS Consume Float32Array request's body as blob
PASS Consume Float32Array request's body as arrayBuffer
FAIL Consume Float32Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Float32Array request's body as bytes
PASS Consume Float32Array request's body as JSON
PASS Consume DataView request's body as text
PASS Consume DataView request's body as blob
PASS Consume DataView request's body as arrayBuffer
FAIL Consume DataView request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume DataView request's body as bytes
PASS Consume DataView request's body as JSON
PASS Consume FormData request's body as FormData
PASS Consume blob response's body as blob
PASS Consume blob response's body as text
PASS Consume blob response's body as json
PASS Consume blob response's body as arrayBuffer
FAIL Consume blob response's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume blob response's body as bytes
PASS Consume blob response's body as blob (empty blob as input)
PASS Consume JSON from text: '"null"'
PASS Consume JSON from text: '"1"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
PASS Consume String request's body as text
PASS Consume String request's body as blob
PASS Consume String request's body as arrayBuffer
FAIL Consume String request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume String request's body as bytes
PASS Consume String request's body as JSON
PASS Consume ArrayBuffer request's body as text
PASS Consume ArrayBuffer request's body as blob
PASS Consume ArrayBuffer request's body as arrayBuffer
FAIL Consume ArrayBuffer request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume ArrayBuffer request's body as bytes
PASS Consume ArrayBuffer request's body as JSON
PASS Consume Uint8Array request's body as text
PASS Consume Uint8Array request's body as blob
PASS Consume Uint8Array request's body as arrayBuffer
FAIL Consume Uint8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Uint8Array request's body as bytes
PASS Consume Uint8Array request's body as JSON
PASS Consume Int8Array request's body as text
PASS Consume Int8Array request's body as blob
PASS Consume Int8Array request's body as arrayBuffer
FAIL Consume Int8Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Int8Array request's body as bytes
PASS Consume Int8Array request's body as JSON
PASS Consume Float32Array request's body as text
PASS Consume Float32Array request's body as blob
PASS Consume Float32Array request's body as arrayBuffer
FAIL Consume Float32Array request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume Float32Array request's body as bytes
PASS Consume Float32Array request's body as JSON
PASS Consume DataView request's body as text
PASS Consume DataView request's body as blob
PASS Consume DataView request's body as arrayBuffer
FAIL Consume DataView request's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume DataView request's body as bytes
PASS Consume DataView request's body as JSON
PASS Consume FormData request's body as FormData
PASS Consume blob response's body as blob
PASS Consume blob response's body as text
PASS Consume blob response's body as json
PASS Consume blob response's body as arrayBuffer
FAIL Consume blob response's body as bytes request.bytes is not a function. (In 'request.bytes()', 'request.bytes' is undefined)
PASS Consume blob response's body as bytes
PASS Consume blob response's body as blob (empty blob as input)
PASS Consume JSON from text: '"null"'
PASS Consume JSON from text: '"1"'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL realm of the Uint8Array from Response bytes() promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'window.Response.prototype.bytes.call')"
FAIL realm of the Uint8Array from Response bytes() assert_true: Uint8Array should be created in receiver's realm expected true got false

Loading

0 comments on commit a534f04

Please sign in to comment.