@@ -175,6 +175,15 @@ added: v0.3.1
175
175
* ` timeout ` {number} Specifies the number of milliseconds to execute ` code `
176
176
before terminating execution. If execution is terminated, an [ ` Error ` ] [ ]
177
177
will be thrown.
178
+ * ` contextName ` {string} Human-readable name of the newly created context.
179
+ ** Default:** ` 'VM Context i' ` , where ` i ` is an ascending numerical index of
180
+ the created context.
181
+ * ` contextOrigin ` {string} [ Origin] [ origin ] corresponding to the newly
182
+ created context for display purposes. The origin should be formatted like a
183
+ URL, but with only the scheme, host, and port (if necessary), like the
184
+ value of the [ ` url.origin ` ] [ ] property of a [ ` URL ` ] [ ] object. Most notably,
185
+ this string should omit the trailing slash, as that denotes a path.
186
+ ** Default:** ` '' ` .
178
187
179
188
First contextifies the given ` sandbox ` , runs the compiled code contained by
180
189
the ` vm.Script ` object within the created sandbox, and returns the result.
@@ -242,12 +251,22 @@ console.log(globalVar);
242
251
// 1000
243
252
```
244
253
245
- ## vm.createContext([ sandbox] )
254
+ ## vm.createContext([ sandbox[ , options ] ] )
246
255
<!-- YAML
247
256
added: v0.3.1
248
257
-->
249
258
250
259
* ` sandbox ` {Object}
260
+ * ` options ` {Object}
261
+ * ` name ` {string} Human-readable name of the newly created context.
262
+ ** Default:** ` 'VM Context i' ` , where ` i ` is an ascending numerical index of
263
+ the created context.
264
+ * ` origin ` {string} [ Origin] [ origin ] corresponding to the newly created
265
+ context for display purposes. The origin should be formatted like a URL,
266
+ but with only the scheme, host, and port (if necessary), like the value of
267
+ the [ ` url.origin ` ] [ ] property of a [ ` URL ` ] [ ] object. Most notably, this
268
+ string should omit the trailing slash, as that denotes a path.
269
+ ** Default:** ` '' ` .
251
270
252
271
If given a ` sandbox ` object, the ` vm.createContext() ` method will [ prepare
253
272
that sandbox] [ contextified ] so that it can be used in calls to
@@ -282,6 +301,9 @@ web browser, the method can be used to create a single sandbox representing a
282
301
window's global object, then run all ` <script> ` tags together within the context
283
302
of that sandbox.
284
303
304
+ The provided ` name ` and ` origin ` of the context are made visible through the
305
+ Inspector API.
306
+
285
307
## vm.isContext(sandbox)
286
308
<!-- YAML
287
309
added: v0.11.7
@@ -385,6 +407,15 @@ added: v0.3.1
385
407
* ` timeout ` {number} Specifies the number of milliseconds to execute ` code `
386
408
before terminating execution. If execution is terminated, an [ ` Error ` ] [ ]
387
409
will be thrown.
410
+ * ` contextName ` {string} Human-readable name of the newly created context.
411
+ ** Default:** ` 'VM Context i' ` , where ` i ` is an ascending numerical index of
412
+ the created context.
413
+ * ` contextOrigin ` {string} [ Origin] [ origin ] corresponding to the newly
414
+ created context for display purposes. The origin should be formatted like a
415
+ URL, but with only the scheme, host, and port (if necessary), like the
416
+ value of the [ ` url.origin ` ] [ ] property of a [ ` URL ` ] [ ] object. Most notably,
417
+ this string should omit the trailing slash, as that denotes a path.
418
+ ** Default:** ` '' ` .
388
419
389
420
The ` vm.runInNewContext() ` first contextifies the given ` sandbox ` object (or
390
421
creates a new ` sandbox ` if passed as ` undefined ` ), compiles the ` code ` , runs it
@@ -510,14 +541,17 @@ associating it with the `sandbox` object is what this document refers to as
510
541
"contextifying" the ` sandbox ` .
511
542
512
543
[ `Error` ] : errors.html#errors_class_error
544
+ [ `URL` ] : url.html#url_class_url
513
545
[ `eval()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
514
546
[ `script.runInContext()` ] : #vm_script_runincontext_contextifiedsandbox_options
515
547
[ `script.runInThisContext()` ] : #vm_script_runinthiscontext_options
516
- [ `vm.createContext()` ] : #vm_vm_createcontext_sandbox
548
+ [ `url.origin` ] : https://nodejs.org/api/url.html#url_url_origin
549
+ [ `vm.createContext()` ] : #vm_vm_createcontext_sandbox_options
517
550
[ `vm.runInContext()` ] : #vm_vm_runincontext_code_contextifiedsandbox_options
518
551
[ `vm.runInThisContext()` ] : #vm_vm_runinthiscontext_code_options
519
552
[ V8 Embedder's Guide ] : https://github.com/v8/v8/wiki/Embedder's%20Guide#contexts
520
553
[ command line option ] : cli.html
521
554
[ contextified ] : #vm_what_does_it_mean_to_contextify_an_object
522
555
[ global object ] : https://es5.github.io/#x15.1
523
556
[ indirect `eval()` call ] : https://es5.github.io/#x10.4.2
557
+ [ origin ] : https://developer.mozilla.org/en-US/docs/Glossary/Origin
0 commit comments