diff options
author | Anonymous <65428781+00ff0000red@users.noreply.github.com> | 2021-01-18 07:04:46 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 10:04:46 -0500 |
commit | db3a1d66331c88917f59beaabf2faf0de11e3019 (patch) | |
tree | 9d62ff4d154c588f473c6dc1fccffc348679e38f /op_crates/web/text_encoding_test.js | |
parent | 6a50615e7cc703b28a3e60c15980568c2fb0a020 (diff) |
fix(op_crates/web) let TextEncoder#encodeInto accept detached ArrayBuffers (#9143)
Diffstat (limited to 'op_crates/web/text_encoding_test.js')
-rw-r--r-- | op_crates/web/text_encoding_test.js | 17 |
1 files changed, 17 insertions, 0 deletions
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(); |