diff options
author | Andreu Botella <abb@randomunok.com> | 2021-10-28 14:17:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-28 23:17:27 +0200 |
commit | 74a93fdf63a17de990954399b10eb6dfe7dd1973 (patch) | |
tree | a1b0d8c48d6ad375100dd0bd8723f8910af47165 /ext/web/08_text_encoding.js | |
parent | 507ab50e0f33f0b4264c68179055ad8a7dc60320 (diff) |
fix(webidl): Don't throw when converting a detached buffer source (#12585)
The Web IDL conversion to `BufferSource` and similar types shouldn't
check whether the buffer is detached.
In the case of `TextDecoder`, our implementation would still throw after
the Web IDL conversions because we're creating a new `Uint8Array` from
the buffer source's buffer, which throws if it's detached. This change
also fixes this bug.
Diffstat (limited to 'ext/web/08_text_encoding.js')
-rw-r--r-- | ext/web/08_text_encoding.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index d3f6d45fb..d2922a6d4 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -105,14 +105,19 @@ } try { - if (ArrayBufferIsView(input)) { - input = new Uint8Array( - input.buffer, - input.byteOffset, - input.byteLength, - ); - } else { - input = new Uint8Array(input); + try { + if (ArrayBufferIsView(input)) { + input = new Uint8Array( + input.buffer, + input.byteOffset, + input.byteLength, + ); + } else { + input = new Uint8Array(input); + } + } catch { + // If the buffer is detached, just create a new empty Uint8Array. + input = new Uint8Array(); } if (input.buffer instanceof SharedArrayBuffer) { // We clone the data into a non-shared ArrayBuffer so we can pass it |