diff options
author | Craig Morten <46491566+asos-craigmorten@users.noreply.github.com> | 2020-08-24 19:09:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-24 20:09:31 +0200 |
commit | 2d800f2cb936d2974982248e589a888250b5b604 (patch) | |
tree | ea02cf624452b0f30af5c376d61c2d60c7d58d31 /op_crates/web/08_text_encoding.js | |
parent | 545ea8e2171b0dc83477b98441241afe39771ed6 (diff) |
fix(op_crates/web): throw TypeError on invalid input types in TextDecoder.decode() (#7179)
Diffstat (limited to 'op_crates/web/08_text_encoding.js')
-rw-r--r-- | op_crates/web/08_text_encoding.js | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js index bf2e20049..e938eecd1 100644 --- a/op_crates/web/08_text_encoding.js +++ b/op_crates/web/08_text_encoding.js @@ -395,7 +395,8 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any function isEitherArrayBuffer(x) { - return x instanceof SharedArrayBuffer || x instanceof ArrayBuffer; + return x instanceof SharedArrayBuffer || x instanceof ArrayBuffer || + typeof x === "undefined"; } class TextDecoder { @@ -442,6 +443,7 @@ bytes = new Uint8Array(input); } else if ( typeof input === "object" && + input !== null && "buffer" in input && isEitherArrayBuffer(input.buffer) ) { @@ -451,7 +453,9 @@ input.byteLength, ); } else { - bytes = new Uint8Array(0); + throw new TypeError( + "Provided input is not of type ArrayBuffer or ArrayBufferView", + ); } // For simple utf-8 decoding "Deno.core.decode" can be used for performance |