@node-red/editor-client 3.0.2 → 3.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/locales/de/editor.json +2 -0
- package/locales/de/infotips.json +0 -0
- package/locales/de/jsonata.json +0 -0
- package/locales/en-US/editor.json +37 -6
- package/locales/en-US/infotips.json +0 -0
- package/locales/en-US/jsonata.json +0 -0
- package/locales/fr/editor.json +1238 -0
- package/locales/fr/infotips.json +23 -0
- package/locales/fr/jsonata.json +274 -0
- package/locales/ja/editor.json +48 -9
- package/locales/ko/editor.json +233 -31
- package/locales/ko/infotips.json +0 -0
- package/locales/ko/jsonata.json +0 -0
- package/locales/pt-BR/editor.json +1208 -0
- package/locales/pt-BR/infotips.json +23 -0
- package/locales/pt-BR/jsonata.json +274 -0
- package/locales/ru/editor.json +2 -0
- package/locales/ru/infotips.json +0 -0
- package/locales/ru/jsonata.json +0 -0
- package/locales/zh-CN/editor.json +1175 -1049
- package/locales/zh-TW/editor.json +3 -0
- package/package.json +1 -1
- package/public/red/about +140 -0
- package/public/red/red.js +2699 -1397
- package/public/red/red.min.js +4 -3
- package/public/red/style.min.css +1 -1
- package/public/red/tours/3.0/images/context-menu.png +0 -0
- package/public/red/tours/3.0/welcome.js +155 -0
- package/public/red/tours/images/context-menu.png +0 -0
- package/public/red/tours/images/global-env-vars.png +0 -0
- package/public/red/tours/images/hiding-flows.png +0 -0
- package/public/red/tours/images/locking-flows.png +0 -0
- package/public/red/tours/images/mermaid.png +0 -0
- package/public/red/tours/images/node-help.png +0 -0
- package/public/red/tours/images/tab-changes.png +0 -0
- package/public/red/tours/welcome.js +111 -94
- package/public/types/node/assert/strict.d.ts +11 -0
- package/public/types/node/assert.d.ts +898 -64
- package/public/types/node/async_hooks.d.ts +362 -94
- package/public/types/node/buffer.d.ts +2158 -14
- package/public/types/node/child_process.d.ts +1109 -257
- package/public/types/node/cluster.d.ts +349 -200
- package/public/types/node/console.d.ts +313 -43
- package/public/types/node/crypto.d.ts +3329 -656
- package/public/types/node/dgram.d.ts +459 -58
- package/public/types/node/diagnostics_channel.d.ts +155 -0
- package/public/types/node/dns/promises.d.ts +371 -0
- package/public/types/node/dns.d.ts +532 -265
- package/public/types/node/domain.d.ts +159 -16
- package/public/types/node/events.d.ts +589 -30
- package/public/types/node/fs/promises.d.ts +1097 -0
- package/public/types/node/fs.d.ts +2484 -958
- package/public/types/node/globals.d.ts +43 -503
- package/public/types/node/http.d.ts +1156 -145
- package/public/types/node/http2.d.ts +1610 -470
- package/public/types/node/https.d.ts +462 -72
- package/public/types/node/module.d.ts +72 -13
- package/public/types/node/net.d.ts +663 -131
- package/public/types/node/os.d.ts +238 -25
- package/public/types/node/path.d.ts +57 -23
- package/public/types/node/perf_hooks.d.ts +424 -112
- package/public/types/node/process.d.ts +1261 -193
- package/public/types/node/querystring.d.ts +107 -7
- package/public/types/node/readline.d.ts +443 -74
- package/public/types/node/stream/consumers.d.ts +15 -0
- package/public/types/node/stream/promises.d.ts +45 -0
- package/public/types/node/stream/web.d.ts +395 -0
- package/public/types/node/stream.d.ts +1081 -177
- package/public/types/node/string_decoder.d.ts +57 -0
- package/public/types/node/test.d.ts +193 -0
- package/public/types/node/timers/promises.d.ts +96 -0
- package/public/types/node/timers.d.ts +87 -12
- package/public/types/node/tls.d.ts +457 -222
- package/public/types/node/trace_events.d.ts +107 -10
- package/public/types/node/tty.d.ts +158 -23
- package/public/types/node/url.d.ts +734 -28
- package/public/types/node/util.d.ts +1542 -164
- package/public/types/node/v8.d.ts +261 -73
- package/public/types/node/vm.d.ts +384 -32
- package/public/types/node/wasi.d.ts +92 -23
- package/public/types/node/worker_threads.d.ts +531 -123
- package/public/types/node/zlib.d.ts +216 -63
- package/public/types/node-red/func.d.ts +3 -0
- package/public/vendor/jquery/css/base/images/ui-icons_444444_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_555555_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_777620_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_777777_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_cc0000_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_ffffff_256x240.png +0 -0
- package/public/vendor/jquery/css/base/jquery-ui.min.css +4 -4
- package/public/vendor/mermaid/mermaid.min.js +1284 -0
- package/public/vendor/monaco/dist/{ade705761eb7e702770d.ttf → 7064e66c3890a12c47b4.ttf} +0 -0
- package/public/vendor/monaco/dist/css.worker.js +1 -1
- package/public/vendor/monaco/dist/css.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/editor.js +1 -1
- package/public/vendor/monaco/dist/editor.js.LICENSE.txt +5 -1
- package/public/vendor/monaco/dist/editor.worker.js +1 -1
- package/public/vendor/monaco/dist/html.worker.js +1 -1
- package/public/vendor/monaco/dist/html.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/json.worker.js +1 -1
- package/public/vendor/monaco/dist/json.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/locale/cs.js +319 -71
- package/public/vendor/monaco/dist/locale/de.js +323 -75
- package/public/vendor/monaco/dist/locale/es.js +318 -70
- package/public/vendor/monaco/dist/locale/fr.js +327 -79
- package/public/vendor/monaco/dist/locale/it.js +325 -77
- package/public/vendor/monaco/dist/locale/ja.js +337 -89
- package/public/vendor/monaco/dist/locale/ko.js +324 -76
- package/public/vendor/monaco/dist/locale/pl.js +322 -74
- package/public/vendor/monaco/dist/locale/pt-br.js +321 -73
- package/public/vendor/monaco/dist/locale/qps-ploc.js +1580 -1332
- package/public/vendor/monaco/dist/locale/ru.js +324 -76
- package/public/vendor/monaco/dist/locale/tr.js +326 -78
- package/public/vendor/monaco/dist/locale/zh-hans.js +328 -80
- package/public/vendor/monaco/dist/locale/zh-hant.js +321 -73
- package/public/vendor/monaco/dist/theme/forge.json +236 -0
- package/public/vendor/monaco/dist/theme/github-dark.json +348 -0
- package/public/vendor/monaco/dist/theme/github-light.json +348 -0
- package/public/vendor/monaco/dist/theme/nord.json +93 -0
- package/public/vendor/monaco/dist/ts.worker.js +1 -1
- package/public/vendor/monaco/dist/ts.worker.js.LICENSE.txt +14 -6
- package/public/vendor/vendor.js +9 -15
- /package/public/red/tours/{images → 3.0/images}/continuous-search.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/debug-path-tooltip.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/junction-quick-add.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/junction-slice.gif +0 -0
- /package/public/red/tours/{images → 3.0/images}/split-wire-with-links.gif +0 -0
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
|
|
2
2
|
/* NOTE: Do not edit directly! This file is generated using `npm run update-types` in https://github.com/Steve-Mcl/monaco-editor-esm-i18n */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The `vm` module enables compiling and running code within V8 Virtual
|
|
6
|
+
* Machine contexts. **The `vm` module is not a security mechanism. Do**
|
|
7
|
+
* **not use it to run untrusted code.**
|
|
8
|
+
*
|
|
9
|
+
* JavaScript code can be compiled and run immediately or
|
|
10
|
+
* compiled, saved, and run later.
|
|
11
|
+
*
|
|
12
|
+
* A common use case is to run the code in a different V8 Context. This means
|
|
13
|
+
* invoked code has a different global object than the invoking code.
|
|
14
|
+
*
|
|
15
|
+
* One can provide the context by `contextifying` an
|
|
16
|
+
* object. The invoked code treats any property in the context like a
|
|
17
|
+
* global variable. Any changes to global variables caused by the invoked
|
|
18
|
+
* code are reflected in the context object.
|
|
19
|
+
*
|
|
20
|
+
* ```js
|
|
21
|
+
* const vm = require('vm');
|
|
22
|
+
*
|
|
23
|
+
* const x = 1;
|
|
24
|
+
*
|
|
25
|
+
* const context = { x: 2 };
|
|
26
|
+
* vm.createContext(context); // Contextify the object.
|
|
27
|
+
*
|
|
28
|
+
* const code = 'x += 40; var y = 17;';
|
|
29
|
+
* // `x` and `y` are global variables in the context.
|
|
30
|
+
* // Initially, x has the value 2 because that is the value of context.x.
|
|
31
|
+
* vm.runInContext(code, context);
|
|
32
|
+
*
|
|
33
|
+
* console.log(context.x); // 42
|
|
34
|
+
* console.log(context.y); // 17
|
|
35
|
+
*
|
|
36
|
+
* console.log(x); // 1; y is not defined.
|
|
37
|
+
* ```
|
|
38
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/vm.js)
|
|
39
|
+
*/
|
|
4
40
|
declare module 'vm' {
|
|
5
|
-
interface Context extends NodeJS.Dict<any> {
|
|
41
|
+
interface Context extends NodeJS.Dict<any> {}
|
|
6
42
|
interface BaseOptions {
|
|
7
43
|
/**
|
|
8
44
|
* Specifies the filename used in stack traces produced by this script.
|
|
@@ -64,13 +100,11 @@ declare module 'vm' {
|
|
|
64
100
|
* The sandbox/context in which the said function should be compiled in.
|
|
65
101
|
*/
|
|
66
102
|
parsingContext?: Context | undefined;
|
|
67
|
-
|
|
68
103
|
/**
|
|
69
104
|
* An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
|
|
70
105
|
*/
|
|
71
106
|
contextExtensions?: Object[] | undefined;
|
|
72
107
|
}
|
|
73
|
-
|
|
74
108
|
interface CreateContextOptions {
|
|
75
109
|
/**
|
|
76
110
|
* Human-readable name of the newly created context.
|
|
@@ -85,27 +119,27 @@ declare module 'vm' {
|
|
|
85
119
|
* @default ''
|
|
86
120
|
*/
|
|
87
121
|
origin?: string | undefined;
|
|
88
|
-
codeGeneration?:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
codeGeneration?:
|
|
123
|
+
| {
|
|
124
|
+
/**
|
|
125
|
+
* If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
|
|
126
|
+
* will throw an EvalError.
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
strings?: boolean | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
wasm?: boolean | undefined;
|
|
135
|
+
}
|
|
136
|
+
| undefined;
|
|
101
137
|
/**
|
|
102
138
|
* If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
|
|
103
139
|
*/
|
|
104
140
|
microtaskMode?: 'afterEvaluate' | undefined;
|
|
105
141
|
}
|
|
106
|
-
|
|
107
142
|
type MeasureMemoryMode = 'summary' | 'detailed';
|
|
108
|
-
|
|
109
143
|
interface MeasureMemoryOptions {
|
|
110
144
|
/**
|
|
111
145
|
* @default 'summary'
|
|
@@ -113,42 +147,360 @@ declare module 'vm' {
|
|
|
113
147
|
mode?: MeasureMemoryMode | undefined;
|
|
114
148
|
context?: Context | undefined;
|
|
115
149
|
}
|
|
116
|
-
|
|
117
150
|
interface MemoryMeasurement {
|
|
118
151
|
total: {
|
|
119
152
|
jsMemoryEstimate: number;
|
|
120
153
|
jsMemoryRange: [number, number];
|
|
121
154
|
};
|
|
122
155
|
}
|
|
123
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Instances of the `vm.Script` class contain precompiled scripts that can be
|
|
158
|
+
* executed in specific contexts.
|
|
159
|
+
* @since v0.3.1
|
|
160
|
+
*/
|
|
124
161
|
class Script {
|
|
125
162
|
constructor(code: string, options?: ScriptOptions);
|
|
126
|
-
|
|
127
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Runs the compiled code contained by the `vm.Script` object within the given`contextifiedObject` and returns the result. Running code does not have access
|
|
165
|
+
* to local scope.
|
|
166
|
+
*
|
|
167
|
+
* The following example compiles code that increments a global variable, sets
|
|
168
|
+
* the value of another global variable, then execute the code multiple times.
|
|
169
|
+
* The globals are contained in the `context` object.
|
|
170
|
+
*
|
|
171
|
+
* ```js
|
|
172
|
+
* const vm = require('vm');
|
|
173
|
+
*
|
|
174
|
+
* const context = {
|
|
175
|
+
* animal: 'cat',
|
|
176
|
+
* count: 2
|
|
177
|
+
* };
|
|
178
|
+
*
|
|
179
|
+
* const script = new vm.Script('count += 1; name = "kitty";');
|
|
180
|
+
*
|
|
181
|
+
* vm.createContext(context);
|
|
182
|
+
* for (let i = 0; i < 10; ++i) {
|
|
183
|
+
* script.runInContext(context);
|
|
184
|
+
* }
|
|
185
|
+
*
|
|
186
|
+
* console.log(context);
|
|
187
|
+
* // Prints: { animal: 'cat', count: 12, name: 'kitty' }
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* Using the `timeout` or `breakOnSigint` options will result in new event loops
|
|
191
|
+
* and corresponding threads being started, which have a non-zero performance
|
|
192
|
+
* overhead.
|
|
193
|
+
* @since v0.3.1
|
|
194
|
+
* @param contextifiedObject A `contextified` object as returned by the `vm.createContext()` method.
|
|
195
|
+
* @return the result of the very last statement executed in the script.
|
|
196
|
+
*/
|
|
197
|
+
runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
|
|
198
|
+
/**
|
|
199
|
+
* First contextifies the given `contextObject`, runs the compiled code contained
|
|
200
|
+
* by the `vm.Script` object within the created context, and returns the result.
|
|
201
|
+
* Running code does not have access to local scope.
|
|
202
|
+
*
|
|
203
|
+
* The following example compiles code that sets a global variable, then executes
|
|
204
|
+
* the code multiple times in different contexts. The globals are set on and
|
|
205
|
+
* contained within each individual `context`.
|
|
206
|
+
*
|
|
207
|
+
* ```js
|
|
208
|
+
* const vm = require('vm');
|
|
209
|
+
*
|
|
210
|
+
* const script = new vm.Script('globalVar = "set"');
|
|
211
|
+
*
|
|
212
|
+
* const contexts = [{}, {}, {}];
|
|
213
|
+
* contexts.forEach((context) => {
|
|
214
|
+
* script.runInNewContext(context);
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* console.log(contexts);
|
|
218
|
+
* // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
|
|
219
|
+
* ```
|
|
220
|
+
* @since v0.3.1
|
|
221
|
+
* @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
|
|
222
|
+
* @return the result of the very last statement executed in the script.
|
|
223
|
+
*/
|
|
224
|
+
runInNewContext(contextObject?: Context, options?: RunningScriptOptions): any;
|
|
225
|
+
/**
|
|
226
|
+
* Runs the compiled code contained by the `vm.Script` within the context of the
|
|
227
|
+
* current `global` object. Running code does not have access to local scope, but_does_ have access to the current `global` object.
|
|
228
|
+
*
|
|
229
|
+
* The following example compiles code that increments a `global` variable then
|
|
230
|
+
* executes that code multiple times:
|
|
231
|
+
*
|
|
232
|
+
* ```js
|
|
233
|
+
* const vm = require('vm');
|
|
234
|
+
*
|
|
235
|
+
* global.globalVar = 0;
|
|
236
|
+
*
|
|
237
|
+
* const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });
|
|
238
|
+
*
|
|
239
|
+
* for (let i = 0; i < 1000; ++i) {
|
|
240
|
+
* script.runInThisContext();
|
|
241
|
+
* }
|
|
242
|
+
*
|
|
243
|
+
* console.log(globalVar);
|
|
244
|
+
*
|
|
245
|
+
* // 1000
|
|
246
|
+
* ```
|
|
247
|
+
* @since v0.3.1
|
|
248
|
+
* @return the result of the very last statement executed in the script.
|
|
249
|
+
*/
|
|
128
250
|
runInThisContext(options?: RunningScriptOptions): any;
|
|
251
|
+
/**
|
|
252
|
+
* 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
|
|
253
|
+
* time and any number of times.
|
|
254
|
+
*
|
|
255
|
+
* ```js
|
|
256
|
+
* const script = new vm.Script(`
|
|
257
|
+
* function add(a, b) {
|
|
258
|
+
* return a + b;
|
|
259
|
+
* }
|
|
260
|
+
*
|
|
261
|
+
* const x = add(1, 2);
|
|
262
|
+
* `);
|
|
263
|
+
*
|
|
264
|
+
* const cacheWithoutX = script.createCachedData();
|
|
265
|
+
*
|
|
266
|
+
* script.runInThisContext();
|
|
267
|
+
*
|
|
268
|
+
* const cacheWithX = script.createCachedData();
|
|
269
|
+
* ```
|
|
270
|
+
* @since v10.6.0
|
|
271
|
+
*/
|
|
129
272
|
createCachedData(): Buffer;
|
|
273
|
+
/** @deprecated in favor of `script.createCachedData()` */
|
|
274
|
+
cachedDataProduced?: boolean | undefined;
|
|
130
275
|
cachedDataRejected?: boolean | undefined;
|
|
276
|
+
cachedData?: Buffer | undefined;
|
|
131
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* If given a `contextObject`, the `vm.createContext()` method will `prepare
|
|
280
|
+
* that object` so that it can be used in calls to {@link runInContext} or `script.runInContext()`. Inside such scripts,
|
|
281
|
+
* the `contextObject` will be the global object, retaining all of its existing
|
|
282
|
+
* 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
|
|
283
|
+
* will remain unchanged.
|
|
284
|
+
*
|
|
285
|
+
* ```js
|
|
286
|
+
* const vm = require('vm');
|
|
287
|
+
*
|
|
288
|
+
* global.globalVar = 3;
|
|
289
|
+
*
|
|
290
|
+
* const context = { globalVar: 1 };
|
|
291
|
+
* vm.createContext(context);
|
|
292
|
+
*
|
|
293
|
+
* vm.runInContext('globalVar *= 2;', context);
|
|
294
|
+
*
|
|
295
|
+
* console.log(context);
|
|
296
|
+
* // Prints: { globalVar: 2 }
|
|
297
|
+
*
|
|
298
|
+
* console.log(global.globalVar);
|
|
299
|
+
* // Prints: 3
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
|
|
303
|
+
* empty `contextified` object will be returned.
|
|
304
|
+
*
|
|
305
|
+
* The `vm.createContext()` method is primarily useful for creating a single
|
|
306
|
+
* context that can be used to run multiple scripts. For instance, if emulating a
|
|
307
|
+
* web browser, the method can be used to create a single context representing a
|
|
308
|
+
* window's global object, then run all `<script>` tags together within that
|
|
309
|
+
* context.
|
|
310
|
+
*
|
|
311
|
+
* The provided `name` and `origin` of the context are made visible through the
|
|
312
|
+
* Inspector API.
|
|
313
|
+
* @since v0.3.1
|
|
314
|
+
* @return contextified object.
|
|
315
|
+
*/
|
|
132
316
|
function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
|
|
317
|
+
/**
|
|
318
|
+
* Returns `true` if the given `object` object has been `contextified` using {@link createContext}.
|
|
319
|
+
* @since v0.11.7
|
|
320
|
+
*/
|
|
133
321
|
function isContext(sandbox: Context): boolean;
|
|
134
|
-
|
|
135
|
-
|
|
322
|
+
/**
|
|
323
|
+
* The `vm.runInContext()` method compiles `code`, runs it within the context of
|
|
324
|
+
* the `contextifiedObject`, then returns the result. Running code does not have
|
|
325
|
+
* access to the local scope. The `contextifiedObject` object _must_ have been
|
|
326
|
+
* previously `contextified` using the {@link createContext} method.
|
|
327
|
+
*
|
|
328
|
+
* If `options` is a string, then it specifies the filename.
|
|
329
|
+
*
|
|
330
|
+
* The following example compiles and executes different scripts using a single `contextified` object:
|
|
331
|
+
*
|
|
332
|
+
* ```js
|
|
333
|
+
* const vm = require('vm');
|
|
334
|
+
*
|
|
335
|
+
* const contextObject = { globalVar: 1 };
|
|
336
|
+
* vm.createContext(contextObject);
|
|
337
|
+
*
|
|
338
|
+
* for (let i = 0; i < 10; ++i) {
|
|
339
|
+
* vm.runInContext('globalVar *= 2;', contextObject);
|
|
340
|
+
* }
|
|
341
|
+
* console.log(contextObject);
|
|
342
|
+
* // Prints: { globalVar: 1024 }
|
|
343
|
+
* ```
|
|
344
|
+
* @since v0.3.1
|
|
345
|
+
* @param code The JavaScript code to compile and run.
|
|
346
|
+
* @param contextifiedObject The `contextified` object that will be used as the `global` when the `code` is compiled and run.
|
|
347
|
+
* @return the result of the very last statement executed in the script.
|
|
348
|
+
*/
|
|
349
|
+
function runInContext(code: string, contextifiedObject: Context, options?: RunningScriptOptions | string): any;
|
|
350
|
+
/**
|
|
351
|
+
* The `vm.runInNewContext()` first contextifies the given `contextObject` (or
|
|
352
|
+
* creates a new `contextObject` if passed as `undefined`), compiles the `code`,
|
|
353
|
+
* runs it within the created context, then returns the result. Running code
|
|
354
|
+
* does not have access to the local scope.
|
|
355
|
+
*
|
|
356
|
+
* If `options` is a string, then it specifies the filename.
|
|
357
|
+
*
|
|
358
|
+
* The following example compiles and executes code that increments a global
|
|
359
|
+
* variable and sets a new one. These globals are contained in the `contextObject`.
|
|
360
|
+
*
|
|
361
|
+
* ```js
|
|
362
|
+
* const vm = require('vm');
|
|
363
|
+
*
|
|
364
|
+
* const contextObject = {
|
|
365
|
+
* animal: 'cat',
|
|
366
|
+
* count: 2
|
|
367
|
+
* };
|
|
368
|
+
*
|
|
369
|
+
* vm.runInNewContext('count += 1; name = "kitty"', contextObject);
|
|
370
|
+
* console.log(contextObject);
|
|
371
|
+
* // Prints: { animal: 'cat', count: 3, name: 'kitty' }
|
|
372
|
+
* ```
|
|
373
|
+
* @since v0.3.1
|
|
374
|
+
* @param code The JavaScript code to compile and run.
|
|
375
|
+
* @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
|
|
376
|
+
* @return the result of the very last statement executed in the script.
|
|
377
|
+
*/
|
|
378
|
+
function runInNewContext(code: string, contextObject?: Context, options?: RunningScriptOptions | string): any;
|
|
379
|
+
/**
|
|
380
|
+
* `vm.runInThisContext()` compiles `code`, runs it within the context of the
|
|
381
|
+
* current `global` and returns the result. Running code does not have access to
|
|
382
|
+
* local scope, but does have access to the current `global` object.
|
|
383
|
+
*
|
|
384
|
+
* If `options` is a string, then it specifies the filename.
|
|
385
|
+
*
|
|
386
|
+
* The following example illustrates using both `vm.runInThisContext()` and
|
|
387
|
+
* the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
|
|
388
|
+
*
|
|
389
|
+
* ```js
|
|
390
|
+
* const vm = require('vm');
|
|
391
|
+
* let localVar = 'initial value';
|
|
392
|
+
*
|
|
393
|
+
* const vmResult = vm.runInThisContext('localVar = "vm";');
|
|
394
|
+
* console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
|
|
395
|
+
* // Prints: vmResult: 'vm', localVar: 'initial value'
|
|
396
|
+
*
|
|
397
|
+
* const evalResult = eval('localVar = "eval";');
|
|
398
|
+
* console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);
|
|
399
|
+
* // Prints: evalResult: 'eval', localVar: 'eval'
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* Because `vm.runInThisContext()` does not have access to the local scope,`localVar` is unchanged. In contrast,
|
|
403
|
+
* [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
|
|
404
|
+
* 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')`.
|
|
405
|
+
*
|
|
406
|
+
* ## Example: Running an HTTP server within a VM
|
|
407
|
+
*
|
|
408
|
+
* When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
|
|
409
|
+
* context. The code passed to this VM context will have its own isolated scope.
|
|
410
|
+
*
|
|
411
|
+
* In order to run a simple web server using the `http` module the code passed to
|
|
412
|
+
* the context must either call `require('http')` on its own, or have a reference
|
|
413
|
+
* to the `http` module passed to it. For instance:
|
|
414
|
+
*
|
|
415
|
+
* ```js
|
|
416
|
+
* 'use strict';
|
|
417
|
+
* const vm = require('vm');
|
|
418
|
+
*
|
|
419
|
+
* const code = `
|
|
420
|
+
* ((require) => {
|
|
421
|
+
* const http = require('http');
|
|
422
|
+
*
|
|
423
|
+
* http.createServer((request, response) => {
|
|
424
|
+
* response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
425
|
+
* response.end('Hello World\\n');
|
|
426
|
+
* }).listen(8124);
|
|
427
|
+
*
|
|
428
|
+
* console.log('Server running at http://127.0.0.1:8124/');
|
|
429
|
+
* })`;
|
|
430
|
+
*
|
|
431
|
+
* vm.runInThisContext(code)(require);
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* The `require()` in the above case shares the state with the context it is
|
|
435
|
+
* passed from. This may introduce risks when untrusted code is executed, e.g.
|
|
436
|
+
* altering objects in the context in unwanted ways.
|
|
437
|
+
* @since v0.3.1
|
|
438
|
+
* @param code The JavaScript code to compile and run.
|
|
439
|
+
* @return the result of the very last statement executed in the script.
|
|
440
|
+
*/
|
|
136
441
|
function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
|
|
442
|
+
/**
|
|
443
|
+
* Compiles the given code into the provided context (if no context is
|
|
444
|
+
* supplied, the current context is used), and returns it wrapped inside a
|
|
445
|
+
* function with the given `params`.
|
|
446
|
+
* @since v10.10.0
|
|
447
|
+
* @param code The body of the function to compile.
|
|
448
|
+
* @param params An array of strings containing all parameters for the function.
|
|
449
|
+
*/
|
|
137
450
|
function compileFunction(code: string, params?: ReadonlyArray<string>, options?: CompileFunctionOptions): Function;
|
|
138
|
-
|
|
139
451
|
/**
|
|
140
|
-
* Measure the memory known to V8 and used by
|
|
452
|
+
* Measure the memory known to V8 and used by all contexts known to the
|
|
453
|
+
* current V8 isolate, or the main context.
|
|
141
454
|
*
|
|
142
455
|
* The format of the object that the returned Promise may resolve with is
|
|
143
456
|
* specific to the V8 engine and may change from one version of V8 to the next.
|
|
144
457
|
*
|
|
145
|
-
* The returned result is different from the statistics returned by
|
|
146
|
-
*
|
|
147
|
-
* the
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
458
|
+
* The returned result is different from the statistics returned by`v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
|
|
459
|
+
* memory reachable by each V8 specific contexts in the current instance of
|
|
460
|
+
* the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
|
|
461
|
+
* the memory occupied by each heap space in the current V8 instance.
|
|
462
|
+
*
|
|
463
|
+
* ```js
|
|
464
|
+
* const vm = require('vm');
|
|
465
|
+
* // Measure the memory used by the main context.
|
|
466
|
+
* vm.measureMemory({ mode: 'summary' })
|
|
467
|
+
* // This is the same as vm.measureMemory()
|
|
468
|
+
* .then((result) => {
|
|
469
|
+
* // The current format is:
|
|
470
|
+
* // {
|
|
471
|
+
* // total: {
|
|
472
|
+
* // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
|
|
473
|
+
* // }
|
|
474
|
+
* // }
|
|
475
|
+
* console.log(result);
|
|
476
|
+
* });
|
|
151
477
|
*
|
|
478
|
+
* const context = vm.createContext({ a: 1 });
|
|
479
|
+
* vm.measureMemory({ mode: 'detailed', execution: 'eager' })
|
|
480
|
+
* .then((result) => {
|
|
481
|
+
* // Reference the context here so that it won't be GC'ed
|
|
482
|
+
* // until the measurement is complete.
|
|
483
|
+
* console.log(context.a);
|
|
484
|
+
* // {
|
|
485
|
+
* // total: {
|
|
486
|
+
* // jsMemoryEstimate: 2574732,
|
|
487
|
+
* // jsMemoryRange: [ 2574732, 2904372 ]
|
|
488
|
+
* // },
|
|
489
|
+
* // current: {
|
|
490
|
+
* // jsMemoryEstimate: 2438996,
|
|
491
|
+
* // jsMemoryRange: [ 2438996, 2768636 ]
|
|
492
|
+
* // },
|
|
493
|
+
* // other: [
|
|
494
|
+
* // {
|
|
495
|
+
* // jsMemoryEstimate: 135736,
|
|
496
|
+
* // jsMemoryRange: [ 135736, 465376 ]
|
|
497
|
+
* // }
|
|
498
|
+
* // ]
|
|
499
|
+
* // }
|
|
500
|
+
* console.log(result);
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
* @since v13.10.0
|
|
152
504
|
* @experimental
|
|
153
505
|
*/
|
|
154
506
|
function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
|
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
|
|
2
2
|
/* NOTE: Do not edit directly! This file is generated using `npm run update-types` in https://github.com/Steve-Mcl/monaco-editor-esm-i18n */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The WASI API provides an implementation of the [WebAssembly System Interface](https://wasi.dev/) specification. WASI gives sandboxed WebAssembly applications access to the
|
|
6
|
+
* underlying operating system via a collection of POSIX-like functions.
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { readFile } from 'fs/promises';
|
|
10
|
+
* import { WASI } from 'wasi';
|
|
11
|
+
* import { argv, env } from 'process';
|
|
12
|
+
*
|
|
13
|
+
* const wasi = new WASI({
|
|
14
|
+
* args: argv,
|
|
15
|
+
* env,
|
|
16
|
+
* preopens: {
|
|
17
|
+
* '/sandbox': '/some/real/path/that/wasm/can/access'
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Some WASI binaries require:
|
|
22
|
+
* // const importObject = { wasi_unstable: wasi.wasiImport };
|
|
23
|
+
* const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
|
|
24
|
+
*
|
|
25
|
+
* const wasm = await WebAssembly.compile(
|
|
26
|
+
* await readFile(new URL('./demo.wasm', import.meta.url))
|
|
27
|
+
* );
|
|
28
|
+
* const instance = await WebAssembly.instantiate(wasm, importObject);
|
|
29
|
+
*
|
|
30
|
+
* wasi.start(instance);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* To run the above example, create a new WebAssembly text format file named`demo.wat`:
|
|
34
|
+
*
|
|
35
|
+
* ```text
|
|
36
|
+
* (module
|
|
37
|
+
* ;; Import the required fd_write WASI function which will write the given io vectors to stdout
|
|
38
|
+
* ;; The function signature for fd_write is:
|
|
39
|
+
* ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written
|
|
40
|
+
* (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
|
|
41
|
+
*
|
|
42
|
+
* (memory 1)
|
|
43
|
+
* (export "memory" (memory 0))
|
|
44
|
+
*
|
|
45
|
+
* ;; Write 'hello world\n' to memory at an offset of 8 bytes
|
|
46
|
+
* ;; Note the trailing newline which is required for the text to appear
|
|
47
|
+
* (data (i32.const 8) "hello world\n")
|
|
48
|
+
*
|
|
49
|
+
* (func $main (export "_start")
|
|
50
|
+
* ;; Creating a new io vector within linear memory
|
|
51
|
+
* (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string
|
|
52
|
+
* (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string
|
|
53
|
+
*
|
|
54
|
+
* (call $fd_write
|
|
55
|
+
* (i32.const 1) ;; file_descriptor - 1 for stdout
|
|
56
|
+
* (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0
|
|
57
|
+
* (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one.
|
|
58
|
+
* (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written
|
|
59
|
+
* )
|
|
60
|
+
* drop ;; Discard the number of bytes written from the top of the stack
|
|
61
|
+
* )
|
|
62
|
+
* )
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Use [wabt](https://github.com/WebAssembly/wabt) to compile `.wat` to `.wasm`
|
|
66
|
+
*
|
|
67
|
+
* ```console
|
|
68
|
+
* $ wat2wasm demo.wat
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* The `--experimental-wasi-unstable-preview1` CLI argument is needed for this
|
|
72
|
+
* example to run.
|
|
73
|
+
* @experimental
|
|
74
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/wasi.js)
|
|
75
|
+
*/
|
|
4
76
|
declare module 'wasi' {
|
|
5
77
|
interface WASIOptions {
|
|
6
78
|
/**
|
|
@@ -9,13 +81,11 @@ declare module 'wasi' {
|
|
|
9
81
|
* WASI command itself.
|
|
10
82
|
*/
|
|
11
83
|
args?: string[] | undefined;
|
|
12
|
-
|
|
13
84
|
/**
|
|
14
85
|
* An object similar to `process.env` that the WebAssembly
|
|
15
86
|
* application will see as its environment.
|
|
16
87
|
*/
|
|
17
88
|
env?: object | undefined;
|
|
18
|
-
|
|
19
89
|
/**
|
|
20
90
|
* This object represents the WebAssembly application's
|
|
21
91
|
* sandbox directory structure. The string keys of `preopens` are treated as
|
|
@@ -23,7 +93,6 @@ declare module 'wasi' {
|
|
|
23
93
|
* the real paths to those directories on the host machine.
|
|
24
94
|
*/
|
|
25
95
|
preopens?: NodeJS.Dict<string> | undefined;
|
|
26
|
-
|
|
27
96
|
/**
|
|
28
97
|
* By default, WASI applications terminate the Node.js
|
|
29
98
|
* process via the `__wasi_proc_exit()` function. Setting this option to `true`
|
|
@@ -32,57 +101,57 @@ declare module 'wasi' {
|
|
|
32
101
|
* @default false
|
|
33
102
|
*/
|
|
34
103
|
returnOnExit?: boolean | undefined;
|
|
35
|
-
|
|
36
104
|
/**
|
|
37
105
|
* The file descriptor used as standard input in the WebAssembly application.
|
|
38
106
|
* @default 0
|
|
39
107
|
*/
|
|
40
108
|
stdin?: number | undefined;
|
|
41
|
-
|
|
42
109
|
/**
|
|
43
110
|
* The file descriptor used as standard output in the WebAssembly application.
|
|
44
111
|
* @default 1
|
|
45
112
|
*/
|
|
46
113
|
stdout?: number | undefined;
|
|
47
|
-
|
|
48
114
|
/**
|
|
49
115
|
* The file descriptor used as standard error in the WebAssembly application.
|
|
50
116
|
* @default 2
|
|
51
117
|
*/
|
|
52
118
|
stderr?: number | undefined;
|
|
53
119
|
}
|
|
54
|
-
|
|
120
|
+
/**
|
|
121
|
+
* The `WASI` class provides the WASI system call API and additional convenience
|
|
122
|
+
* methods for working with WASI-based applications. Each `WASI` instance
|
|
123
|
+
* represents a distinct sandbox environment. For security purposes, each `WASI`instance must have its command-line arguments, environment variables, and
|
|
124
|
+
* sandbox directory structure configured explicitly.
|
|
125
|
+
* @since v13.3.0, v12.16.0
|
|
126
|
+
*/
|
|
55
127
|
class WASI {
|
|
56
128
|
constructor(options?: WASIOptions);
|
|
57
129
|
/**
|
|
130
|
+
* 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()`
|
|
131
|
+
* export, then an exception is thrown.
|
|
58
132
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* invoke the `__wasi_unstable_reactor_start()` export. If neither of those exports
|
|
62
|
-
* is present on `instance`, then `start()` does nothing.
|
|
63
|
-
*
|
|
64
|
-
* `start()` requires that `instance` exports a [`WebAssembly.Memory`][] named
|
|
65
|
-
* `memory`. If `instance` does not have a `memory` export an exception is thrown.
|
|
133
|
+
* `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
|
|
134
|
+
* `instance` does not have a `memory` export an exception is thrown.
|
|
66
135
|
*
|
|
67
136
|
* If `start()` is called more than once, an exception is thrown.
|
|
137
|
+
* @since v13.3.0, v12.16.0
|
|
68
138
|
*/
|
|
69
139
|
start(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
|
|
70
|
-
|
|
71
140
|
/**
|
|
72
|
-
* Attempt to initialize `instance` as a WASI reactor by invoking its
|
|
73
|
-
* If `instance` contains a `_start()` export, then an exception is thrown.
|
|
141
|
+
* 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.
|
|
74
142
|
*
|
|
75
|
-
* `
|
|
76
|
-
*
|
|
143
|
+
* `initialize()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named`memory`.
|
|
144
|
+
* If `instance` does not have a `memory` export an exception is thrown.
|
|
77
145
|
*
|
|
78
146
|
* If `initialize()` is called more than once, an exception is thrown.
|
|
147
|
+
* @since v14.6.0, v12.19.0
|
|
79
148
|
*/
|
|
80
149
|
initialize(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
|
|
81
|
-
|
|
82
150
|
/**
|
|
83
|
-
*
|
|
84
|
-
* should be passed as the `wasi_snapshot_preview1` import during the instantiation
|
|
85
|
-
* [`WebAssembly.Instance`]
|
|
151
|
+
* `wasiImport` is an object that implements the WASI system call API. This object
|
|
152
|
+
* should be passed as the `wasi_snapshot_preview1` import during the instantiation
|
|
153
|
+
* of a [`WebAssembly.Instance`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance).
|
|
154
|
+
* @since v13.3.0, v12.16.0
|
|
86
155
|
*/
|
|
87
156
|
readonly wasiImport: NodeJS.Dict<any>; // TODO: Narrow to DOM types
|
|
88
157
|
}
|