@@ -175,6 +175,15 @@ added: v0.3.1
175175 * ` timeout ` {number} Specifies the number of milliseconds to execute ` code `
176176 before terminating execution. If execution is terminated, an [ ` Error ` ] [ ]
177177 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:** ` '' ` .
178187
179188First contextifies the given ` sandbox ` , runs the compiled code contained by
180189the ` vm.Script ` object within the created sandbox, and returns the result.
@@ -242,12 +251,22 @@ console.log(globalVar);
242251// 1000
243252```
244253
245- ## vm.createContext([ sandbox] )
254+ ## vm.createContext([ sandbox[ , options ] ] )
246255<!-- YAML
247256added: v0.3.1
248257-->
249258
250259* ` 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:** ` '' ` .
251270
252271If given a ` sandbox ` object, the ` vm.createContext() ` method will [ prepare
253272that 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
282301window's global object, then run all ` <script> ` tags together within the context
283302of that sandbox.
284303
304+ The provided ` name ` and ` origin ` of the context are made visible through the
305+ Inspector API.
306+
285307## vm.isContext(sandbox)
286308<!-- YAML
287309added: v0.11.7
@@ -385,6 +407,15 @@ added: v0.3.1
385407 * ` timeout ` {number} Specifies the number of milliseconds to execute ` code `
386408 before terminating execution. If execution is terminated, an [ ` Error ` ] [ ]
387409 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:** ` '' ` .
388419
389420The ` vm.runInNewContext() ` first contextifies the given ` sandbox ` object (or
390421creates 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
510541"contextifying" the ` sandbox ` .
511542
512543[ `Error` ] : errors.html#errors_class_error
544+ [ `URL` ] : url.html#url_class_url
513545[ `eval()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
514546[ `script.runInContext()` ] : #vm_script_runincontext_contextifiedsandbox_options
515547[ `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
517550[ `vm.runInContext()` ] : #vm_vm_runincontext_code_contextifiedsandbox_options
518551[ `vm.runInThisContext()` ] : #vm_vm_runinthiscontext_code_options
519552[ V8 Embedder's Guide ] : https://github.com/v8/v8/wiki/Embedder's%20Guide#contexts
520553[ command line option ] : cli.html
521554[ contextified ] : #vm_what_does_it_mean_to_contextify_an_object
522555[ global object ] : https://es5.github.io/#x15.1
523556[ indirect `eval()` call ] : https://es5.github.io/#x10.4.2
557+ [ origin ] : https://developer.mozilla.org/en-US/docs/Glossary/Origin
0 commit comments