Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bytes() method to Blob for reading bytes into a Uint8Array #198

Merged
merged 1 commit into from
May 24, 2024

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented May 21, 2024

Closes #197

The Fetch API is getting a Uint8Array-returning bytes() method alongside its existing arrayBuffer() method, following the principle that APIs should generally vend byte buffers as Uint8Arrays.

This PR makes the same change for Blob, which has its own distinct arrayBuffer method.

I'm assuming this is uncontroversial given the support from the three major implementations for doing this on Body, but I can open an issue and solicit explicit support separately if you'd prefer. I'll write tests if I get a signal that this is able to go forward. Tests written, see link.

Implementation commitment:


Preview | Diff

@marcoscaceres marcoscaceres changed the title Add bytes() method for reading bytes into a Uint8Array Add bytes() method to Blob for reading bytes into a Uint8Array May 21, 2024
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request May 24, 2024
https://bugs.webkit.org/show_bug.cgi?id=274119
rdar://128418858

Reviewed by Youenn Fablet.

This implements w3c/FileAPI#198 and
w3c/push-api#370 creating parity for these
APIs with Fetch's Body.

This incorporates the tests from
web-platform-tests/wpt#46232 modulo a typo fix.
PushMessageData test coverage is done through a local test that would
be good to upstream at some point.

* LayoutTests/http/wpt/push-api/pushEvent.any.js:
(test):
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/Blob-methods-from-detached-frame-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/Blob-methods-from-detached-frame.html:
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-bytes.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-bytes.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-bytes.any.js: Added.
(string_appeared_here.promise_test.async const):
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-bytes.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-bytes.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/w3c-import.log:
* Source/WebCore/Modules/push-api/PushMessageData.cpp:
(WebCore::PushMessageData::arrayBuffer):
(WebCore::PushMessageData::bytes):
* Source/WebCore/Modules/push-api/PushMessageData.h:
* Source/WebCore/Modules/push-api/PushMessageData.idl:
* Source/WebCore/fileapi/Blob.cpp:
(WebCore::Blob::arrayBuffer):
(WebCore::Blob::bytes):
* Source/WebCore/fileapi/Blob.h:
* Source/WebCore/fileapi/Blob.idl:

Canonical link: https://commits.webkit.org/279263@main
@saschanaz
Copy link
Member

This is off topic, should we split implementation commitment to implementor interest and implementation bugs? The single list wasn't fully clear in some cases (some people thought it's enough to have bugs filed).

@annevk
Copy link
Member

annevk commented May 24, 2024

Makes sense. The WHATWG template is quite a bit clearer.

@mkruisselbrink mkruisselbrink merged commit 85b18bc into main May 24, 2024
2 checks passed
github-actions bot added a commit that referenced this pull request May 24, 2024
SHA: 85b18bc
Reason: push, by mkruisselbrink

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@annevk annevk deleted the bytes branch May 24, 2024 17:07
@saschanaz
Copy link
Member

saschanaz commented May 24, 2024

Well I do support this, but you still need to ask people?

(edit: Oh there was Tom. web-platform-tests/wpt#46232 (comment))

annevk pushed a commit to web-platform-tests/wpt that referenced this pull request May 24, 2024
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 3, 2024
…testonly

Automatic update from web-platform-tests
Add tests for Blob.prototype.bytes()

For w3c/FileAPI#198.
--

wpt-commits: cceaf3628da950621004d9b5d8c1d1f367073347
wpt-pr: 46232
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this pull request Jun 5, 2024
…testonly

Automatic update from web-platform-tests
Add tests for Blob.prototype.bytes()

For w3c/FileAPI#198.
--

wpt-commits: cceaf3628da950621004d9b5d8c1d1f367073347
wpt-pr: 46232
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this pull request Jun 14, 2024
…testonly

Automatic update from web-platform-tests
Add tests for Blob.prototype.bytes()

For w3c/FileAPI#198.
--

wpt-commits: cceaf3628da950621004d9b5d8c1d1f367073347
wpt-pr: 46232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants