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

fix: Blob constructor on various ArrayBuffer views #40706

Merged
merged 8 commits into from Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/internal/blob.js
Expand Up @@ -121,10 +121,10 @@ function getSource(source, endings) {

// We copy into a new Uint8Array because the underlying
// BackingStores are going to be detached and owned by
// the Blob. We also don't want to have to worry about
// byte offsets.
source = new Uint8Array(source);
return [source.byteLength, source];
// the Blob.
const { buffer, byteOffset, byteLength } = source;
const slice = buffer.slice(byteOffset, byteOffset + byteLength);
return [byteLength, new Uint8Array(slice)];
}

class Blob {
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-blob.js
Expand Up @@ -220,3 +220,18 @@ assert.throws(() => new Blob({}), {
});
});
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Based on test/fixtures/wpt/FileAPI/blob/Blob-constructor.any.js
// which is disabled due to dependency on other web APIs.
// Exercises #40705

@aduh95 does this look good ?

(async () => {
const blob = new Blob([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to have a comment referencing where this test is coming from.

new Uint8Array([0x50, 0x41, 0x53, 0x53]),
new Int8Array([0x50, 0x41, 0x53, 0x53]),
new Uint16Array([0x4150, 0x5353]),
new Int16Array([0x4150, 0x5353]),
new Uint32Array([0x53534150]),
new Int32Array([0x53534150]),
new Float32Array([0xD341500000]),
]);

assert.strictEqual(blob.size, 28);
assert.strictEqual(blob.type, '');
})().then(common.mustCall());