@@ -26,6 +26,7 @@ const {
26
26
exposeLazyInterfaces,
27
27
defineReplaceableLazyAttribute,
28
28
setupCoverageHooks,
29
+ kEmptyObject,
29
30
} = require ( 'internal/util' ) ;
30
31
31
32
const {
@@ -59,6 +60,18 @@ function prepareWorkerThreadExecution() {
59
60
} ) ;
60
61
}
61
62
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
+
62
75
function prepareExecution ( options ) {
63
76
const { expandArgv1, initializeModules, isMainThread } = options ;
64
77
@@ -150,16 +163,16 @@ function setupSymbolDisposePolyfill() {
150
163
}
151
164
}
152
165
153
- function setupUserModules ( isLoaderWorker = false ) {
166
+ function setupUserModules ( options = kEmptyObject ) {
167
+ const { isLoaderWorker = false , noPreloadModules = false } = options ;
154
168
initializeCJSLoader ( ) ;
155
169
initializeESMLoader ( isLoaderWorker ) ;
156
170
const CJSLoader = require ( 'internal/modules/cjs/loader' ) ;
157
171
assert ( ! CJSLoader . hasLoadedAnyUserCJSModule ) ;
158
172
// Loader workers are responsible for doing this themselves.
159
- if ( isLoaderWorker ) {
160
- return ;
173
+ if ( ! isLoaderWorker || noPreloadModules ) {
174
+ loadPreloadModules ( ) ;
161
175
}
162
- loadPreloadModules ( ) ;
163
176
// Need to be done after --require setup.
164
177
initializeFrozenIntrinsics ( ) ;
165
178
}
@@ -687,6 +700,7 @@ module.exports = {
687
700
setupUserModules,
688
701
prepareMainThreadExecution,
689
702
prepareWorkerThreadExecution,
703
+ prepareShadowRealmExecution,
690
704
markBootstrapComplete,
691
705
loadPreloadModules,
692
706
initializeFrozenIntrinsics,
0 commit comments