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

lib: make the builtInObjects set deterministic during bootstrap #33049

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

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.)
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Apr 24, 2020
@joyeecheung
Copy link
Member Author

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)) {
Copy link
Member Author

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

Copy link
Member

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];
}

lib/internal/util/inspect.js Outdated Show resolved Hide resolved
lib/internal/util/inspect.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/pre_execution.js Outdated Show resolved Hide resolved
Copy link
Member

@juanarbol juanarbol left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot
Copy link
Collaborator

Copy link
Contributor

@antsmartian antsmartian left a comment

Choose a reason for hiding this comment

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

Nice 👍

@joyeecheung joyeecheung added the blocked PRs that are blocked by other issues or PRs. label May 12, 2020
@joyeecheung
Copy link
Member Author

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

Comment on lines +146 to +147
'Infinity',
'NaN',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'Infinity',
'NaN',

'NaN',
'Boolean',
'String',
'Symbol',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'Symbol',

Comment on lines +161 to +163
'JSON',
'Math',
'Intl',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'JSON',
'Math',
'Intl',

Comment on lines +182 to +183
'Proxy',
'Reflect'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'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)) {
Copy link
Member

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];
}

@BridgeAR
Copy link
Member

BridgeAR commented Dec 1, 2021

@joyeecheung do you still work on this?

@aduh95 aduh95 added the stalled Issues and PRs that are stalled. label May 11, 2024
Copy link
Contributor

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.

Copy link
Contributor

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.

@github-actions github-actions bot closed this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. stalled Issues and PRs that are stalled. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants