@@ -322,9 +322,9 @@ intrinsically asynchronous, in contrast with the synchronous nature of
322322` vm.Script ` objects. With the help of async functions, however, manipulating
323323` vm.SourceTextModule ` objects is fairly straightforward.
324324
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.
328328
329329This implementation lies at a lower level than the [ ECMAScript Module
330330loader] [ ] . There is also currently no way to interact with the Loader, though
@@ -391,15 +391,6 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
391391
392392 // Step 3
393393 //
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- //
403394 // Evaluate the Module. The evaluate() method returns a Promise with a single
404395 // property "result" that contains the result of the very last statement
405396 // 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 });
417408
418409* ` code ` {string} JavaScript Module code to parse
419410* ` 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.
422414 * ` context ` {Object} The [ contextified] [ ] object as returned by the
423415 ` vm.createContext() ` method, to compile and evaluate this ` Module ` in.
424416 * ` lineOffset ` {integer} Specifies the line number offset that is displayed
@@ -465,7 +457,6 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
465457 });
466458 // Since module has no dependencies, the linker function will never be called.
467459 await module .link (() => {});
468- module .instantiate ();
469460 await module .evaluate ();
470461
471462 // Now, Object.prototype.secret will be equal to 42.
@@ -516,7 +507,7 @@ in the ECMAScript specification.
516507
517508Evaluate the module.
518509
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
520511throw an error. It could be called also when the module has already been
521512evaluated, in which case it will do one of the following two things:
522513
@@ -531,23 +522,6 @@ This method cannot be called while the module is being evaluated
531522Corresponds to the [ Evaluate() concrete method] [ ] field of [ Source Text Module
532523Record] [ ] s in the ECMAScript specification.
533524
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-
551525### module.link(linker)
552526
553527* ` linker ` {Function}
@@ -563,17 +537,17 @@ Module Record][]s in the ECMAScript specification.
563537 * Returns: {vm .SourceTextModule | Promise }
564538* Returns: {Promise }
565539
566- Link module dependencies . This method must be called before instantiation , and
540+ Link module dependencies . This method must be called before evaluation , and
567541can only be called once per module .
568542
569543The function is expected to return a `Module` object or a `Promise` that
570544eventually resolves to a `Module` object. The returned `Module` must satisfy the
571545following two invariants:
572546
573547* 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'`.
575549
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
577551recursively called on the returned `Module` with the same provided `linker`
578552function .
579553
@@ -587,37 +561,22 @@ specification, with a few key differences:
587561
588562* The linker function is allowed to be asynchronous while
589563 [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.
593564
594565The 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
596567that point all modules would have been fully linked already, the
597568[HostResolveImportedModule][] implementation is fully synchronous per
598569specification.
599570
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.
614573
615574### module.namespace
616575
617576* {Object }
618577
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.
621580
622581Corresponds to the [GetModuleNamespace][] abstract operation in the ECMAScript
623582specification.
@@ -628,21 +587,13 @@ specification.
628587
629588The current status of the module . Will be one of:
630589
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.
640591
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 .
643594
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.
646597
647598* `'evaluating'`: The module is being evaluated through a `module.evaluate()` on
648599 itself or a parent module.
@@ -656,11 +607,11 @@ Other than `'errored'`, this status string corresponds to the specification's
656607`'evaluated'` in the specification, but with `[[EvaluationError]]` set to a
657608value that is not `undefined`.
658609
659- ### module .url
610+ ### module.identifier
660611
661612* {string}
662613
663- The URL of the current module , as set in the constructor .
614+ The identifier of the current module , as set in the constructor .
664615
665616## vm.compileFunction (code [, params [, options ]])
666617<!-- YAML
@@ -1127,11 +1078,11 @@ queues.
11271078[` vm.runInContext()` ]: #vm_vm_runincontext_code_contextifiedsandbox_options
11281079[` vm.runInThisContext()` ]: #vm_vm_runinthiscontext_code_options
11291080[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
11351086[V8 Embedder' s Guide]: https://v8.dev/docs/embed#contexts
11361087[contextified]: #vm_what_does_it_mean_to_contextify_an_object
11371088[global object]: https://es5.github.io/#x15.1
0 commit comments