From db3a1d66331c88917f59beaabf2faf0de11e3019 Mon Sep 17 00:00:00 2001 From: Anonymous <65428781+00ff0000red@users.noreply.github.com> Date: Mon, 18 Jan 2021 07:04:46 -0800 Subject: fix(op_crates/web) let TextEncoder#encodeInto accept detached ArrayBuffers (#9143) --- op_crates/web/text_encoding_test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'op_crates/web/text_encoding_test.js') diff --git a/op_crates/web/text_encoding_test.js b/op_crates/web/text_encoding_test.js index 2c7cbd641..9a289b8b8 100644 --- a/op_crates/web/text_encoding_test.js +++ b/op_crates/web/text_encoding_test.js @@ -243,6 +243,22 @@ function textEncodeInto3() { assertArrayEquals(Array.from(bytes), [0xf0, 0x9d, 0x93, 0xbd, 0x00]); } +function textEncodeIntoDetachedBuffer() { + const fixture = "𝓽𝓮𝔁𝓽"; + const encoder = new TextEncoder(); + const memory = new WebAssembly.Memory({ + initial: 1, + maximum: 1, + shared: false, + }); + const bytes = new Uint8Array(memory.buffer, 0, 100); + memory.grow(0); // detaches memory.buffer + const result = encoder.encodeInto(fixture, bytes); + assert(bytes.byteLength === 0); + assert(result.read === 0); + assert(result.written === 0); +} + function textDecoderSharedUint8Array() { const ab = new SharedArrayBuffer(6); const dataView = new DataView(ab); @@ -1209,6 +1225,7 @@ function main() { textEncodeInto(); textEncodeInto2(); textEncodeInto3(); + textEncodeIntoDetachedBuffer(); textDecoderSharedUint8Array(); textDecoderSharedInt32Array(); toStringShouldBeWebCompatibility(); -- cgit v1.2.3