Skip to content

Commit 7a5b023

Browse files
fundonbnoordhuis
authored andcommitted
doc: fix vm module examples
PR-URL: #1147 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 7bde3f1 commit 7a5b023

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

doc/api/vm.markdown

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ code does not have access to local scope, but does have access to the current
1919

2020
Example 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
117118
new 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));

0 commit comments

Comments
 (0)