Skip to content

lib: expose v8.startupSnapshot functions on globalThis#63138

Open
addaleax wants to merge 1 commit intonodejs:mainfrom
addaleax:global-symbolfor-startupsnapshot
Open

lib: expose v8.startupSnapshot functions on globalThis#63138
addaleax wants to merge 1 commit intonodejs:mainfrom
addaleax:global-symbolfor-startupsnapshot

Conversation

@addaleax
Copy link
Copy Markdown
Member

@addaleax addaleax commented May 5, 2026

Not necessarily tied to this approach, but we've found this to be a genuine gap when trying to include libraries in startup snapshots. If we're reluctant to place these methods on the global object, I'd also consider the global process to be a good venue to expose this.


Expose methods from require('v8').startupSnapshot which are relevant for isomorphic libraries through a Symbol-indexed property on the global object.

This provides a mechanism for using these functions from libraries that do not integrate with Node.js's module system, while still enabling integration with the startup snapshot mechanism. It also provides a path for exposing this feature from other runtimes that support a startup-snapshot-style feature.

We do not typically expose runtime-specific/non-standard capabilities on the global object, so using a Symbol property seems like the best way to avoid any potential naming conflicts and its consequences.

Expose methods from `require('v8').startupSnapshot` which are
relevant for isomorphic libraries through a `Symbol`-indexed
property on the global object.

This provides a mechanism for using these functions from libraries
that do not integrate with Node.js's module system, while still
enabling integration with the startup snapshot mechanism.
It also provides a path for exposing this feature from other
runtimes that support a startup-snapshot-style feature.

We do not typically expose runtime-specific/non-standard
capabilities on the global object, so using a `Symbol` property
seems like the best way to avoid any potential naming conflicts
and its consequences.

Signed-off-by: Anna Henningsen <anna@addaleax.net>
@addaleax addaleax requested a review from joyeecheung May 5, 2026 22:55
@addaleax addaleax added semver-minor PRs that contain new features and should be released in the next minor version. snapshot Issues and PRs related to the startup snapshot labels May 5, 2026
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. util Issues and PRs related to the built-in util module. v8 module Issues and PRs related to the "v8" subsystem. labels May 5, 2026
@joyeecheung
Copy link
Copy Markdown
Member

I am a bit wary of adding things to globalThis. process would be a better compromise. Although if process is viable, then I think process.getBuiltinModule('v8').startupSnapshot also does the job? The API was specifically added to help isomorphic ESM feature-detect Node.js stuff.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.69%. Comparing base (6df4f7b) to head (ffc4000).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/node_util.cc 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63138      +/-   ##
==========================================
+ Coverage   89.67%   89.69%   +0.01%     
==========================================
  Files         712      712              
  Lines      221251   221269      +18     
  Branches    42391    42397       +6     
==========================================
+ Hits       198405   198462      +57     
+ Misses      14669    14623      -46     
- Partials     8177     8184       +7     
Files with missing lines Coverage Δ
lib/internal/process/pre_execution.js 98.03% <100.00%> (-0.36%) ⬇️
lib/internal/v8/startup_snapshot.js 95.80% <100.00%> (+0.31%) ⬆️
src/node_util.cc 80.65% <50.00%> (ø)

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. semver-minor PRs that contain new features and should be released in the next minor version. snapshot Issues and PRs related to the startup snapshot util Issues and PRs related to the built-in util module. v8 module Issues and PRs related to the "v8" subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants