m06_task3.js 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.idea/.name +1 -0
- package/.idea/inspectionProfiles/Project_Default.xml +10 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/node_lab_6.iml +12 -0
- package/06_task2.html +73 -0
- package/06_task2.js +52 -0
- package/06_task3.js +3 -0
- package/06_task4.js +3 -0
- package/m06_task3.js +28 -0
- package/package/index.js +28 -0
- package/package/node_modules/.package-lock.json +31 -0
- package/package/node_modules/@types/node/LICENSE +21 -0
- package/package/node_modules/@types/node/README.md +16 -0
- package/package/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/package/node_modules/@types/node/assert.d.ts +961 -0
- package/package/node_modules/@types/node/async_hooks.d.ts +501 -0
- package/package/node_modules/@types/node/buffer.d.ts +2258 -0
- package/package/node_modules/@types/node/child_process.d.ts +1369 -0
- package/package/node_modules/@types/node/cluster.d.ts +410 -0
- package/package/node_modules/@types/node/console.d.ts +412 -0
- package/package/node_modules/@types/node/constants.d.ts +18 -0
- package/package/node_modules/@types/node/crypto.d.ts +3964 -0
- package/package/node_modules/@types/node/dgram.d.ts +545 -0
- package/package/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
- package/package/node_modules/@types/node/dns/promises.d.ts +370 -0
- package/package/node_modules/@types/node/dns.d.ts +659 -0
- package/package/node_modules/@types/node/dom-events.d.ts +126 -0
- package/package/node_modules/@types/node/domain.d.ts +170 -0
- package/package/node_modules/@types/node/events.d.ts +678 -0
- package/package/node_modules/@types/node/fs/promises.d.ts +1138 -0
- package/package/node_modules/@types/node/fs.d.ts +3872 -0
- package/package/node_modules/@types/node/globals.d.ts +300 -0
- package/package/node_modules/@types/node/globals.global.d.ts +1 -0
- package/package/node_modules/@types/node/http.d.ts +1614 -0
- package/package/node_modules/@types/node/http2.d.ts +2134 -0
- package/package/node_modules/@types/node/https.d.ts +541 -0
- package/package/node_modules/@types/node/index.d.ts +133 -0
- package/package/node_modules/@types/node/inspector.d.ts +2741 -0
- package/package/node_modules/@types/node/module.d.ts +114 -0
- package/package/node_modules/@types/node/net.d.ts +869 -0
- package/package/node_modules/@types/node/os.d.ts +466 -0
- package/package/node_modules/@types/node/package.json +232 -0
- package/package/node_modules/@types/node/path.d.ts +191 -0
- package/package/node_modules/@types/node/perf_hooks.d.ts +625 -0
- package/package/node_modules/@types/node/process.d.ts +1482 -0
- package/package/node_modules/@types/node/punycode.d.ts +117 -0
- package/package/node_modules/@types/node/querystring.d.ts +131 -0
- package/package/node_modules/@types/node/readline/promises.d.ts +143 -0
- package/package/node_modules/@types/node/readline.d.ts +653 -0
- package/package/node_modules/@types/node/repl.d.ts +424 -0
- package/package/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/package/node_modules/@types/node/stream/promises.d.ts +42 -0
- package/package/node_modules/@types/node/stream/web.d.ts +330 -0
- package/package/node_modules/@types/node/stream.d.ts +1340 -0
- package/package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/package/node_modules/@types/node/test.d.ts +314 -0
- package/package/node_modules/@types/node/timers/promises.d.ts +68 -0
- package/package/node_modules/@types/node/timers.d.ts +94 -0
- package/package/node_modules/@types/node/tls.d.ts +1028 -0
- package/package/node_modules/@types/node/trace_events.d.ts +171 -0
- package/package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/package/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
- package/package/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
- package/package/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
- package/package/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
- package/package/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
- package/package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/package/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/package/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
- package/package/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
- package/package/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
- package/package/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
- package/package/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/package/node_modules/@types/node/ts4.8/events.d.ts +678 -0
- package/package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
- package/package/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
- package/package/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
- package/package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/package/node_modules/@types/node/ts4.8/http.d.ts +1614 -0
- package/package/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
- package/package/node_modules/@types/node/ts4.8/https.d.ts +541 -0
- package/package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/package/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
- package/package/node_modules/@types/node/ts4.8/module.d.ts +114 -0
- package/package/node_modules/@types/node/ts4.8/net.d.ts +869 -0
- package/package/node_modules/@types/node/ts4.8/os.d.ts +466 -0
- package/package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
- package/package/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
- package/package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/package/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
- package/package/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
- package/package/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/package/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/package/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/package/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
- package/package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/package/node_modules/@types/node/ts4.8/test.d.ts +314 -0
- package/package/node_modules/@types/node/ts4.8/timers/promises.d.ts +68 -0
- package/package/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
- package/package/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
- package/package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
- package/package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
- package/package/node_modules/@types/node/ts4.8/url.d.ts +897 -0
- package/package/node_modules/@types/node/ts4.8/util.d.ts +1850 -0
- package/package/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
- package/package/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
- package/package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
- package/package/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
- package/package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/package/node_modules/@types/node/tty.d.ts +206 -0
- package/package/node_modules/@types/node/url.d.ts +897 -0
- package/package/node_modules/@types/node/util.d.ts +1850 -0
- package/package/node_modules/@types/node/v8.d.ts +396 -0
- package/package/node_modules/@types/node/vm.d.ts +509 -0
- package/package/node_modules/@types/node/wasi.d.ts +158 -0
- package/package/node_modules/@types/node/worker_threads.d.ts +689 -0
- package/package/node_modules/@types/node/zlib.d.ts +517 -0
- package/package/node_modules/@types/nodemailer/LICENSE +21 -0
- package/package/node_modules/@types/nodemailer/README.md +16 -0
- package/package/node_modules/@types/nodemailer/index.d.ts +83 -0
- package/package/node_modules/@types/nodemailer/lib/addressparser/index.d.ts +31 -0
- package/package/node_modules/@types/nodemailer/lib/base64/index.d.ts +22 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/index.d.ts +45 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/message-parser.d.ts +75 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/relaxed-body.d.ts +75 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/sign.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/fetch/cookies.d.ts +54 -0
- package/package/node_modules/@types/nodemailer/lib/fetch/index.d.ts +38 -0
- package/package/node_modules/@types/nodemailer/lib/json-transport/index.d.ts +50 -0
- package/package/node_modules/@types/nodemailer/lib/mail-composer/index.d.ts +25 -0
- package/package/node_modules/@types/nodemailer/lib/mailer/index.d.ts +230 -0
- package/package/node_modules/@types/nodemailer/lib/mailer/mail-message.d.ts +28 -0
- package/package/node_modules/@types/nodemailer/lib/mime-funcs/index.d.ts +87 -0
- package/package/node_modules/@types/nodemailer/lib/mime-funcs/mime-types.d.ts +2 -0
- package/package/node_modules/@types/nodemailer/lib/mime-node/index.d.ts +137 -0
- package/package/node_modules/@types/nodemailer/lib/mime-node/last-newline.d.ts +9 -0
- package/package/node_modules/@types/nodemailer/lib/qp/index.d.ts +23 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/index.d.ts +53 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-unix.d.ts +7 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-windows.d.ts +7 -0
- package/package/node_modules/@types/nodemailer/lib/ses-transport/index.d.ts +136 -0
- package/package/node_modules/@types/nodemailer/lib/shared/index.d.ts +51 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/data-stream.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/http-proxy-client.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/index.d.ts +254 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-pool/index.d.ts +90 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-pool/pool-resource.d.ts +66 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-transport/index.d.ts +115 -0
- package/package/node_modules/@types/nodemailer/lib/stream-transport/index.d.ts +56 -0
- package/package/node_modules/@types/nodemailer/lib/well-known/index.d.ts +6 -0
- package/package/node_modules/@types/nodemailer/lib/xoauth2/index.d.ts +110 -0
- package/package/node_modules/@types/nodemailer/package.json +37 -0
- package/package/node_modules/nodemailer/.gitattributes +6 -0
- package/package/node_modules/nodemailer/.prettierrc.js +8 -0
- package/package/node_modules/nodemailer/CHANGELOG.md +715 -0
- package/package/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
- package/package/node_modules/nodemailer/CONTRIBUTING.md +67 -0
- package/package/node_modules/nodemailer/LICENSE +16 -0
- package/package/node_modules/nodemailer/README.md +93 -0
- package/package/node_modules/nodemailer/SECURITY.txt +22 -0
- package/package/node_modules/nodemailer/lib/addressparser/index.js +313 -0
- package/package/node_modules/nodemailer/lib/base64/index.js +142 -0
- package/package/node_modules/nodemailer/lib/dkim/index.js +251 -0
- package/package/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
- package/package/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
- package/package/node_modules/nodemailer/lib/dkim/sign.js +117 -0
- package/package/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
- package/package/node_modules/nodemailer/lib/fetch/index.js +269 -0
- package/package/node_modules/nodemailer/lib/json-transport/index.js +82 -0
- package/package/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
- package/package/node_modules/nodemailer/lib/mailer/index.js +427 -0
- package/package/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
- package/package/node_modules/nodemailer/lib/mime-funcs/index.js +619 -0
- package/package/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
- package/package/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
- package/package/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
- package/package/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
- package/package/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
- package/package/node_modules/nodemailer/lib/nodemailer.js +143 -0
- package/package/node_modules/nodemailer/lib/qp/index.js +219 -0
- package/package/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
- package/package/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
- package/package/node_modules/nodemailer/lib/shared/index.js +639 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/index.js +1786 -0
- package/package/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
- package/package/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
- package/package/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
- package/package/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
- package/package/node_modules/nodemailer/lib/well-known/index.js +47 -0
- package/package/node_modules/nodemailer/lib/well-known/services.json +286 -0
- package/package/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
- package/package/node_modules/nodemailer/package.json +46 -0
- package/package/node_modules/nodemailer/postinstall.js +101 -0
- package/package/package-lock.json +60 -0
- package/package/package.json +6 -0
- package/package.json +19 -0
@@ -0,0 +1,509 @@
|
|
1
|
+
/**
|
2
|
+
* The `vm` module enables compiling and running code within V8 Virtual
|
3
|
+
* Machine contexts.
|
4
|
+
*
|
5
|
+
* **The `vm` module is not a security**
|
6
|
+
* **mechanism. Do not use it to run untrusted code.**
|
7
|
+
*
|
8
|
+
* JavaScript code can be compiled and run immediately or
|
9
|
+
* compiled, saved, and run later.
|
10
|
+
*
|
11
|
+
* A common use case is to run the code in a different V8 Context. This means
|
12
|
+
* invoked code has a different global object than the invoking code.
|
13
|
+
*
|
14
|
+
* One can provide the context by `contextifying` an
|
15
|
+
* object. The invoked code treats any property in the context like a
|
16
|
+
* global variable. Any changes to global variables caused by the invoked
|
17
|
+
* code are reflected in the context object.
|
18
|
+
*
|
19
|
+
* ```js
|
20
|
+
* const vm = require('vm');
|
21
|
+
*
|
22
|
+
* const x = 1;
|
23
|
+
*
|
24
|
+
* const context = { x: 2 };
|
25
|
+
* vm.createContext(context); // Contextify the object.
|
26
|
+
*
|
27
|
+
* const code = 'x += 40; var y = 17;';
|
28
|
+
* // `x` and `y` are global variables in the context.
|
29
|
+
* // Initially, x has the value 2 because that is the value of context.x.
|
30
|
+
* vm.runInContext(code, context);
|
31
|
+
*
|
32
|
+
* console.log(context.x); // 42
|
33
|
+
* console.log(context.y); // 17
|
34
|
+
*
|
35
|
+
* console.log(x); // 1; y is not defined.
|
36
|
+
* ```
|
37
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/vm.js)
|
38
|
+
*/
|
39
|
+
declare module 'vm' {
|
40
|
+
interface Context extends NodeJS.Dict<any> {}
|
41
|
+
interface BaseOptions {
|
42
|
+
/**
|
43
|
+
* Specifies the filename used in stack traces produced by this script.
|
44
|
+
* Default: `''`.
|
45
|
+
*/
|
46
|
+
filename?: string | undefined;
|
47
|
+
/**
|
48
|
+
* Specifies the line number offset that is displayed in stack traces produced by this script.
|
49
|
+
* Default: `0`.
|
50
|
+
*/
|
51
|
+
lineOffset?: number | undefined;
|
52
|
+
/**
|
53
|
+
* Specifies the column number offset that is displayed in stack traces produced by this script.
|
54
|
+
* @default 0
|
55
|
+
*/
|
56
|
+
columnOffset?: number | undefined;
|
57
|
+
}
|
58
|
+
interface ScriptOptions extends BaseOptions {
|
59
|
+
displayErrors?: boolean | undefined;
|
60
|
+
timeout?: number | undefined;
|
61
|
+
cachedData?: Buffer | undefined;
|
62
|
+
/** @deprecated in favor of `script.createCachedData()` */
|
63
|
+
produceCachedData?: boolean | undefined;
|
64
|
+
}
|
65
|
+
interface RunningScriptOptions extends BaseOptions {
|
66
|
+
/**
|
67
|
+
* When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
|
68
|
+
* Default: `true`.
|
69
|
+
*/
|
70
|
+
displayErrors?: boolean | undefined;
|
71
|
+
/**
|
72
|
+
* Specifies the number of milliseconds to execute code before terminating execution.
|
73
|
+
* If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
|
74
|
+
*/
|
75
|
+
timeout?: number | undefined;
|
76
|
+
/**
|
77
|
+
* If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
|
78
|
+
* Existing handlers for the event that have been attached via `process.on('SIGINT')` will be disabled during script execution, but will continue to work after that.
|
79
|
+
* If execution is terminated, an `Error` will be thrown.
|
80
|
+
* Default: `false`.
|
81
|
+
*/
|
82
|
+
breakOnSigint?: boolean | undefined;
|
83
|
+
/**
|
84
|
+
* If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
|
85
|
+
*/
|
86
|
+
microtaskMode?: 'afterEvaluate' | undefined;
|
87
|
+
}
|
88
|
+
interface CompileFunctionOptions extends BaseOptions {
|
89
|
+
/**
|
90
|
+
* Provides an optional data with V8's code cache data for the supplied source.
|
91
|
+
*/
|
92
|
+
cachedData?: Buffer | undefined;
|
93
|
+
/**
|
94
|
+
* Specifies whether to produce new cache data.
|
95
|
+
* Default: `false`,
|
96
|
+
*/
|
97
|
+
produceCachedData?: boolean | undefined;
|
98
|
+
/**
|
99
|
+
* The sandbox/context in which the said function should be compiled in.
|
100
|
+
*/
|
101
|
+
parsingContext?: Context | undefined;
|
102
|
+
/**
|
103
|
+
* An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
|
104
|
+
*/
|
105
|
+
contextExtensions?: Object[] | undefined;
|
106
|
+
}
|
107
|
+
interface CreateContextOptions {
|
108
|
+
/**
|
109
|
+
* Human-readable name of the newly created context.
|
110
|
+
* @default 'VM Context i' Where i is an ascending numerical index of the created context.
|
111
|
+
*/
|
112
|
+
name?: string | undefined;
|
113
|
+
/**
|
114
|
+
* Corresponds to the newly created context for display purposes.
|
115
|
+
* The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
|
116
|
+
* like the value of the `url.origin` property of a URL object.
|
117
|
+
* Most notably, this string should omit the trailing slash, as that denotes a path.
|
118
|
+
* @default ''
|
119
|
+
*/
|
120
|
+
origin?: string | undefined;
|
121
|
+
codeGeneration?:
|
122
|
+
| {
|
123
|
+
/**
|
124
|
+
* If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
|
125
|
+
* will throw an EvalError.
|
126
|
+
* @default true
|
127
|
+
*/
|
128
|
+
strings?: boolean | undefined;
|
129
|
+
/**
|
130
|
+
* If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
|
131
|
+
* @default true
|
132
|
+
*/
|
133
|
+
wasm?: boolean | undefined;
|
134
|
+
}
|
135
|
+
| undefined;
|
136
|
+
/**
|
137
|
+
* If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
|
138
|
+
*/
|
139
|
+
microtaskMode?: 'afterEvaluate' | undefined;
|
140
|
+
}
|
141
|
+
type MeasureMemoryMode = 'summary' | 'detailed';
|
142
|
+
interface MeasureMemoryOptions {
|
143
|
+
/**
|
144
|
+
* @default 'summary'
|
145
|
+
*/
|
146
|
+
mode?: MeasureMemoryMode | undefined;
|
147
|
+
context?: Context | undefined;
|
148
|
+
}
|
149
|
+
interface MemoryMeasurement {
|
150
|
+
total: {
|
151
|
+
jsMemoryEstimate: number;
|
152
|
+
jsMemoryRange: [number, number];
|
153
|
+
};
|
154
|
+
}
|
155
|
+
/**
|
156
|
+
* Instances of the `vm.Script` class contain precompiled scripts that can be
|
157
|
+
* executed in specific contexts.
|
158
|
+
* @since v0.3.1
|
159
|
+
*/
|
160
|
+
class Script {
|
161
|
+
constructor(code: string, options?: ScriptOptions);
|
162
|
+
/**
|
163
|
+
* Runs the compiled code contained by the `vm.Script` object within the given`contextifiedObject` and returns the result. Running code does not have access
|
164
|
+
* to local scope.
|
165
|
+
*
|
166
|
+
* The following example compiles code that increments a global variable, sets
|
167
|
+
* the value of another global variable, then execute the code multiple times.
|
168
|
+
* The globals are contained in the `context` object.
|
169
|
+
*
|
170
|
+
* ```js
|
171
|
+
* const vm = require('vm');
|
172
|
+
*
|
173
|
+
* const context = {
|
174
|
+
* animal: 'cat',
|
175
|
+
* count: 2
|
176
|
+
* };
|
177
|
+
*
|
178
|
+
* const script = new vm.Script('count += 1; name = "kitty";');
|
179
|
+
*
|
180
|
+
* vm.createContext(context);
|
181
|
+
* for (let i = 0; i < 10; ++i) {
|
182
|
+
* script.runInContext(context);
|
183
|
+
* }
|
184
|
+
*
|
185
|
+
* console.log(context);
|
186
|
+
* // Prints: { animal: 'cat', count: 12, name: 'kitty' }
|
187
|
+
* ```
|
188
|
+
*
|
189
|
+
* Using the `timeout` or `breakOnSigint` options will result in new event loops
|
190
|
+
* and corresponding threads being started, which have a non-zero performance
|
191
|
+
* overhead.
|
192
|
+
* @since v0.3.1
|
193
|
+
* @param contextifiedObject A `contextified` object as returned by the `vm.createContext()` method.
|
194
|
+
* @return the result of the very last statement executed in the script.
|
195
|
+
*/
|
196
|
+
runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
|
197
|
+
/**
|
198
|
+
* First contextifies the given `contextObject`, runs the compiled code contained
|
199
|
+
* by the `vm.Script` object within the created context, and returns the result.
|
200
|
+
* Running code does not have access to local scope.
|
201
|
+
*
|
202
|
+
* The following example compiles code that sets a global variable, then executes
|
203
|
+
* the code multiple times in different contexts. The globals are set on and
|
204
|
+
* contained within each individual `context`.
|
205
|
+
*
|
206
|
+
* ```js
|
207
|
+
* const vm = require('vm');
|
208
|
+
*
|
209
|
+
* const script = new vm.Script('globalVar = "set"');
|
210
|
+
*
|
211
|
+
* const contexts = [{}, {}, {}];
|
212
|
+
* contexts.forEach((context) => {
|
213
|
+
* script.runInNewContext(context);
|
214
|
+
* });
|
215
|
+
*
|
216
|
+
* console.log(contexts);
|
217
|
+
* // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
|
218
|
+
* ```
|
219
|
+
* @since v0.3.1
|
220
|
+
* @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
|
221
|
+
* @return the result of the very last statement executed in the script.
|
222
|
+
*/
|
223
|
+
runInNewContext(contextObject?: Context, options?: RunningScriptOptions): any;
|
224
|
+
/**
|
225
|
+
* Runs the compiled code contained by the `vm.Script` within the context of the
|
226
|
+
* current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
|
227
|
+
*
|
228
|
+
* The following example compiles code that increments a `global` variable then
|
229
|
+
* executes that code multiple times:
|
230
|
+
*
|
231
|
+
* ```js
|
232
|
+
* const vm = require('vm');
|
233
|
+
*
|
234
|
+
* global.globalVar = 0;
|
235
|
+
*
|
236
|
+
* const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });
|
237
|
+
*
|
238
|
+
* for (let i = 0; i < 1000; ++i) {
|
239
|
+
* script.runInThisContext();
|
240
|
+
* }
|
241
|
+
*
|
242
|
+
* console.log(globalVar);
|
243
|
+
*
|
244
|
+
* // 1000
|
245
|
+
* ```
|
246
|
+
* @since v0.3.1
|
247
|
+
* @return the result of the very last statement executed in the script.
|
248
|
+
*/
|
249
|
+
runInThisContext(options?: RunningScriptOptions): any;
|
250
|
+
/**
|
251
|
+
* Creates a code cache that can be used with the `Script` constructor's`cachedData` option. Returns a `Buffer`. This method may be called at any
|
252
|
+
* time and any number of times.
|
253
|
+
*
|
254
|
+
* ```js
|
255
|
+
* const script = new vm.Script(`
|
256
|
+
* function add(a, b) {
|
257
|
+
* return a + b;
|
258
|
+
* }
|
259
|
+
*
|
260
|
+
* const x = add(1, 2);
|
261
|
+
* `);
|
262
|
+
*
|
263
|
+
* const cacheWithoutX = script.createCachedData();
|
264
|
+
*
|
265
|
+
* script.runInThisContext();
|
266
|
+
*
|
267
|
+
* const cacheWithX = script.createCachedData();
|
268
|
+
* ```
|
269
|
+
* @since v10.6.0
|
270
|
+
*/
|
271
|
+
createCachedData(): Buffer;
|
272
|
+
/** @deprecated in favor of `script.createCachedData()` */
|
273
|
+
cachedDataProduced?: boolean | undefined;
|
274
|
+
cachedDataRejected?: boolean | undefined;
|
275
|
+
cachedData?: Buffer | undefined;
|
276
|
+
}
|
277
|
+
/**
|
278
|
+
* If given a `contextObject`, the `vm.createContext()` method will `prepare
|
279
|
+
* that object` so that it can be used in calls to {@link runInContext} or `script.runInContext()`. Inside such scripts,
|
280
|
+
* the `contextObject` will be the global object, retaining all of its existing
|
281
|
+
* properties but also having the built-in objects and functions any standard [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global variables
|
282
|
+
* will remain unchanged.
|
283
|
+
*
|
284
|
+
* ```js
|
285
|
+
* const vm = require('vm');
|
286
|
+
*
|
287
|
+
* global.globalVar = 3;
|
288
|
+
*
|
289
|
+
* const context = { globalVar: 1 };
|
290
|
+
* vm.createContext(context);
|
291
|
+
*
|
292
|
+
* vm.runInContext('globalVar *= 2;', context);
|
293
|
+
*
|
294
|
+
* console.log(context);
|
295
|
+
* // Prints: { globalVar: 2 }
|
296
|
+
*
|
297
|
+
* console.log(global.globalVar);
|
298
|
+
* // Prints: 3
|
299
|
+
* ```
|
300
|
+
*
|
301
|
+
* If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
|
302
|
+
* empty `contextified` object will be returned.
|
303
|
+
*
|
304
|
+
* The `vm.createContext()` method is primarily useful for creating a single
|
305
|
+
* context that can be used to run multiple scripts. For instance, if emulating a
|
306
|
+
* web browser, the method can be used to create a single context representing a
|
307
|
+
* window's global object, then run all `<script>` tags together within that
|
308
|
+
* context.
|
309
|
+
*
|
310
|
+
* The provided `name` and `origin` of the context are made visible through the
|
311
|
+
* Inspector API.
|
312
|
+
* @since v0.3.1
|
313
|
+
* @return contextified object.
|
314
|
+
*/
|
315
|
+
function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
|
316
|
+
/**
|
317
|
+
* Returns `true` if the given `object` object has been `contextified` using {@link createContext}.
|
318
|
+
* @since v0.11.7
|
319
|
+
*/
|
320
|
+
function isContext(sandbox: Context): boolean;
|
321
|
+
/**
|
322
|
+
* The `vm.runInContext()` method compiles `code`, runs it within the context of
|
323
|
+
* the `contextifiedObject`, then returns the result. Running code does not have
|
324
|
+
* access to the local scope. The `contextifiedObject` object _must_ have been
|
325
|
+
* previously `contextified` using the {@link createContext} method.
|
326
|
+
*
|
327
|
+
* If `options` is a string, then it specifies the filename.
|
328
|
+
*
|
329
|
+
* The following example compiles and executes different scripts using a single `contextified` object:
|
330
|
+
*
|
331
|
+
* ```js
|
332
|
+
* const vm = require('vm');
|
333
|
+
*
|
334
|
+
* const contextObject = { globalVar: 1 };
|
335
|
+
* vm.createContext(contextObject);
|
336
|
+
*
|
337
|
+
* for (let i = 0; i < 10; ++i) {
|
338
|
+
* vm.runInContext('globalVar *= 2;', contextObject);
|
339
|
+
* }
|
340
|
+
* console.log(contextObject);
|
341
|
+
* // Prints: { globalVar: 1024 }
|
342
|
+
* ```
|
343
|
+
* @since v0.3.1
|
344
|
+
* @param code The JavaScript code to compile and run.
|
345
|
+
* @param contextifiedObject The `contextified` object that will be used as the `global` when the `code` is compiled and run.
|
346
|
+
* @return the result of the very last statement executed in the script.
|
347
|
+
*/
|
348
|
+
function runInContext(code: string, contextifiedObject: Context, options?: RunningScriptOptions | string): any;
|
349
|
+
/**
|
350
|
+
* The `vm.runInNewContext()` first contextifies the given `contextObject` (or
|
351
|
+
* creates a new `contextObject` if passed as `undefined`), compiles the `code`,
|
352
|
+
* runs it within the created context, then returns the result. Running code
|
353
|
+
* does not have access to the local scope.
|
354
|
+
*
|
355
|
+
* If `options` is a string, then it specifies the filename.
|
356
|
+
*
|
357
|
+
* The following example compiles and executes code that increments a global
|
358
|
+
* variable and sets a new one. These globals are contained in the `contextObject`.
|
359
|
+
*
|
360
|
+
* ```js
|
361
|
+
* const vm = require('vm');
|
362
|
+
*
|
363
|
+
* const contextObject = {
|
364
|
+
* animal: 'cat',
|
365
|
+
* count: 2
|
366
|
+
* };
|
367
|
+
*
|
368
|
+
* vm.runInNewContext('count += 1; name = "kitty"', contextObject);
|
369
|
+
* console.log(contextObject);
|
370
|
+
* // Prints: { animal: 'cat', count: 3, name: 'kitty' }
|
371
|
+
* ```
|
372
|
+
* @since v0.3.1
|
373
|
+
* @param code The JavaScript code to compile and run.
|
374
|
+
* @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
|
375
|
+
* @return the result of the very last statement executed in the script.
|
376
|
+
*/
|
377
|
+
function runInNewContext(code: string, contextObject?: Context, options?: RunningScriptOptions | string): any;
|
378
|
+
/**
|
379
|
+
* `vm.runInThisContext()` compiles `code`, runs it within the context of the
|
380
|
+
* current `global` and returns the result. Running code does not have access to
|
381
|
+
* local scope, but does have access to the current `global` object.
|
382
|
+
*
|
383
|
+
* If `options` is a string, then it specifies the filename.
|
384
|
+
*
|
385
|
+
* The following example illustrates using both `vm.runInThisContext()` and
|
386
|
+
* the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
|
387
|
+
*
|
388
|
+
* ```js
|
389
|
+
* const vm = require('vm');
|
390
|
+
* let localVar = 'initial value';
|
391
|
+
*
|
392
|
+
* const vmResult = vm.runInThisContext('localVar = "vm";');
|
393
|
+
* console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
|
394
|
+
* // Prints: vmResult: 'vm', localVar: 'initial value'
|
395
|
+
*
|
396
|
+
* const evalResult = eval('localVar = "eval";');
|
397
|
+
* console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);
|
398
|
+
* // Prints: evalResult: 'eval', localVar: 'eval'
|
399
|
+
* ```
|
400
|
+
*
|
401
|
+
* Because `vm.runInThisContext()` does not have access to the local scope,`localVar` is unchanged. In contrast,
|
402
|
+
* [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
|
403
|
+
* local scope, so the value `localVar` is changed. In this way`vm.runInThisContext()` is much like an [indirect `eval()` call](https://es5.github.io/#x10.4.2), e.g.`(0,eval)('code')`.
|
404
|
+
*
|
405
|
+
* ## Example: Running an HTTP server within a VM
|
406
|
+
*
|
407
|
+
* When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
|
408
|
+
* context. The code passed to this VM context will have its own isolated scope.
|
409
|
+
*
|
410
|
+
* In order to run a simple web server using the `http` module the code passed to
|
411
|
+
* the context must either call `require('http')` on its own, or have a reference
|
412
|
+
* to the `http` module passed to it. For instance:
|
413
|
+
*
|
414
|
+
* ```js
|
415
|
+
* 'use strict';
|
416
|
+
* const vm = require('vm');
|
417
|
+
*
|
418
|
+
* const code = `
|
419
|
+
* ((require) => {
|
420
|
+
* const http = require('http');
|
421
|
+
*
|
422
|
+
* http.createServer((request, response) => {
|
423
|
+
* response.writeHead(200, { 'Content-Type': 'text/plain' });
|
424
|
+
* response.end('Hello World\\n');
|
425
|
+
* }).listen(8124);
|
426
|
+
*
|
427
|
+
* console.log('Server running at http://127.0.0.1:8124/');
|
428
|
+
* })`;
|
429
|
+
*
|
430
|
+
* vm.runInThisContext(code)(require);
|
431
|
+
* ```
|
432
|
+
*
|
433
|
+
* The `require()` in the above case shares the state with the context it is
|
434
|
+
* passed from. This may introduce risks when untrusted code is executed, e.g.
|
435
|
+
* altering objects in the context in unwanted ways.
|
436
|
+
* @since v0.3.1
|
437
|
+
* @param code The JavaScript code to compile and run.
|
438
|
+
* @return the result of the very last statement executed in the script.
|
439
|
+
*/
|
440
|
+
function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
|
441
|
+
/**
|
442
|
+
* Compiles the given code into the provided context (if no context is
|
443
|
+
* supplied, the current context is used), and returns it wrapped inside a
|
444
|
+
* function with the given `params`.
|
445
|
+
* @since v10.10.0
|
446
|
+
* @param code The body of the function to compile.
|
447
|
+
* @param params An array of strings containing all parameters for the function.
|
448
|
+
*/
|
449
|
+
function compileFunction(code: string, params?: ReadonlyArray<string>, options?: CompileFunctionOptions): Function;
|
450
|
+
/**
|
451
|
+
* Measure the memory known to V8 and used by all contexts known to the
|
452
|
+
* current V8 isolate, or the main context.
|
453
|
+
*
|
454
|
+
* The format of the object that the returned Promise may resolve with is
|
455
|
+
* specific to the V8 engine and may change from one version of V8 to the next.
|
456
|
+
*
|
457
|
+
* The returned result is different from the statistics returned by`v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
|
458
|
+
* memory reachable by each V8 specific contexts in the current instance of
|
459
|
+
* the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
|
460
|
+
* the memory occupied by each heap space in the current V8 instance.
|
461
|
+
*
|
462
|
+
* ```js
|
463
|
+
* const vm = require('vm');
|
464
|
+
* // Measure the memory used by the main context.
|
465
|
+
* vm.measureMemory({ mode: 'summary' })
|
466
|
+
* // This is the same as vm.measureMemory()
|
467
|
+
* .then((result) => {
|
468
|
+
* // The current format is:
|
469
|
+
* // {
|
470
|
+
* // total: {
|
471
|
+
* // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
|
472
|
+
* // }
|
473
|
+
* // }
|
474
|
+
* console.log(result);
|
475
|
+
* });
|
476
|
+
*
|
477
|
+
* const context = vm.createContext({ a: 1 });
|
478
|
+
* vm.measureMemory({ mode: 'detailed', execution: 'eager' })
|
479
|
+
* .then((result) => {
|
480
|
+
* // Reference the context here so that it won't be GC'ed
|
481
|
+
* // until the measurement is complete.
|
482
|
+
* console.log(context.a);
|
483
|
+
* // {
|
484
|
+
* // total: {
|
485
|
+
* // jsMemoryEstimate: 2574732,
|
486
|
+
* // jsMemoryRange: [ 2574732, 2904372 ]
|
487
|
+
* // },
|
488
|
+
* // current: {
|
489
|
+
* // jsMemoryEstimate: 2438996,
|
490
|
+
* // jsMemoryRange: [ 2438996, 2768636 ]
|
491
|
+
* // },
|
492
|
+
* // other: [
|
493
|
+
* // {
|
494
|
+
* // jsMemoryEstimate: 135736,
|
495
|
+
* // jsMemoryRange: [ 135736, 465376 ]
|
496
|
+
* // }
|
497
|
+
* // ]
|
498
|
+
* // }
|
499
|
+
* console.log(result);
|
500
|
+
* });
|
501
|
+
* ```
|
502
|
+
* @since v13.10.0
|
503
|
+
* @experimental
|
504
|
+
*/
|
505
|
+
function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
|
506
|
+
}
|
507
|
+
declare module 'node:vm' {
|
508
|
+
export * from 'vm';
|
509
|
+
}
|
@@ -0,0 +1,158 @@
|
|
1
|
+
/**
|
2
|
+
* The WASI API provides an implementation of the [WebAssembly System Interface](https://wasi.dev/) specification. WASI gives sandboxed WebAssembly applications access to the
|
3
|
+
* underlying operating system via a collection of POSIX-like functions.
|
4
|
+
*
|
5
|
+
* ```js
|
6
|
+
* import { readFile } from 'fs/promises';
|
7
|
+
* import { WASI } from 'wasi';
|
8
|
+
* import { argv, env } from 'process';
|
9
|
+
*
|
10
|
+
* const wasi = new WASI({
|
11
|
+
* args: argv,
|
12
|
+
* env,
|
13
|
+
* preopens: {
|
14
|
+
* '/sandbox': '/some/real/path/that/wasm/can/access'
|
15
|
+
* }
|
16
|
+
* });
|
17
|
+
*
|
18
|
+
* // Some WASI binaries require:
|
19
|
+
* // const importObject = { wasi_unstable: wasi.wasiImport };
|
20
|
+
* const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
|
21
|
+
*
|
22
|
+
* const wasm = await WebAssembly.compile(
|
23
|
+
* await readFile(new URL('./demo.wasm', import.meta.url))
|
24
|
+
* );
|
25
|
+
* const instance = await WebAssembly.instantiate(wasm, importObject);
|
26
|
+
*
|
27
|
+
* wasi.start(instance);
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* To run the above example, create a new WebAssembly text format file named`demo.wat`:
|
31
|
+
*
|
32
|
+
* ```text
|
33
|
+
* (module
|
34
|
+
* ;; Import the required fd_write WASI function which will write the given io vectors to stdout
|
35
|
+
* ;; The function signature for fd_write is:
|
36
|
+
* ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written
|
37
|
+
* (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
|
38
|
+
*
|
39
|
+
* (memory 1)
|
40
|
+
* (export "memory" (memory 0))
|
41
|
+
*
|
42
|
+
* ;; Write 'hello world\n' to memory at an offset of 8 bytes
|
43
|
+
* ;; Note the trailing newline which is required for the text to appear
|
44
|
+
* (data (i32.const 8) "hello world\n")
|
45
|
+
*
|
46
|
+
* (func $main (export "_start")
|
47
|
+
* ;; Creating a new io vector within linear memory
|
48
|
+
* (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string
|
49
|
+
* (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string
|
50
|
+
*
|
51
|
+
* (call $fd_write
|
52
|
+
* (i32.const 1) ;; file_descriptor - 1 for stdout
|
53
|
+
* (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0
|
54
|
+
* (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one.
|
55
|
+
* (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written
|
56
|
+
* )
|
57
|
+
* drop ;; Discard the number of bytes written from the top of the stack
|
58
|
+
* )
|
59
|
+
* )
|
60
|
+
* ```
|
61
|
+
*
|
62
|
+
* Use [wabt](https://github.com/WebAssembly/wabt) to compile `.wat` to `.wasm`
|
63
|
+
*
|
64
|
+
* ```console
|
65
|
+
* $ wat2wasm demo.wat
|
66
|
+
* ```
|
67
|
+
*
|
68
|
+
* The `--experimental-wasi-unstable-preview1` CLI argument is needed for this
|
69
|
+
* example to run.
|
70
|
+
* @experimental
|
71
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/wasi.js)
|
72
|
+
*/
|
73
|
+
declare module 'wasi' {
|
74
|
+
interface WASIOptions {
|
75
|
+
/**
|
76
|
+
* An array of strings that the WebAssembly application will
|
77
|
+
* see as command line arguments. The first argument is the virtual path to the
|
78
|
+
* WASI command itself.
|
79
|
+
*/
|
80
|
+
args?: string[] | undefined;
|
81
|
+
/**
|
82
|
+
* An object similar to `process.env` that the WebAssembly
|
83
|
+
* application will see as its environment.
|
84
|
+
*/
|
85
|
+
env?: object | undefined;
|
86
|
+
/**
|
87
|
+
* This object represents the WebAssembly application's
|
88
|
+
* sandbox directory structure. The string keys of `preopens` are treated as
|
89
|
+
* directories within the sandbox. The corresponding values in `preopens` are
|
90
|
+
* the real paths to those directories on the host machine.
|
91
|
+
*/
|
92
|
+
preopens?: NodeJS.Dict<string> | undefined;
|
93
|
+
/**
|
94
|
+
* By default, WASI applications terminate the Node.js
|
95
|
+
* process via the `__wasi_proc_exit()` function. Setting this option to `true`
|
96
|
+
* causes `wasi.start()` to return the exit code rather than terminate the
|
97
|
+
* process.
|
98
|
+
* @default false
|
99
|
+
*/
|
100
|
+
returnOnExit?: boolean | undefined;
|
101
|
+
/**
|
102
|
+
* The file descriptor used as standard input in the WebAssembly application.
|
103
|
+
* @default 0
|
104
|
+
*/
|
105
|
+
stdin?: number | undefined;
|
106
|
+
/**
|
107
|
+
* The file descriptor used as standard output in the WebAssembly application.
|
108
|
+
* @default 1
|
109
|
+
*/
|
110
|
+
stdout?: number | undefined;
|
111
|
+
/**
|
112
|
+
* The file descriptor used as standard error in the WebAssembly application.
|
113
|
+
* @default 2
|
114
|
+
*/
|
115
|
+
stderr?: number | undefined;
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* The `WASI` class provides the WASI system call API and additional convenience
|
119
|
+
* methods for working with WASI-based applications. Each `WASI` instance
|
120
|
+
* represents a distinct sandbox environment. For security purposes, each `WASI`instance must have its command-line arguments, environment variables, and
|
121
|
+
* sandbox directory structure configured explicitly.
|
122
|
+
* @since v13.3.0, v12.16.0
|
123
|
+
*/
|
124
|
+
class WASI {
|
125
|
+
constructor(options?: WASIOptions);
|
126
|
+
/**
|
127
|
+
* Attempt to begin execution of `instance` as a WASI command by invoking its`_start()` export. If `instance` does not contain a `_start()` export, or if`instance` contains an `_initialize()`
|
128
|
+
* export, then an exception is thrown.
|
129
|
+
*
|
130
|
+
* `start()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named`memory`. If
|
131
|
+
* `instance` does not have a `memory` export an exception is thrown.
|
132
|
+
*
|
133
|
+
* If `start()` is called more than once, an exception is thrown.
|
134
|
+
* @since v13.3.0, v12.16.0
|
135
|
+
*/
|
136
|
+
start(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
|
137
|
+
/**
|
138
|
+
* Attempt to initialize `instance` as a WASI reactor by invoking its`_initialize()` export, if it is present. If `instance` contains a `_start()`export, then an exception is thrown.
|
139
|
+
*
|
140
|
+
* `initialize()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named`memory`.
|
141
|
+
* If `instance` does not have a `memory` export an exception is thrown.
|
142
|
+
*
|
143
|
+
* If `initialize()` is called more than once, an exception is thrown.
|
144
|
+
* @since v14.6.0, v12.19.0
|
145
|
+
*/
|
146
|
+
initialize(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
|
147
|
+
/**
|
148
|
+
* `wasiImport` is an object that implements the WASI system call API. This object
|
149
|
+
* should be passed as the `wasi_snapshot_preview1` import during the instantiation
|
150
|
+
* of a [`WebAssembly.Instance`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance).
|
151
|
+
* @since v13.3.0, v12.16.0
|
152
|
+
*/
|
153
|
+
readonly wasiImport: NodeJS.Dict<any>; // TODO: Narrow to DOM types
|
154
|
+
}
|
155
|
+
}
|
156
|
+
declare module 'node:wasi' {
|
157
|
+
export * from 'wasi';
|
158
|
+
}
|