doc: vm.runIn*Context can accept a string as options

PR-URL: https://github.com/nodejs/node/pull/19910
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Gerhard Stoebich 2018-04-10 10:21:56 +02:00 committed by Trivikram Kamat
parent a3db1cc514
commit 7ead832b5a

View File

@ -694,7 +694,7 @@ Returns `true` if the given `sandbox` object has been [contextified][] using
* `code` {string} The JavaScript code to compile and run. * `code` {string} The JavaScript code to compile and run.
* `contextifiedSandbox` {Object} The [contextified][] object that will be used * `contextifiedSandbox` {Object} The [contextified][] object that will be used
as the `global` when the `code` is compiled and run. as the `global` when the `code` is compiled and run.
* `options` * `options` {Object|string}
* `filename` {string} Specifies the filename used in stack traces produced * `filename` {string} Specifies the filename used in stack traces produced
by this script. by this script.
* `lineOffset` {number} Specifies the line number offset that is displayed * `lineOffset` {number} Specifies the line number offset that is displayed
@ -713,6 +713,8 @@ the `contextifiedSandbox`, then returns the result. Running code does not have
access to the local scope. The `contextifiedSandbox` object *must* have been access to the local scope. The `contextifiedSandbox` object *must* have been
previously [contextified][] using the [`vm.createContext()`][] method. previously [contextified][] using the [`vm.createContext()`][] method.
If `options` is a string, then it specifies the filename.
The following example compiles and executes different scripts using a single The following example compiles and executes different scripts using a single
[contextified][] object: [contextified][] object:
@ -739,7 +741,7 @@ added: v0.3.1
* `code` {string} The JavaScript code to compile and run. * `code` {string} The JavaScript code to compile and run.
* `sandbox` {Object} An object that will be [contextified][]. If `undefined`, a * `sandbox` {Object} An object that will be [contextified][]. If `undefined`, a
new object will be created. new object will be created.
* `options` * `options` {Object|string}
* `filename` {string} Specifies the filename used in stack traces produced * `filename` {string} Specifies the filename used in stack traces produced
by this script. by this script.
* `lineOffset` {number} Specifies the line number offset that is displayed * `lineOffset` {number} Specifies the line number offset that is displayed
@ -767,6 +769,8 @@ creates a new `sandbox` if passed as `undefined`), compiles the `code`, runs it
within the context of the created context, then returns the result. Running code within the context of the created context, then returns the result. Running code
does not have access to the local scope. does not have access to the local scope.
If `options` is a string, then it specifies the filename.
The following example compiles and executes code that increments a global The following example compiles and executes code that increments a global
variable and sets a new one. These globals are contained in the `sandbox`. variable and sets a new one. These globals are contained in the `sandbox`.
@ -791,7 +795,7 @@ added: v0.3.1
--> -->
* `code` {string} The JavaScript code to compile and run. * `code` {string} The JavaScript code to compile and run.
* `options` * `options` {Object|string}
* `filename` {string} Specifies the filename used in stack traces produced * `filename` {string} Specifies the filename used in stack traces produced
by this script. by this script.
* `lineOffset` {number} Specifies the line number offset that is displayed * `lineOffset` {number} Specifies the line number offset that is displayed
@ -809,6 +813,8 @@ added: v0.3.1
current `global` and returns the result. Running code does not have access to current `global` and returns the result. Running code does not have access to
local scope, but does have access to the current `global` object. local scope, but does have access to the current `global` object.
If `options` is a string, then it specifies the filename.
The following example illustrates using both `vm.runInThisContext()` and The following example illustrates using both `vm.runInThisContext()` and
the JavaScript [`eval()`][] function to run the same code: the JavaScript [`eval()`][] function to run the same code: