File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ code does not have access to local scope, but does have access to the current
1919
2020Example of using ` vm.runInThisContext ` and ` eval ` to run the same code:
2121
22+ var vm = require('vm');
2223 var localVar = 'initial value';
2324
2425 var vmResult = vm.runInThisContext('localVar = "vm";');
@@ -117,7 +118,7 @@ Example: compile and execute code that increments a global variable and sets a
117118new one. These globals are contained in the sandbox.
118119
119120 var util = require('util');
120- var vm = require('vm'),
121+ var vm = require('vm');
121122
122123 var sandbox = {
123124 animal: 'cat',
@@ -223,10 +224,11 @@ execute the code multiple times. These globals are contained in the sandbox.
223224 count: 2
224225 };
225226
227+ var context = new vm.createContext(sandbox);
226228 var script = new vm.Script('count += 1; name = "kitty"');
227229
228230 for (var i = 0; i < 10; ++i) {
229- script.runInContext(sandbox );
231+ script.runInContext(context );
230232 }
231233
232234 console.log(util.inspect(sandbox));
You can’t perform that action at this time.
0 commit comments