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 by cola119 · Pull Request #44020 · nodejs/node

Conversation

@cola119

@cola119 cola119 commented Jul 28, 2022

Copy link
Copy Markdown
Member

Currently TextDecoder.decode will throw TypeError when a detached buffer is given since it will try to convert a detached buffer into new buffer. This PR fixed TypeError by checking if a buffer is detached.

const buffer = new ArrayBuffer(1);
new MessageChannel().port1.postMessage(buffer, [buffer]); // buffer is detached
const decoder = new TextDecoder();
decoder.decode(buffer);
// node: TypeError: Cannot perform Construct on a detached ArrayBuffer
// chrome/safari/deno: ""

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@nodejs-github-bot nodejs-github-bot added encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run. labels Jul 28, 2022
@cola119
cola119 force-pushed the fix-type-error-of-detached-buffer branch from bbb15af to ad6a134 Compare July 28, 2022 09:08
BridgeAR
BridgeAR reviewed Jul 28, 2022
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user, I would rather have the error than an empty buffer. The reason is that with the empty buffer, I just do not realize that something does not work as I expected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cola119

cola119 commented Jul 28, 2022

Copy link
Copy Markdown
Member Author

I personally would like Node.js to have the same behavior as Web browser, especially in encoding APIs because many times I want to share the encoding logic between Web and server. Throwing TypeError feels confusing for me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@LiviaMedeiros

LiviaMedeiros commented Jul 28, 2022

Copy link
Copy Markdown
Member

Doesn't it look more like issue with Buffer.from()? new Uint8Array(ab) on detached buffer should throw but Uint8Array.from(ab) should return exactly what's expected in TextDecoder.decode().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cola119
cola119 force-pushed the fix-type-error-of-detached-buffer branch from ad6a134 to 6639bec Compare July 30, 2022 04:08
jasnell
jasnell approved these changes Aug 28, 2022
View reviewed changes
@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 28, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 28, 2022
@nodejs-github-bot

nodejs-github-bot commented Oct 28, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/47523/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Oct 29, 2022
CI Reliability 2022-10-29 nodejs/reliability#414
Open
15 tasks
@aduh95

aduh95 commented Oct 29, 2022

Copy link
Copy Markdown
Contributor

Error: Found 1 unexpected passes. Consider updating test/wpt/status/encoding.json for these files: streams/decode-utf8.any.js @cola119 could you take a look at this please?

cola119 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aduh95 aduh95 removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Oct 29, 2022
@github-actions github-actions Bot mentioned this pull request Oct 30, 2022
CI Reliability 2022-10-30 nodejs/reliability#415
Open
15 tasks
@cola119
cola119 force-pushed the fix-type-error-of-detached-buffer branch from 6639bec to 89329e6 Compare October 30, 2022 04:43
@cola119

cola119 commented Oct 30, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@aduh95 I updated the status accordingly. 89329e62540060b56adeacd6502d1366b9a5d50b PTAL.
(encoding.json was updated in #44101 and at that time streams/decode-utf8.any.js was expected to fail. This PR fixes that issue and I needed to update the status.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 30, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 30, 2022
@nodejs-github-bot

nodejs-github-bot commented Oct 30, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/47580/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cola119
cola119 force-pushed the fix-type-error-of-detached-buffer branch 2 times, most recently from 684f18a to a154022 Compare October 30, 2022 23:38
@cola119

cola119 commented Oct 30, 2022

Copy link
Copy Markdown
Member Author

Rebased and squashed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cola119 cola119 added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 30, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 30, 2022
@nodejs-github-bot

nodejs-github-bot commented Oct 30, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/47581/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Oct 31, 2022
CI Reliability 2022-10-31 nodejs/reliability#416
Open
19 tasks
@nodejs-github-bot

nodejs-github-bot commented Oct 31, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/47585/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cola119 cola119 removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Oct 31, 2022
cola119 added 2 commits October 31, 2022 22:27
@cola119
lib: fix TypeError when converting a detached buffer source
a8ed04f
@cola119
fixup! lib: fix TypeError when converting a detached buffer source
2007eb5
@cola119
cola119 force-pushed the fix-type-error-of-detached-buffer branch from a154022 to 2007eb5 Compare October 31, 2022 13:32
@cola119 cola119 added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 31, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 31, 2022
@nodejs-github-bot

nodejs-github-bot commented Oct 31, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/47591/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Nov 1, 2022
CI Reliability 2022-11-01 nodejs/reliability#417
Open
17 tasks
@cola119

cola119 commented Nov 1, 2022

Copy link
Copy Markdown
Member Author

@aduh95 PTAL 2007eb5

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aduh95
aduh95 approved these changes Nov 1, 2022
View reviewed changes
@aduh95 aduh95 added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 1, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 1, 2022
@nodejs-github-bot
nodejs-github-bot merged commit 86088ab into nodejs:main Nov 1, 2022
@nodejs-github-bot

nodejs-github-bot commented Nov 1, 2022

Copy link
Copy Markdown
Collaborator

Landed in 86088ab

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

RafaelGSS pushed a commit that referenced this pull request Nov 10, 2022
@cola119 @RafaelGSS
lib: fix TypeError when converting a detached buffer source
d172669
PR-URL: #44020
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
@RafaelGSS RafaelGSS mentioned this pull request Nov 10, 2022
v19.1.0 proposal #45269
Merged
@danielleadams danielleadams mentioned this pull request Dec 30, 2022
v18.13.0 release proposal #46025
Merged
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
@cola119 @danielleadams
lib: fix TypeError when converting a detached buffer source
68690ef
PR-URL: #44020
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 3, 2023
@cola119 @danielleadams
lib: fix TypeError when converting a detached buffer source
57897f8
PR-URL: #44020
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BridgeAR BridgeAR BridgeAR left review comments
@jasnell jasnell jasnell approved these changes
@aduh95 aduh95 aduh95 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@cola119 @LiviaMedeiros @nodejs-github-bot @aduh95 @jasnell @BridgeAR
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.