GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: fix TypeError when converting a detached buffer source · nodejs/node@57897f8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • encoding.js
  • test
    • parallel
      • test-whatwg-encoding-custom-textdecoder.js
    • wpt/status
      • encoding.json
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/encoding.js‎

Copy file name to clipboardExpand all lines: lib/internal/encoding.js
+18-4Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,13 @@ function makeTextDecoderICU() {
412412
decode(input = empty, options = kEmptyObject) {
413413
validateDecoder(this);
414414
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+
}
416422
} else if (!isArrayBufferView(input)) {
417423
throw new ERR_INVALID_ARG_TYPE('input',
418424
['ArrayBuffer', 'ArrayBufferView'],
@@ -485,10 +491,18 @@ function makeTextDecoderJS() {
485491
decode(input = empty, options = kEmptyObject) {
486492
validateDecoder(this);
487493
if (isAnyArrayBuffer(input)) {
488-
input = lazyBuffer().from(input);
494+
try {
495+
input = lazyBuffer().from(input);
496+
} catch {
497+
input = empty;
498+
}
489499
} 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+
}
492506
} else {
493507
throw new ERR_INVALID_ARG_TYPE('input',
494508
['ArrayBuffer', 'ArrayBufferView'],
Collapse file

‎test/parallel/test-whatwg-encoding-custom-textdecoder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-encoding-custom-textdecoder.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,10 @@ if (common.hasIntl) {
211211
assert.strictEqual(e.code, 'ERR_ENCODING_NOT_SUPPORTED');
212212
}
213213
}
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+
}
Collapse file

‎test/wpt/status/encoding.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/encoding.json
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@
6161
"requires": ["small-icu"]
6262
},
6363
"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"]
7065
},
7166
"streams/decode-bad-chunks.any.js": {
7267
"fail": {

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.