#53546: fix: only run the node_init preload in the principal realm
Description of Change
Node runs the embedder preload for every realm it bootstraps, including ShadowRealms, and Electron's preload is the node_init bundle (asar support, child_process hooks). Inside a ShadowRealm that bundle has nothing to work with and currently dies on its first line, so every new ShadowRealm() in a process with Node integration prints CompileAndCall failed to evaluate electron script (electron/js2c/node_init): Uncaught TypeError: internalBinding is not a function to stderr. OnNodePreload now returns early for any realm other than the principal one.
That stderr line was the only reason parallel/test-shadow-realm-custom-loaders was disabled, so it comes off the list; all eight test-shadow-realm* tests pass. #53528 carries the same guard because its asar change needs it; whichever lands second just loses the hunk.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses
Release Notes
Notes: Fixed a spurious node_init error being logged when creating a ShadowRealm with Node.js integration enabled.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron