@@ -51,7 +51,7 @@ class ModuleJob {
51
51
// `loader` is the Loader instance used for loading dependencies.
52
52
// `moduleProvider` is a function
53
53
constructor ( loader , url , importAssertions = { __proto__ : null } ,
54
- moduleProvider , isMain , inspectBrk ) {
54
+ moduleProvider , isMain , inspectBrk , sync = false ) {
55
55
this . loader = loader ;
56
56
this . importAssertions = importAssertions ;
57
57
this . isMain = isMain ;
@@ -64,6 +64,11 @@ class ModuleJob {
64
64
// `this.module` is also filled in below.
65
65
this . modulePromise = ReflectApply ( moduleProvider , loader , [ url , isMain ] ) ;
66
66
67
+ if ( sync ) {
68
+ this . module = this . modulePromise ;
69
+ this . modulePromise = PromiseResolve ( this . module ) ;
70
+ }
71
+
67
72
// Wait for the ModuleWrap instance being linked with all dependencies.
68
73
const link = async ( ) => {
69
74
this . module = await this . modulePromise ;
@@ -187,14 +192,18 @@ class ModuleJob {
187
192
}
188
193
189
194
runSync ( ) {
190
- assert ( this . modulePromise instanceof ModuleWrap ) ;
195
+ if ( this . instantiated !== undefined ) {
196
+ return this . instantiated ;
197
+ }
198
+ assert ( this . module instanceof ModuleWrap ) ;
191
199
192
200
// TODO: better handle errors
193
- this . modulePromise . instantiate ( ) ;
201
+ this . module . instantiate ( ) ;
202
+ this . instantiated = PromiseResolve ( ) ;
194
203
const timeout = - 1 ;
195
204
const breakOnSigint = false ;
196
- this . modulePromise . evaluate ( timeout , breakOnSigint ) ;
197
- return { __proto__ : null , module : this . modulePromise } ;
205
+ this . module . evaluate ( timeout , breakOnSigint ) ;
206
+ return { __proto__ : null , module : this . module } ;
198
207
}
199
208
200
209
async run ( ) {
0 commit comments