fix(op_crates/web) let TextEncoder#encodeInto accept detached ArrayBuffers (#9143)

This commit is contained in:
Anonymous 2021-01-18 07:04:46 -08:00 committed by GitHub
parent 6a50615e7c
commit db3a1d6633
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -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;