@@ -64,6 +64,7 @@ const {
64
64
} = binding ;
65
65
66
66
const STATUS_MAP = {
67
+ __proto__ : null ,
67
68
[ kUninstantiated ] : 'unlinked' ,
68
69
[ kInstantiating ] : 'linking' ,
69
70
[ kInstantiated ] : 'linked' ,
@@ -251,13 +252,15 @@ class Module {
251
252
}
252
253
}
253
254
254
- const kDependencySpecifiers = Symbol ( 'kDependencySpecifiers' ) ;
255
255
const kNoError = Symbol ( 'kNoError' ) ;
256
256
257
257
class SourceTextModule extends Module {
258
258
#error = kNoError ;
259
259
#statusOverride;
260
260
261
+ #moduleRequests;
262
+ #dependencySpecifiers;
263
+
261
264
constructor ( sourceText , options = kEmptyObject ) {
262
265
validateString ( sourceText , 'sourceText' ) ;
263
266
validateObject ( options , 'options' ) ;
@@ -298,20 +301,25 @@ class SourceTextModule extends Module {
298
301
importModuleDynamically,
299
302
} ) ;
300
303
301
- this [ kDependencySpecifiers ] = undefined ;
304
+ this . #moduleRequests = ObjectFreeze ( ArrayPrototypeMap ( this [ kWrap ] . getModuleRequests ( ) , ( request ) => {
305
+ return ObjectFreeze ( {
306
+ __proto__ : null ,
307
+ specifier : request . specifier ,
308
+ attributes : request . attributes ,
309
+ } ) ;
310
+ } ) ) ;
302
311
}
303
312
304
313
async [ kLink ] ( linker ) {
305
314
this . #statusOverride = 'linking' ;
306
315
307
- const moduleRequests = this [ kWrap ] . getModuleRequests ( ) ;
308
316
// Iterates the module requests and links with the linker.
309
317
// Specifiers should be aligned with the moduleRequests array in order.
310
- const specifiers = Array ( moduleRequests . length ) ;
311
- const modulePromises = Array ( moduleRequests . length ) ;
318
+ const specifiers = Array ( this . # moduleRequests. length ) ;
319
+ const modulePromises = Array ( this . # moduleRequests. length ) ;
312
320
// Iterates with index to avoid calling into userspace with `Symbol.iterator`.
313
- for ( let idx = 0 ; idx < moduleRequests . length ; idx ++ ) {
314
- const { specifier, attributes } = moduleRequests [ idx ] ;
321
+ for ( let idx = 0 ; idx < this . # moduleRequests. length ; idx ++ ) {
322
+ const { specifier, attributes } = this . # moduleRequests[ idx ] ;
315
323
316
324
const linkerResult = linker ( specifier , this , {
317
325
attributes,
@@ -349,16 +357,16 @@ class SourceTextModule extends Module {
349
357
}
350
358
351
359
get dependencySpecifiers ( ) {
352
- validateThisInternalField ( this , kDependencySpecifiers , 'SourceTextModule' ) ;
353
- // TODO(legendecas): add a new getter to expose the import attributes as the value type
354
- // of [[RequestedModules]] is changed in https://tc39.es/proposal-import-attributes/#table-cyclic-module-fields.
355
- this [ kDependencySpecifiers ] ??= ObjectFreeze (
356
- ArrayPrototypeMap ( this [ kWrap ] . getModuleRequests ( ) , ( request ) => request . specifier ) ) ;
357
- return this [ kDependencySpecifiers ] ;
360
+ this . #dependencySpecifiers ??= ObjectFreeze (
361
+ ArrayPrototypeMap ( this . #moduleRequests, ( request ) => request . specifier ) ) ;
362
+ return this . #dependencySpecifiers;
363
+ }
364
+
365
+ get moduleRequests ( ) {
366
+ return this . #moduleRequests;
358
367
}
359
368
360
369
get status ( ) {
361
- validateThisInternalField ( this , kDependencySpecifiers , 'SourceTextModule' ) ;
362
370
if ( this . #error !== kNoError ) {
363
371
return 'errored' ;
364
372
}
@@ -369,7 +377,6 @@ class SourceTextModule extends Module {
369
377
}
370
378
371
379
get error ( ) {
372
- validateThisInternalField ( this , kDependencySpecifiers , 'SourceTextModule' ) ;
373
380
if ( this . #error !== kNoError ) {
374
381
return this . #error;
375
382
}
@@ -432,8 +439,12 @@ class SyntheticModule extends Module {
432
439
}
433
440
434
441
function importModuleDynamicallyWrap ( importModuleDynamically ) {
435
- const importModuleDynamicallyWrapper = async ( ...args ) => {
436
- const m = await ReflectApply ( importModuleDynamically , this , args ) ;
442
+ const importModuleDynamicallyWrapper = async ( specifier , referrer , attributes ) => {
443
+ const m = await ReflectApply (
444
+ importModuleDynamically ,
445
+ this ,
446
+ [ specifier , referrer , attributes ] ,
447
+ ) ;
437
448
if ( isModuleNamespaceObject ( m ) ) {
438
449
return m ;
439
450
}
0 commit comments