-
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
lib: make the builtInObjects set deterministic during bootstrap #33049
Conversation
Make this list explicit instead of filtering over globalThis so that this list is deterministic during the bootstrap regardless of: a) Wether this file is required when the context is going to be serialized, or what the V8 flags are. V8 does not add SharedArrayBuffer, Atomics, WebAssembly, and other flaggable globals e.g. harmony ones to a context that will be serialized. b) Wether this file is required before or after bootstrap (Node.js adds things like Buffer, URL, etc.)
cc @BridgeAR @addaleax (because I found this when working on #32761 (comment)) |
const { builtInObjects } = require('internal/util/inspect'); | ||
// The content of this list depends on e.g. v8 flags, as well as | ||
// what gets added by Node.js to the global object. | ||
for (const key of ObjectGetOwnPropertyNames(globalThis)) { |
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 now contains these added by Node.js
'global',
'process',
'Buffer',
'URL',
'URLSearchParams',
'TextEncoder',
'TextDecoder',
'clearInterval',
'clearTimeout',
'setInterval',
'setTimeout',
'queueMicrotask',
'clearImmediate',
'setImmediate'
We still need this loop if we want to pick up what get's added by V8 through harmony flags (like WeakRefs). I wonder which of these do we want to skip? @BridgeAR
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 mostly do not need those. The only ones that we should keep are global classes that have a prototype. The current RegExp is not matching exactly what we actually need. I just checked and this seems to ideally model what is needed for inspect:
function isConstructor(name) {
try {
Reflect.construct(String, [], globalThis[name]);
} catch {
return false;
}
return globalThis[name].prototype !== undefined && name[0].toUpperCase() === name[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.
LGTM
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.
Nice 👍
Blocking this for now so that this set serves as a smoke test for a reland of https://chromium-review.googlesource.com/c/v8/v8/+/2143983 |
'Infinity', | ||
'NaN', |
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.
'Infinity', | |
'NaN', |
'NaN', | ||
'Boolean', | ||
'String', | ||
'Symbol', |
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.
'Symbol', |
'JSON', | ||
'Math', | ||
'Intl', |
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.
'JSON', | |
'Math', | |
'Intl', |
'Proxy', | ||
'Reflect' |
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.
'Proxy', | |
'Reflect' | |
'SharedArrayBuffer' |
const { builtInObjects } = require('internal/util/inspect'); | ||
// The content of this list depends on e.g. v8 flags, as well as | ||
// what gets added by Node.js to the global object. | ||
for (const key of ObjectGetOwnPropertyNames(globalThis)) { |
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 mostly do not need those. The only ones that we should keep are global classes that have a prototype. The current RegExp is not matching exactly what we actually need. I just checked and this seems to ideally model what is needed for inspect:
function isConstructor(name) {
try {
Reflect.construct(String, [], globalThis[name]);
} catch {
return false;
}
return globalThis[name].prototype !== undefined && name[0].toUpperCase() === name[0];
}
8ae28ff
to
2935f72
Compare
@joyeecheung do you still work on this? |
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Closing this because it has stalled. Feel free to reopen if this issue/PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions. |
Make this list explicit instead of filtering over globalThis so that
this list is deterministic during the bootstrap regardless of:
a) Wether this file is required when the context is going to be
serialized, or what the V8 flags are. V8 does not add
SharedArrayBuffer, Atomics, WebAssembly, and other flaggable
globals e.g. harmony ones to a context that will be serialized.
b) Wether this file is required before or after bootstrap
(Node.js adds things like Buffer, URL, etc.)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes