From 5d9a7f81ae24a67a5085ead4ff3c1cbb08eff9e6 Mon Sep 17 00:00:00 2001 From: Gerhard Stoebich Date: Tue, 10 Apr 2018 10:21:56 +0200 Subject: [PATCH] doc: `vm.runIn*Context` can accept a string as options PR-URL: https://github.com/nodejs/node/pull/19910 Reviewed-By: Gus Caplan Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Vse Mozhet Byt Reviewed-By: Trivikram Kamat --- doc/api/vm.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/doc/api/vm.md b/doc/api/vm.md index 5c929714c501dc..aa52d7c02e54ad 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -630,7 +630,7 @@ Returns `true` if the given `sandbox` object has been [contextified][] using * `code` {string} The JavaScript code to compile and run. * `contextifiedSandbox` {Object} The [contextified][] object that will be used as the `global` when the `code` is compiled and run. -* `options` +* `options` {Object|string} * `filename` {string} Specifies the filename used in stack traces produced by this script. * `lineOffset` {number} Specifies the line number offset that is displayed @@ -649,6 +649,8 @@ the `contextifiedSandbox`, then returns the result. Running code does not have access to the local scope. The `contextifiedSandbox` object *must* have been 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 [contextified][] object: @@ -705,7 +707,7 @@ added: v0.3.1 * `code` {string} The JavaScript code to compile and run. * `sandbox` {Object} An object that will be [contextified][]. If `undefined`, a new object will be created. -* `options` +* `options` {Object|string} * `filename` {string} Specifies the filename used in stack traces produced by this script. * `lineOffset` {number} Specifies the line number offset that is displayed @@ -733,6 +735,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 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 variable and sets a new one. These globals are contained in the `sandbox`. @@ -757,7 +761,7 @@ added: v0.3.1 --> * `code` {string} The JavaScript code to compile and run. -* `options` +* `options` {Object|string} * `filename` {string} Specifies the filename used in stack traces produced by this script. * `lineOffset` {number} Specifies the line number offset that is displayed @@ -775,6 +779,8 @@ added: v0.3.1 current `global` and returns the result. Running code does not have access to 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 JavaScript [`eval()`][] function to run the same code: