-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
util: expose the WHATWG Encoding API globally #20662
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
Changes from 1 commit
ffd137a
651ad34
7020995
5820e16
98b1684
a6637f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This commit makes `util.TextEncoder` and `util.TextDecoder` available on the global object.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -771,9 +771,13 @@ added: v8.0.0 | |
| * {symbol} that can be used to declare custom promisified variants of functions, | ||
| see [Custom promisified functions][]. | ||
|
|
||
| ## Class: util.TextDecoder | ||
| ## Class: TextDecoder | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is confusing if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mscdex I did this for consistency since, in the But I agree with you that this is confusing. In the case of So I'm gonna change this here, and also follow your suggestion of moving the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mscdex Actually, I'm not quite sure about this. All the globals in In fact, I think there are 3 possibilities here: [1.] Keep the encoding documentation in
[2.] Move the encoding documentation to
[3.] Move the encoding documentation to a new documentation section, e.g.
In any case, I'm not sure what's a good way to proceed with this. So I'd greatly appreciate more feedback regarding this issue. PS: When I go to https://nodejs.org/dist/latest-v10.x/docs/api/, I sorely miss a tiny search-box in the top-right corner - I think that would help a lot.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For overall doc search, you can use "View on single page" variant, there is a link at the top of each doc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vsemozhetbyt True, but I don't think that's a friendly UX/DX. (Especially on mobile, loading the whole documentation on a single page might not be the best option. But then again, I think this is off-topic here.) |
||
| <!-- YAML | ||
| added: v8.3.0 | ||
| changes: | ||
| - version: v11.0.0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this should be specified here, I think we use a placeholder that gets filled in later?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for the other v11.0.0 uses in this file and globals.md. |
||
| pr-url: https://github.com/nodejs/node/pull/TO_DO | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these need updated |
||
| description: The class is now available on the global object. | ||
| --> | ||
|
|
||
| An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API. | ||
|
|
@@ -908,9 +912,13 @@ thrown. | |
| The value will be `true` if the decoding result will include the byte order | ||
| mark. | ||
|
|
||
| ## Class: util.TextEncoder | ||
| ## Class: TextEncoder | ||
| <!-- YAML | ||
| added: v8.3.0 | ||
| changes: | ||
| - version: v11.0.0 | ||
| pr-url: https://github.com/nodejs/node/pull/TO_DO | ||
| description: The class is now available on the global object. | ||
| --> | ||
|
|
||
| An implementation of the [WHATWG Encoding Standard][] `TextEncoder` API. All | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,15 @@ export function leakedGlobals() { | |
| knownGlobals.push(Symbol); | ||
| } | ||
|
|
||
| // WHATWG APIs | ||
| if (global.TextEncoder) { | ||
| knownGlobals.push(TextEncoder); | ||
| } | ||
|
|
||
| if (global.TextDecoder) { | ||
| knownGlobals.push(TextDecoder) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If these values are added to the global, they should not be checked for. Instead, they should be added to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, they should not be checked for conditionally. So I'm gonna add Thanks for the feedback, @BridgeAR! On another note, I think the recently added BTW, the globals are only added in the following case: const browserGlobals = !process._noBrowserGlobals;
if (browserGlobals) {
// ...
}I could not find any documentation regarding this, except that there was once a So I assume I could remove these 2 lines, too? EDIT: I found out I can't remove these 2 lines. The no-browser-globals mode can be turned on with |
||
|
|
||
| const leaked = []; | ||
|
|
||
| for (const val in global) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const { TextEncoder, TextDecoder } = require('util'); | ||
|
|
||
| assert.deepStrictEqual( | ||
| Object.getOwnPropertyDescriptor(global, 'TextEncoder'), | ||
| { | ||
| value: TextEncoder, | ||
| writable: true, | ||
| configurable: true, | ||
| enumerable: false | ||
| } | ||
| ); | ||
|
|
||
| assert.deepStrictEqual( | ||
| Object.getOwnPropertyDescriptor(global, 'TextDecoder'), | ||
| { | ||
| value: TextDecoder, | ||
| writable: true, | ||
| configurable: true, | ||
| enumerable: false | ||
| } | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a new line at the end
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AyushG3112 Done: 651ad34 |
||
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.
If what we're doing is migrating from
utilto a global, I think it'd be better to have the reverse: document here and haveutil.TextEncoderlink to the definition here.