-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
deps,lib,src: remove dependency on --allow-natives-syntax #20719
Conversation
@@ -935,8 +934,7 @@ if (typeof Symbol !== 'undefined') { | |||
const aSet = new Set([1, 3]); | |||
assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }'); | |||
assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }'); | |||
assert.strictEqual(util.inspect(aSet.entries()), | |||
'[Set Iterator] { [ 1, 1 ], [ 3, 3 ] }'); | |||
assert.strictEqual(util.inspect(aSet.entries()), '[Set Iterator] { 1, 3 }'); |
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.
@nodejs/tsc Would we consider this a semver-major change? I’d prefer not to. If we do, I’d probably want to adjust the V8 CL first.
Edit: Would be cool to see as a quick poll: 👎 if you think it is semver-major, 👍 if you think this is fine as a patch change, 😕 if you don’t have an opinion
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.
I think this is more a kind of bugfix than a breaking change.
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.
@@ -915,7 +909,7 @@ function formatMap(ctx, value, recurseTimes, keys) { | |||
|
|||
function formatWeakSet(ctx, value, recurseTimes, keys) { | |||
const maxArrayLength = Math.max(ctx.maxArrayLength, 0); | |||
const entries = previewWeakSet(value, maxArrayLength + 1); | |||
const entries = previewEntries(value).slice(0, maxArrayLength + 1); |
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.
This is pretty bad for performance. The same for the other parts.
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.
Yeah, especially the lack of a limit is a bit “:confused:”, but on the other hand I don’t think any of these would typically be hot paths. (In particular, I don’t think we need to make showHidden: true
fast.)
@@ -935,8 +934,7 @@ if (typeof Symbol !== 'undefined') { | |||
const aSet = new Set([1, 3]); | |||
assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }'); | |||
assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }'); | |||
assert.strictEqual(util.inspect(aSet.entries()), | |||
'[Set Iterator] { [ 1, 1 ], [ 3, 3 ] }'); | |||
assert.strictEqual(util.inspect(aSet.entries()), '[Set Iterator] { 1, 3 }'); |
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.
I think this is more a kind of bugfix than a breaking change.
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.
Node.js parts LGTM.
@@ -29,7 +29,7 @@ const { | |||
ERR_INVALID_ARG_VALUE, | |||
}, | |||
} = require('internal/errors'); | |||
const { previewMapIterator, previewSetIterator } = require('internal/v8'); | |||
const { previewEntries } = process.binding('util'); |
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.
can we put them on an internalBinding instead?
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.
Any concrete preferences? The most stable part of process.binding('util')
(type checking) is runtime-deprecated in Node 10, so we might be able to move the entire util binding to internalBinding('util')
in Node 11 anyway…
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.
whatever gets it done is fine with me, i just want to see process.binding stop existing :)
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.
LGTM on the node parts
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.
Apropos the V8 changes, I'd probably add
WeakMap
and WeakSet
to v8.h that map to JSWeakMap
and JSWeakSet
. They have GetEntries()
methods that let you limit the number of returned elements. That seems too useful to pass up.
Likewise, MapIterator
and SetIterator
, mapping to JSMapIterator
and JSSetIterator
. Cloning the iterator like we do now is pretty elegant and straightforward: just call NewJSMapIterator()
or NewJSSetIterator()
with the iterator's table and index.
(I can chime in on the CL if you want but I figured most of the discussion so far happened here.)
@bnoordhuis Yeah, that sounds fine to me as well. It sounds like a non-trivial amount of extra work though, so I’d prefer to wait for feedback from somebody on the V8 team. :) |
Original commit message: [api] Expose PreviewEntries as public API Turn `debug::EntriesPreview` into a public API. This is a straightforward approach to addressing nodejs#20409 (not relying on functionality behind `--allow-natives-syntax`) in Node.js. Refs: v8/v8@ff0a979
Use a new public V8 API for inspecting weak collections and collection iterators, rather than using V8-internal functions to achieve this. This currently comes with a slight modification of the output for inspecting iterators generated by `Set().entries()`. Fixes: nodejs#20409
The upstream patch landed as it was in v8/v8@ff0a979, so I guess this is no longer blocked. |
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.
LGTM even though I would really love a follow up PR on V8 that adds a limit option.
return args.GetReturnValue().Set(entries); | ||
|
||
uint32_t length = entries->Length(); | ||
CHECK_EQ(length % 2, 0); |
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.
This check should actually be obsolete. We should realize it one way or the other if the V8 implementation is broken.
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.
Right now, if there’s a single extra element at the end, we wouldn’t notice that. Like, yes, obviously that would be a bug in V8, but I don’t think there’s much harm in the extra check?
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.
We should notice it because this code will only run in case we have a test for this code path and in those tests we actually strictly check the outcome.
Environment* env = Environment::GetCurrent(args); | ||
Local<Context> context = env->context(); | ||
|
||
Local<Array> pairs = Array::New(env->isolate(), length / 2); |
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.
do we know the speed impact of this loop being in js vs c++?
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.
@devsnek At least I don’t, but I guess the answer is that doing it in JS is a bit faster. But if we’re looking for optimizations, avoiding the pairs
array altogether is probably a much better (but requires some more restructuring of existing code on the JS side) and like I said, I don’t think any of these code paths are typically hot paths anyway.
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.
Thinking about it: that would not be complicated. It was actually implemented in WeakMap
like that before. The output would not be as nice but it is definitely faster, so I am +1 on that.
See https://github.com/nodejs/node/pull/20719/files#diff-3deb3f32958bb937ae05c6f3e4abbdf5L938 for the former implementation. It does not seem to be much difference using this approach, especially since the C++ function here would be smaller.
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.
That’s definitely a place where it’s easy to switch – but all other uses expected the array-of-tuples layout.
so I am +1 on that.
Yeah, I’d like that as well. Not as a blocker for this PR, though – you can feel freel to hack on this yourself, if you have concrete ideas about how this is going to look in the end?
Original commit message: [api] Expose PreviewEntries as public API Turn `debug::EntriesPreview` into a public API. This is a straightforward approach to addressing #20409 (not relying on functionality behind `--allow-natives-syntax`) in Node.js. Refs: v8/v8@ff0a979 PR-URL: #20719 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Use a new public V8 API for inspecting weak collections and collection iterators, rather than using V8-internal functions to achieve this. This currently comes with a slight modification of the output for inspecting iterators generated by `Set().entries()`. Fixes: #20409 PR-URL: #20719 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Use a plain `[key, value, key, value]`-style list instead of an array of pairs for inspecting collections. This also fixes a bug with `console.table()` where inspecting a non-key-value `MapIterator` would have led to odd results. Refs: nodejs#20719 (comment)
Original commit message: [api] Expose PreviewEntries as public API Turn `debug::EntriesPreview` into a public API. This is a straightforward approach to addressing nodejs#20409 (not relying on functionality behind `--allow-natives-syntax`) in Node.js. Refs: v8/v8@ff0a979 PR-URL: nodejs#20719 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Original commit message: [api] Expose PreviewEntries as public API Turn `debug::EntriesPreview` into a public API. This is a straightforward approach to addressing #20409 (not relying on functionality behind `--allow-natives-syntax`) in Node.js. Refs: v8/v8@ff0a979 PR-URL: #20719 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Original commit message: [api] Expose PreviewEntries as public API Turn `debug::EntriesPreview` into a public API. This is a straightforward approach to addressing #20409 (not relying on functionality behind `--allow-natives-syntax`) in Node.js. Refs: v8/v8@ff0a979 PR-URL: #20719 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Use a plain `[key, value, key, value]`-style list instead of an array of pairs for inspecting collections. This also fixes a bug with `console.table()` where inspecting a non-key-value `MapIterator` would have led to odd results. PR-URL: nodejs#20831 Refs: nodejs#20719 (comment) Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Use a plain `[key, value, key, value]`-style list instead of an array of pairs for inspecting collections. This also fixes a bug with `console.table()` where inspecting a non-key-value `MapIterator` would have led to odd results. PR-URL: #20831 Refs: #20719 (comment) Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Should this be backported to |
This is blocked on the freshly created https://chromium-review.googlesource.com/#/c/v8/v8/+/1057467 for now anyway. I don’t even have a good feeling for whether the V8 team is going to accept that, given that I get the impression that they seem a bit reluctant to add methods to the API that are not coming from the JS spec :)
fyi @BridgeAR @bnoordhuis @hashseed
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes