@@ -322,9 +322,9 @@ intrinsically asynchronous, in contrast with the synchronous nature of
322
322
` vm.Script ` objects. With the help of async functions, however, manipulating
323
323
` vm.SourceTextModule ` objects is fairly straightforward.
324
324
325
- Using a ` vm.SourceTextModule ` object requires four distinct steps:
326
- creation/parsing, linking, instantiation, and evaluation. These four steps are
327
- illustrated in the following example.
325
+ Using a ` vm.SourceTextModule ` object requires three distinct steps:
326
+ creation/parsing, linking, and evaluation. These three steps are illustrated in
327
+ the following example.
328
328
329
329
This implementation lies at a lower level than the [ ECMAScript Module
330
330
loader] [ ] . There is also currently no way to interact with the Loader, though
@@ -391,15 +391,6 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
391
391
392
392
// Step 3
393
393
//
394
- // Instantiate the top-level Module.
395
- //
396
- // Only the top-level Module needs to be explicitly instantiated; its
397
- // dependencies will be recursively instantiated by instantiate().
398
-
399
- bar .instantiate ();
400
-
401
- // Step 4
402
- //
403
394
// Evaluate the Module. The evaluate() method returns a Promise with a single
404
395
// property "result" that contains the result of the very last statement
405
396
// executed in the Module. In the case of `bar`, it is `s;`, which refers to
@@ -417,8 +408,9 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
417
408
418
409
* ` code ` {string} JavaScript Module code to parse
419
410
* ` options `
420
- * ` url ` {string} URL used in module resolution and stack traces. ** Default:**
421
- ` 'vm:module(i)' ` where ` i ` is a context-specific ascending index.
411
+ * ` identifier ` {string} String used in stack traces.
412
+ ** Default:** ` 'vm:module(i)' ` where ` i ` is a context-specific ascending
413
+ index.
422
414
* ` context ` {Object} The [ contextified] [ ] object as returned by the
423
415
` vm.createContext() ` method, to compile and evaluate this ` Module ` in.
424
416
* ` lineOffset ` {integer} Specifies the line number offset that is displayed
@@ -465,7 +457,6 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
465
457
});
466
458
// Since module has no dependencies, the linker function will never be called.
467
459
await module .link (() => {});
468
- module .instantiate ();
469
460
await module .evaluate ();
470
461
471
462
// Now, Object.prototype.secret will be equal to 42.
@@ -516,7 +507,7 @@ in the ECMAScript specification.
516
507
517
508
Evaluate the module.
518
509
519
- This must be called after the module has been instantiated ; otherwise it will
510
+ This must be called after the module has been linked ; otherwise it will
520
511
throw an error. It could be called also when the module has already been
521
512
evaluated, in which case it will do one of the following two things:
522
513
@@ -531,23 +522,6 @@ This method cannot be called while the module is being evaluated
531
522
Corresponds to the [ Evaluate() concrete method] [ ] field of [ Source Text Module
532
523
Record] [ ] s in the ECMAScript specification.
533
524
534
- ### module.instantiate()
535
-
536
- Instantiate the module. This must be called after linking has completed
537
- (` linkingStatus ` is ` 'linked' ` ); otherwise it will throw an error. It may also
538
- throw an exception if one of the dependencies does not provide an export the
539
- parent module requires.
540
-
541
- However, if this function succeeded, further calls to this function after the
542
- initial instantiation will be no-ops, to be consistent with the ECMAScript
543
- specification.
544
-
545
- Unlike other methods operating on ` Module ` , this function completes
546
- synchronously and returns nothing.
547
-
548
- Corresponds to the [ Instantiate() concrete method] [ ] field of [ Source Text
549
- Module Record] [ ] s in the ECMAScript specification.
550
-
551
525
### module.link(linker)
552
526
553
527
* ` linker ` {Function}
@@ -563,17 +537,17 @@ Module Record][]s in the ECMAScript specification.
563
537
* Returns: {vm .SourceTextModule | Promise }
564
538
* Returns: {Promise }
565
539
566
- Link module dependencies . This method must be called before instantiation , and
540
+ Link module dependencies . This method must be called before evaluation , and
567
541
can only be called once per module .
568
542
569
543
The function is expected to return a `Module` object or a `Promise` that
570
544
eventually resolves to a `Module` object. The returned `Module` must satisfy the
571
545
following two invariants:
572
546
573
547
* It must belong to the same context as the parent `Module`.
574
- * Its `linkingStatus ` must not be `'errored'`.
548
+ * Its `status ` must not be `'errored'`.
575
549
576
- If the returned `Module`'s `linkingStatus ` is `'unlinked'`, this method will be
550
+ If the returned `Module`'s `status ` is `'unlinked'`, this method will be
577
551
recursively called on the returned `Module` with the same provided `linker`
578
552
function .
579
553
@@ -587,37 +561,22 @@ specification, with a few key differences:
587
561
588
562
* The linker function is allowed to be asynchronous while
589
563
[HostResolveImportedModule][] is synchronous.
590
- * The linker function is executed during linking, a Node.js-specific stage
591
- before instantiation, while [HostResolveImportedModule][] is called during
592
- instantiation.
593
564
594
565
The actual [HostResolveImportedModule][] implementation used during module
595
- instantiation is one that returns the modules linked during linking. Since at
566
+ linking is one that returns the modules linked during linking. Since at
596
567
that point all modules would have been fully linked already, the
597
568
[HostResolveImportedModule][] implementation is fully synchronous per
598
569
specification.
599
570
600
- ### module.linkingStatus
601
-
602
- * {string}
603
-
604
- The current linking status of ` module` . It will be one of the following values:
605
-
606
- * ` 'unlinked'` : ` module.link()` has not yet been called.
607
- * ` 'linking'` : ` module.link()` has been called, but not all Promises returned by
608
- the linker function have been resolved yet.
609
- * `'linked'`: `module.link ()` has been called, and all its dependencies have
610
- been successfully linked.
611
- * `'errored'`: `module.link()` has been called, but at least one of its
612
- dependencies failed to link, either because the callback returned a `Promise`
613
- that is rejected, or because the `Module` the callback returned is invalid.
571
+ Corresponds to the [Link() concrete method][] field of [Source Text Module
572
+ Record][]s in the ECMAScript specification.
614
573
615
574
### module.namespace
616
575
617
576
* {Object }
618
577
619
- The namespace object of the module . This is only available after instantiation
620
- (` module.instantiate ()` ) has completed.
578
+ The namespace object of the module . This is only available after linking
579
+ (` module.link ()` ) has completed.
621
580
622
581
Corresponds to the [GetModuleNamespace][] abstract operation in the ECMAScript
623
582
specification.
@@ -628,21 +587,13 @@ specification.
628
587
629
588
The current status of the module . Will be one of:
630
589
631
- * ` 'uninstantiated'` : The module is not instantiated . It may because of any of
632
- the following reasons:
633
-
634
- * The module was just created.
635
- * ` module.instantiate()` has been called on this module , but it failed for
636
- some reason.
637
-
638
- This status does not convey any information regarding if ` module.link()` has
639
- been called . See ` module.linkingStatus` for that.
590
+ * ` 'unlinked'` : ` module.link()` has not yet been called.
640
591
641
- * ` 'instantiating '` : The module is currently being instantiated through a
642
- ` module.instantiate() ` call on itself or a parent module .
592
+ * ` 'linking '` : ` module.link() ` has been called, but not all Promises returned
593
+ by the linker function have been resolved yet .
643
594
644
- * ` 'instantiated '` : The module has been instantiated successfully, but
645
- ` module.evaluate()` has not yet been called.
595
+ * `'linked '`: The module has been linked successfully, and all of its
596
+ dependencies are linked, but `module.evaluate ()` has not yet been called.
646
597
647
598
* `'evaluating'`: The module is being evaluated through a `module.evaluate()` on
648
599
itself or a parent module.
@@ -656,11 +607,11 @@ Other than `'errored'`, this status string corresponds to the specification's
656
607
`'evaluated'` in the specification, but with `[[EvaluationError]]` set to a
657
608
value that is not `undefined`.
658
609
659
- ### module .url
610
+ ### module.identifier
660
611
661
612
* {string}
662
613
663
- The URL of the current module , as set in the constructor .
614
+ The identifier of the current module , as set in the constructor .
664
615
665
616
## vm.compileFunction (code [, params [, options ]])
666
617
<!-- YAML
@@ -1127,11 +1078,11 @@ queues.
1127
1078
[` vm.runInContext()` ]: #vm_vm_runincontext_code_contextifiedsandbox_options
1128
1079
[` vm.runInThisContext()` ]: #vm_vm_runinthiscontext_code_options
1129
1080
[ECMAScript Module Loader]: esm .html #esm_ecmascript_modules
1130
- [Evaluate () concrete method]: https: // tc39.github.io /ecma262/#sec-moduleevaluation
1131
- [GetModuleNamespace]: https: // tc39.github.io /ecma262/#sec-getmodulenamespace
1132
- [HostResolveImportedModule]: https: // tc39.github.io /ecma262/#sec-hostresolveimportedmodule
1133
- [Instantiate () concrete method]: https: // tc39.github.io /ecma262/#sec-moduledeclarationinstantiation
1134
- [Source Text Module Record]: https: // tc39.github.io /ecma262/#sec-source-text-module-records
1081
+ [Evaluate () concrete method]: https: // tc39.es /ecma262/#sec-moduleevaluation
1082
+ [GetModuleNamespace]: https: // tc39.es /ecma262/#sec-getmodulenamespace
1083
+ [HostResolveImportedModule]: https: // tc39.es /ecma262/#sec-hostresolveimportedmodule
1084
+ [Link () concrete method]: https: // tc39.es /ecma262/#sec-moduledeclarationlinking
1085
+ [Source Text Module Record]: https: // tc39.es /ecma262/#sec-source-text-module-records
1135
1086
[V8 Embedder' s Guide]: https://v8.dev/docs/embed#contexts
1136
1087
[contextified]: #vm_what_does_it_mean_to_contextify_an_object
1137
1088
[global object]: https://es5.github.io/#x15.1
0 commit comments