@@ -43,7 +43,7 @@ console.log(x); // 1; y is not defined.
43
43
** The vm module is not a security mechanism. Do not use it to run untrusted
44
44
code** .
45
45
46
- ## Class: vm.Module
46
+ ## Class: vm.SourceTextModule
47
47
<!-- YAML
48
48
added: v9.6.0
49
49
-->
@@ -53,20 +53,20 @@ added: v9.6.0
53
53
* This feature is only available with the ` --experimental-vm-modules ` command
54
54
flag enabled.*
55
55
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.
60
60
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.
66
66
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.
70
70
71
71
This implementation lies at a lower level than the [ ECMAScript Module
72
72
loader] [ ] . There is also currently no way to interact with the Loader, though
@@ -80,15 +80,15 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
80
80
(async () => {
81
81
// Step 1
82
82
//
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.
87
87
//
88
88
// Here, we attempt to obtain the default export from the module "foo", and
89
89
// put it into local binding "secret".
90
90
91
- const bar = new vm.Module (`
91
+ const bar = new vm.SourceTextModule (`
92
92
import s from 'foo';
93
93
s;
94
94
` , { context: contextifiedSandbox });
@@ -118,7 +118,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
118
118
119
119
async function linker (specifier , referencingModule ) {
120
120
if (specifier === ' foo' ) {
121
- return new vm.Module (`
121
+ return new vm.SourceTextModule (`
122
122
// The "secret" variable refers to the global variable we added to
123
123
// "contextifiedSandbox" when creating the context.
124
124
export default secret;
@@ -155,7 +155,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
155
155
})();
156
156
```
157
157
158
- ### Constructor: new vm.Module (code[ , options] )
158
+ ### Constructor: new vm.SourceTextModule (code[ , options] )
159
159
160
160
* ` code ` {string} JavaScript Module code to parse
161
161
* ` options `
@@ -170,7 +170,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
170
170
* ` initalizeImportMeta ` {Function} Called during evaluation of this ` Module `
171
171
to initialize the ` import.meta ` . This function has the signature `(meta,
172
172
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.
174
174
175
175
Creates a new ES ` Module ` object.
176
176
@@ -185,7 +185,7 @@ const vm = require('vm');
185
185
const contextifiedSandbox = vm .createContext ({ secret: 42 });
186
186
187
187
(async () => {
188
- const module = new vm.Module (
188
+ const module = new vm.SourceTextModule (
189
189
' Object.getPrototypeOf(import.meta.prop).secret = secret;' ,
190
190
{
191
191
initializeImportMeta (meta ) {
0 commit comments