Skip to content

Add support for [AllowResizable] inputs in TextDeEncoder#58636

Draft
daxpedda wants to merge 1 commit intoweb-platform-tests:masterfrom
daxpedda:encode-resizable
Draft

Add support for [AllowResizable] inputs in TextDeEncoder#58636
daxpedda wants to merge 1 commit intoweb-platform-tests:masterfrom
daxpedda:encode-resizable

Conversation

@daxpedda
Copy link
Copy Markdown

@daxpedda daxpedda marked this pull request as draft March 20, 2026 09:35
@wpt-pr-bot wpt-pr-bot requested review from annevk and yuki3 March 20, 2026 09:35
const destinationFiller = destinationData.filler;
const encoder = new TextEncoder();
const opts = resizable ? { maxByteLength: bufferLength } : undefined;
const buffer = createBuffer(arrayBufferOrSharedArrayBuffer, bufferLength, opts);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because we always want the max length to be the buffer length, I think this could be better solved on the createBuffer level. Maybe detect if opts is a boolean is an option?

Comment on lines -17 to -30

test(t => {
const enc = new TextEncoder();

// Fixed-length SABs should not throw
const sab = createBuffer('SharedArrayBuffer', 16);
enc.encodeInto("foobar", new Uint8Array(sab));

const gsab = createBuffer('SharedArrayBuffer', 16, { maxByteLength: 1024 });
// TextEncoder.encodeInto doesn't have [AllowResizable] but has [AllowShared]
assert_throws_js(TypeError, () => {
enc.encodeInto("foobar", new Uint8Array(gsab));
});
}, "APIs with [AllowShared] but without [AllowResizable] throw when passed growable SharedArrayBuffers");
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No API exists that fulfills these conditions apart from FileSystemSyncAccessHandle.read/write().
I felt like handling this here would be out of scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants