@@ -43,7 +43,7 @@ console.log(x); // 1; y is not defined.
4343** The vm module is not a security mechanism. Do not use it to run untrusted
4444code** .
4545
46- ## Class: vm.Module
46+ ## Class: vm.SourceTextModule
4747<!-- YAML
4848added: v9.6.0
4949-->
@@ -53,20 +53,20 @@ added: v9.6.0
5353* This feature is only available with the ` --experimental-vm-modules ` command
5454flag enabled.*
5555
56- The ` vm.Module ` class provides a low-level interface for using ECMAScript
57- modules in VM contexts. It is the counterpart of the ` vm.Script ` class that
58- closely mirrors [ Source Text Module Record] [ ] s as defined in the ECMAScript
59- specification.
56+ The ` vm.SourceTextModule ` class provides a low-level interface for using
57+ ECMAScript modules in VM contexts. It is the counterpart of the ` vm.Script `
58+ class that closely mirrors [ Source Text Module Record] [ ] s as defined in the
59+ ECMAScript specification.
6060
61- Unlike ` vm.Script ` however, every ` vm.Module ` object is bound to a context from
62- its creation. Operations on ` vm.Module ` objects are intrinsically asynchronous,
63- in contrast with the synchronous nature of ` vm.Script ` objects. With the help
64- of async functions, however, manipulating ` vm.Module ` objects is fairly
65- straightforward.
61+ Unlike ` vm.Script ` however, every ` vm.SourceTextModule ` object is bound to a
62+ context from its creation. Operations on ` vm.SourceTextModule ` objects are
63+ intrinsically asynchronous, in contrast with the synchronous nature of
64+ ` vm.Script ` objects. With the help of async functions, however, manipulating
65+ ` vm.SourceTextModule ` objects is fairly straightforward.
6666
67- Using a ` vm.Module ` object requires four distinct steps: creation/parsing,
68- linking, instantiation, and evaluation. These four steps are illustrated in the
69- following example.
67+ Using a ` vm.SourceTextModule ` object requires four distinct steps:
68+ creation/parsing, linking, instantiation, and evaluation. These four steps are
69+ illustrated in the following example.
7070
7171This implementation lies at a lower level than the [ ECMAScript Module
7272loader] [ ] . There is also currently no way to interact with the Loader, though
@@ -80,15 +80,15 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
8080(async () => {
8181 // Step 1
8282 //
83- // Create a Module by constructing a new `vm.Module ` object. This parses the
84- // provided source text, throwing a `SyntaxError` if anything goes wrong. By
85- // default, a Module is created in the top context. But here, we specify
86- // `contextifiedSandbox` as the context this Module belongs to.
83+ // Create a Module by constructing a new `vm.SourceTextModule ` object. This
84+ // parses the provided source text, throwing a `SyntaxError` if anything goes
85+ // wrong. By default, a Module is created in the top context. But here, we
86+ // specify `contextifiedSandbox` as the context this Module belongs to.
8787 //
8888 // Here, we attempt to obtain the default export from the module "foo", and
8989 // put it into local binding "secret".
9090
91- const bar = new vm.Module (`
91+ const bar = new vm.SourceTextModule (`
9292 import s from 'foo';
9393 s;
9494 ` , { context: contextifiedSandbox });
@@ -118,7 +118,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
118118
119119 async function linker (specifier , referencingModule ) {
120120 if (specifier === ' foo' ) {
121- return new vm.Module (`
121+ return new vm.SourceTextModule (`
122122 // The "secret" variable refers to the global variable we added to
123123 // "contextifiedSandbox" when creating the context.
124124 export default secret;
@@ -155,7 +155,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
155155})();
156156```
157157
158- ### Constructor: new vm.Module (code[ , options] )
158+ ### Constructor: new vm.SourceTextModule (code[ , options] )
159159
160160* ` code ` {string} JavaScript Module code to parse
161161* ` options `
@@ -170,7 +170,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
170170 * ` initalizeImportMeta ` {Function} Called during evaluation of this ` Module `
171171 to initialize the ` import.meta ` . This function has the signature `(meta,
172172 module)` , where ` meta` is the ` import.meta` object in the ` Module`, and
173- ` module ` is this ` vm.Module ` object.
173+ ` module ` is this ` vm.SourceTextModule ` object.
174174
175175Creates a new ES ` Module ` object.
176176
@@ -185,7 +185,7 @@ const vm = require('vm');
185185const contextifiedSandbox = vm .createContext ({ secret: 42 });
186186
187187(async () => {
188- const module = new vm.Module (
188+ const module = new vm.SourceTextModule (
189189 ' Object.getPrototypeOf(import.meta.prop).secret = secret;' ,
190190 {
191191 initializeImportMeta (meta ) {
0 commit comments