@@ -25,6 +25,7 @@ const {
2525 exposeLazyInterfaces,
2626 defineReplaceableLazyAttribute,
2727 setupCoverageHooks,
28+ kEmptyObject,
2829} = require ( 'internal/util' ) ;
2930
3031const {
@@ -57,6 +58,18 @@ function prepareWorkerThreadExecution() {
5758 } ) ;
5859}
5960
61+ function prepareShadowRealmExecution ( ) {
62+ // Patch the process object with legacy properties and normalizations
63+ // Do not expand argv1 as it is not available in ShadowRealm
64+ patchProcessObject ( false ) ;
65+ setupDebugEnv ( ) ;
66+
67+ setupUserModules ( {
68+ __proto__ : null ,
69+ noPreloadModules : true ,
70+ } ) ;
71+ }
72+
6073function prepareExecution ( options ) {
6174 const { expandArgv1, initializeModules, isMainThread } = options ;
6275
@@ -132,12 +145,15 @@ function setupSymbolDisposePolyfill() {
132145 Symbol . asyncDispose ??= SymbolAsyncDispose ;
133146}
134147
135- function setupUserModules ( isLoaderWorker = false ) {
148+ function setupUserModules ( options = kEmptyObject ) {
149+ const { isLoaderWorker = false , noPreloadModules = false } = options ;
136150 initializeCJSLoader ( ) ;
137151 initializeESMLoader ( isLoaderWorker ) ;
138152 const CJSLoader = require ( 'internal/modules/cjs/loader' ) ;
139153 assert ( ! CJSLoader . hasLoadedAnyUserCJSModule ) ;
140- loadPreloadModules ( ) ;
154+ if ( ! noPreloadModules ) {
155+ loadPreloadModules ( ) ;
156+ }
141157 // Need to be done after --require setup.
142158 initializeFrozenIntrinsics ( ) ;
143159}
@@ -666,5 +682,6 @@ module.exports = {
666682 setupUserModules,
667683 prepareMainThreadExecution,
668684 prepareWorkerThreadExecution,
685+ prepareShadowRealmExecution,
669686 markBootstrapComplete,
670687} ;
0 commit comments