@@ -26,6 +26,7 @@ const {
2626 exposeLazyInterfaces,
2727 defineReplaceableLazyAttribute,
2828 setupCoverageHooks,
29+ kEmptyObject,
2930} = require ( 'internal/util' ) ;
3031
3132const {
@@ -59,6 +60,18 @@ function prepareWorkerThreadExecution() {
5960 } ) ;
6061}
6162
63+ function prepareShadowRealmExecution ( ) {
64+ // Patch the process object with legacy properties and normalizations.
65+ // Do not expand argv1 as it is not available in ShadowRealm.
66+ patchProcessObject ( false ) ;
67+ setupDebugEnv ( ) ;
68+
69+ setupUserModules ( {
70+ __proto__ : null ,
71+ noPreloadModules : true ,
72+ } ) ;
73+ }
74+
6275function prepareExecution ( options ) {
6376 const { expandArgv1, initializeModules, isMainThread } = options ;
6477
@@ -150,16 +163,16 @@ function setupSymbolDisposePolyfill() {
150163 }
151164}
152165
153- function setupUserModules ( isLoaderWorker = false ) {
166+ function setupUserModules ( options = kEmptyObject ) {
167+ const { isLoaderWorker = false , noPreloadModules = false } = options ;
154168 initializeCJSLoader ( ) ;
155169 initializeESMLoader ( isLoaderWorker ) ;
156170 const CJSLoader = require ( 'internal/modules/cjs/loader' ) ;
157171 assert ( ! CJSLoader . hasLoadedAnyUserCJSModule ) ;
158172 // Loader workers are responsible for doing this themselves.
159- if ( isLoaderWorker ) {
160- return ;
173+ if ( ! isLoaderWorker || noPreloadModules ) {
174+ loadPreloadModules ( ) ;
161175 }
162- loadPreloadModules ( ) ;
163176 // Need to be done after --require setup.
164177 initializeFrozenIntrinsics ( ) ;
165178}
@@ -687,6 +700,7 @@ module.exports = {
687700 setupUserModules,
688701 prepareMainThreadExecution,
689702 prepareWorkerThreadExecution,
703+ prepareShadowRealmExecution,
690704 markBootstrapComplete,
691705 loadPreloadModules,
692706 initializeFrozenIntrinsics,
0 commit comments