FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: fix TypeError when converting a detached buffer source by cola119 · Pull Request #44020 · nodejs/node · GitHub

/ node Public

lib: fix TypeError when converting a detached buffer source - #44020

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
cola119:fix-type-error-of-detached-buffer
Nov 1, 2022
Merged

lib: fix TypeError when converting a detached buffer source#44020
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
cola119:fix-type-error-of-detached-buffer

Conversation

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: ""

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 force-pushed the fix-type-error-of-detached-buffer branch from bbb15af to ad6a134 Compare July 28, 2022 09:08

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

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.

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().

cola119 force-pushed the fix-type-error-of-detached-buffer branch from ad6a134 to 6639bec Compare July 30, 2022 04:08
aduh95 added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 28, 2022
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 28, 2022

Copy link
Copy Markdown
Collaborator

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?

aduh95 removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Oct 29, 2022
cola119 force-pushed the fix-type-error-of-detached-buffer branch from 6639bec to 89329e6 Compare October 30, 2022 04:43

cola119 commented Oct 30, 2022
edited
Loading

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.)

aduh95 added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 30, 2022
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 30, 2022

Copy link
Copy Markdown
Collaborator

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 commented Oct 30, 2022

Copy link
Copy Markdown
Member Author

Rebased and squashed

cola119 added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 30, 2022
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 30, 2022

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

cola119 removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Oct 31, 2022
cola119 force-pushed the fix-type-error-of-detached-buffer branch from a154022 to 2007eb5 Compare October 31, 2022 13:32
cola119 added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2022
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2022

Copy link
Copy Markdown
Collaborator

cola119 commented Nov 1, 2022

Copy link
Copy Markdown
Member Author

@aduh95 PTAL 2007eb5

aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 1, 2022
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 1, 2022
nodejs-github-bot merged commit 86088ab into nodejs:main Nov 1, 2022

Copy link
Copy Markdown
Collaborator

Landed in 86088ab

RafaelGSS pushed a commit that referenced this pull request Nov 10, 2022
PR-URL: #44020
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
RafaelGSS mentioned this pull request Nov 10, 2022
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
PR-URL: #44020
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
danielleadams pushed a commit that referenced this pull request Jan 3, 2023
PR-URL: #44020
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL