@@ -64,6 +64,7 @@ const {
6464} = binding ;
6565
6666const STATUS_MAP = {
67+ __proto__ : null ,
6768 [ kUninstantiated ] : 'unlinked' ,
6869 [ kInstantiating ] : 'linking' ,
6970 [ kInstantiated ] : 'linked' ,
@@ -251,13 +252,15 @@ class Module {
251252 }
252253}
253254
254- const kDependencySpecifiers = Symbol ( 'kDependencySpecifiers' ) ;
255255const kNoError = Symbol ( 'kNoError' ) ;
256256
257257class SourceTextModule extends Module {
258258 #error = kNoError ;
259259 #statusOverride;
260260
261+ #moduleRequests;
262+ #dependencySpecifiers;
263+
261264 constructor ( sourceText , options = kEmptyObject ) {
262265 validateString ( sourceText , 'sourceText' ) ;
263266 validateObject ( options , 'options' ) ;
@@ -298,20 +301,25 @@ class SourceTextModule extends Module {
298301 importModuleDynamically,
299302 } ) ;
300303
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+ } ) ) ;
302311 }
303312
304313 async [ kLink ] ( linker ) {
305314 this . #statusOverride = 'linking' ;
306315
307- const moduleRequests = this [ kWrap ] . getModuleRequests ( ) ;
308316 // Iterates the module requests and links with the linker.
309317 // 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 ) ;
312320 // 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 ] ;
315323
316324 const linkerResult = linker ( specifier , this , {
317325 attributes,
@@ -349,16 +357,16 @@ class SourceTextModule extends Module {
349357 }
350358
351359 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;
358367 }
359368
360369 get status ( ) {
361- validateThisInternalField ( this , kDependencySpecifiers , 'SourceTextModule' ) ;
362370 if ( this . #error !== kNoError ) {
363371 return 'errored' ;
364372 }
@@ -369,7 +377,6 @@ class SourceTextModule extends Module {
369377 }
370378
371379 get error ( ) {
372- validateThisInternalField ( this , kDependencySpecifiers , 'SourceTextModule' ) ;
373380 if ( this . #error !== kNoError ) {
374381 return this . #error;
375382 }
@@ -432,8 +439,12 @@ class SyntheticModule extends Module {
432439}
433440
434441function 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+ ) ;
437448 if ( isModuleNamespaceObject ( m ) ) {
438449 return m ;
439450 }
0 commit comments