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/08_text_encoding.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'op_crates/web/08_text_encoding.js') diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js index 6a6b23f71..d1b14b98b 100644 --- a/op_crates/web/08_text_encoding.js +++ b/op_crates/web/08_text_encoding.js @@ -1134,14 +1134,16 @@ return new Uint8Array(output); } encodeInto(input, dest) { - const encoder = new UTF8Encoder(); - const inputStream = new Stream(stringToCodePoints(input)); - if (!(dest instanceof Uint8Array)) { throw new TypeError( "2nd argument to TextEncoder.encodeInto must be Uint8Array", ); } + if (dest.byteLength === 0) { + return { read: 0, written: 0 }; + } + const encoder = new UTF8Encoder(); + const inputStream = new Stream(stringToCodePoints(input)); let written = 0; let read = 0; -- cgit v1.2.3