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/08_text_encoding.js | |
parent | 6a50615e7cc703b28a3e60c15980568c2fb0a020 (diff) |
fix(op_crates/web) let TextEncoder#encodeInto accept detached ArrayBuffers (#9143)
Diffstat (limited to 'op_crates/web/08_text_encoding.js')
-rw-r--r-- | op_crates/web/08_text_encoding.js | 8 |
1 files changed, 5 insertions, 3 deletions
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; |