File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -212,8 +212,24 @@ that sandbox][contextified] so that it can be used in calls to
212212[ ` vm.runInContext() ` ] [ ] or [ ` script.runInContext() ` ] [ ] . Inside such scripts,
213213the ` sandbox ` object will be the global object, retaining all of its existing
214214properties but also having the built-in objects and functions any standard
215- [ global object] [ ] has. Outside of scripts run by the vm module, ` sandbox ` will
216- remain unchanged.
215+ [ global object] [ ] has. Outside of scripts run by the vm module, global variables
216+ will remain unchanged.
217+
218+ ``` js
219+ const util = require (' util' );
220+ const vm = require (' vm' );
221+
222+ var globalVar = 3 ;
223+
224+ const sandbox = { globalVar: 1 };
225+ vm .createContext (sandbox);
226+
227+ vm .runInContext (' globalVar *= 2;' , sandbox);
228+
229+ console .log (util .inspect (sandbox)); // 2
230+
231+ console .log (util .inspect (globalVar)); // 3
232+ ```
217233
218234If ` sandbox ` is omitted (or passed explicitly as ` undefined ` ), a new, empty
219235[ contextified] [ ] sandbox object will be returned.
You can’t perform that action at this time.
0 commit comments