| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -412,7 +412,13 @@ function makeTextDecoderICU() { | |||
| 412 | 412 | decode(input = empty, options = kEmptyObject) { | |
| 413 | 413 | validateDecoder(this); | |
| 414 | 414 | if (isAnyArrayBuffer(input)) { | |
| 415 | - input = lazyBuffer().from(input); | ||
| 415 | + try { | ||
| 416 | + input = lazyBuffer().from(input); | ||
| 417 | + } catch { | ||
| 418 | + // If the buffer is detached, | ||
| 419 | + // use an empty Uint8Array to avoid TypeError | ||
| 420 | + input = empty; | ||
| 421 | + } | ||
| 416 | 422 | } else if (!isArrayBufferView(input)) { | |
| 417 | 423 | throw new ERR_INVALID_ARG_TYPE('input', | |
| 418 | 424 | ['ArrayBuffer', 'ArrayBufferView'], | |
@@ -485,10 +491,18 @@ function makeTextDecoderJS() { | |||
| 485 | 491 | decode(input = empty, options = kEmptyObject) { | |
| 486 | 492 | validateDecoder(this); | |
| 487 | 493 | if (isAnyArrayBuffer(input)) { | |
| 488 | - input = lazyBuffer().from(input); | ||
| 494 | + try { | ||
| 495 | + input = lazyBuffer().from(input); | ||
| 496 | + } catch { | ||
| 497 | + input = empty; | ||
| 498 | + } | ||
| 489 | 499 | } else if (isArrayBufferView(input)) { | |
| 490 | - input = lazyBuffer().from(input.buffer, input.byteOffset, | ||
| 491 | - input.byteLength); | ||
| 500 | + try { | ||
| 501 | + input = lazyBuffer().from(input.buffer, input.byteOffset, | ||
| 502 | + input.byteLength); | ||
| 503 | + } catch { | ||
| 504 | + input = empty; | ||
| 505 | + } | ||
| 492 | 506 | } else { | |
| 493 | 507 | throw new ERR_INVALID_ARG_TYPE('input', | |
| 494 | 508 | ['ArrayBuffer', 'ArrayBufferView'], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,3 +211,10 @@ if (common.hasIntl) { | |||
| 211 | 211 | assert.strictEqual(e.code, 'ERR_ENCODING_NOT_SUPPORTED'); | |
| 212 | 212 | } | |
| 213 | 213 | } | |
| 214 | + | ||
| 215 | + { | ||
| 216 | + const buffer = new ArrayBuffer(1); | ||
| 217 | + new MessageChannel().port1.postMessage(buffer, [buffer]); // buffer is detached | ||
| 218 | + const decoder = new TextDecoder(); | ||
| 219 | + assert.strictEqual(decoder.decode(buffer), ''); | ||
| 220 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,12 +61,7 @@ | |||
| 61 | 61 | "requires": ["small-icu"] | |
| 62 | 62 | }, | |
| 63 | 63 | "streams/decode-utf8.any.js": { | |
| 64 | - "requires": ["small-icu"], | ||
| 65 | - "fail": { | ||
| 66 | - "expected": [ | ||
| 67 | - "decoding a transferred ArrayBuffer chunk should give no output" | ||
| 68 | - ] | ||
| 69 | - } | ||
| 64 | + "requires": ["small-icu"] | ||
| 70 | 65 | }, | |
| 71 | 66 | "streams/decode-bad-chunks.any.js": { | |
| 72 | 67 | "fail": { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments