Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: implement buffer.atob and buffer.btoa #37529

Closed
wants to merge 2 commits into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Feb 26, 2021

Web Platform atob and btoa impl.

Just an initial get it working impl, not performance optimized.

Signed-off-by: James M Snell jasnell@gmail.com
Fixes: #3462

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 26, 2021
@nodejs-github-bot nodejs-github-bot added the buffer Issues and PRs related to the buffer subsystem. label Feb 26, 2021
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Kinda feeling "meh" on repeating the web's mistakes, but I can see the point for web compat.

doc/api/buffer.md Show resolved Hide resolved
doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Show resolved Hide resolved
@benjamingr
Copy link
Member

I also don't really see the point for this API in Node.js, especially since ours (.toString on buffer) is arguably better and this API does not actually improve web compatibility by much since it's not global (and global probably isn't worth the breakage)

@jasnell
Copy link
Member Author

jasnell commented Feb 27, 2021

Yep. It's been a long standing open feature request, and is implemented in other platforms, it was a quick impl so I figured let's see what the reaction is. I'm fine with not having this either. I'll close this and close the feature request issue as a #wontfix.

@jasnell jasnell closed this Feb 27, 2021
@jasnell
Copy link
Member Author

jasnell commented Mar 17, 2021

I'm reopening this as I've had three separate, independent conversations with different folks in the past two weeks about the lack of atob/btoa in core. Yes, it's not as good as what we already have, and no, I don't see it as being critical, but the implementation is simple and easily maintained and it does improve cross-platform interop.

@jasnell jasnell reopened this Mar 17, 2021
@ljharb
Copy link
Member

ljharb commented Mar 17, 2021

@jasnell why couldn’t they be globals? (I’m sure there’s discussion somewhere, but I’d love to read it linked from here)

@jasnell
Copy link
Member Author

jasnell commented Mar 17, 2021

Globals are semver major. If this lands I'll open a separate commit adding that. But this way it allows us the option of backporting the basic impls to 15 and 14

@ljharb
Copy link
Member

ljharb commented Mar 17, 2021

awesome, sounds like a great plan

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Just making sure this doesn’t land until it has a big, bold warning against using it (or deprecation notice, tbh – I’d personally say that introducing this as a deprecated feature from the start would be just fine, but I’m guessing not everybody’s on the same page there…)

@jasnell
Copy link
Member Author

jasnell commented Mar 17, 2021

I'd be -1 for introducing as deprecated but I'm definitely adding a notice in the docs as suggested. I definitely say we need a new status indicator in the docs that Is-Not-Deprecated-But-Is-Also-Not-Recommended

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Mar 17, 2021

@jasnell jasnell requested a review from addaleax March 17, 2021 18:29
@ljharb
Copy link
Member

ljharb commented Mar 17, 2021

The JS spec is going to use the term "legacy" for "things that are icky that we wish we could get rid of", if that helps :-)

@jasnell
Copy link
Member Author

jasnell commented Mar 17, 2021

That does help, actually. There are a few APIs in core that are currently deprecated but really fall under that legacy category instead. I may have to open a PR adding that in as an option

doc/api/buffer.md Outdated Show resolved Hide resolved
Signed-off-by: James M Snell <jasnell@gmail.com>
Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell jasnell added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 17, 2021

const lazyInvalidCharError = hideStackFrames((message, name) => {
if (DOMException === undefined)
DOMException = internalBinding('messaging').DOMException;
Copy link
Member

Choose a reason for hiding this comment

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

why do we always have to lazily load this constructor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's gotten a bit out of hand really. I'm doing it for consistency. I recently landed a PR that updated the various AbortError instances to eliminate this in multiple places but there are still more. What would be good is a PR that moves DOMException into `internal/errors' and replaces these lazy loads for that.

@benjamingr
Copy link
Member

I'm still -0 on this (since right now we're just adding the bad methods without improving compatibility since they're not global) but I see the merit if they're global in the next major.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

jasnell added a commit that referenced this pull request Mar 18, 2021
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #37529
Fixes: #3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell added a commit that referenced this pull request Mar 18, 2021
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #37529
Fixes: #3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@jasnell
Copy link
Member Author

jasnell commented Mar 18, 2021

Landed in 08770bc and c6855eb

@jasnell jasnell closed this Mar 18, 2021
ruyadorno pushed a commit that referenced this pull request Mar 20, 2021
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #37529
Fixes: #3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
ruyadorno pushed a commit that referenced this pull request Mar 20, 2021
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #37529
Fixes: #3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
ruyadorno added a commit that referenced this pull request Mar 30, 2021
Notable changes:

* buffer:
  * implement btoa and atob (James M Snell) #37529
* deps:
  * upgrade npm to 7.7.6 (Ruy Adorno) #37968
* doc:
  * add legacy status to stability index (James M Snell) #37784
  * add @Linkgoron to collaborators (Nitzan Uziely) #37817
* http:
  * add http.ClientRequest.getRawHeaderNames() (simov) #37660
@ruyadorno ruyadorno mentioned this pull request Mar 30, 2021
ruyadorno added a commit that referenced this pull request Mar 30, 2021
PR-URL: #37977

Notable changes:

* buffer:
  * implement btoa and atob (James M Snell) #37529
* deps:
  * upgrade npm to 7.7.6 (Ruy Adorno) #37968
* doc:
  * add legacy status to stability index (James M Snell) #37784
  * add @Linkgoron to collaborators (Nitzan Uziely) #37817
* http:
  * add http.ClientRequest.getRawHeaderNames() (simov) #37660
ruyadorno added a commit that referenced this pull request Mar 31, 2021
PR-URL: #37977

Notable changes:

* buffer:
  * implement btoa and atob (James M Snell) #37529
* deps:
  * upgrade npm to 7.7.6 (Ruy Adorno) #37968
* doc:
  * add legacy status to stability index (James M Snell) #37784
  * add @Linkgoron to collaborators (Nitzan Uziely) #37817
* http:
  * add http.ClientRequest.getRawHeaderNames() (simov) #37660
ruyadorno added a commit that referenced this pull request Mar 31, 2021
PR-URL: #37977

Notable changes:

* buffer:
  * implement btoa and atob (James M Snell) #37529
* deps:
  * upgrade npm to 7.7.6 (Ruy Adorno) #37968
* doc:
  * add legacy status to stability index (James M Snell) #37784
  * add @Linkgoron to collaborators (Nitzan Uziely) #37817
* http:
  * add http.ClientRequest.getRawHeaderNames() (simov) #37660
targos pushed a commit that referenced this pull request May 1, 2021
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #37529
Fixes: #3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this pull request May 1, 2021
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #37529
Fixes: #3462
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@danielleadams danielleadams mentioned this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. buffer Issues and PRs related to the buffer subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

btoa() and atob()
7 participants