Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created February 11, 2013 16:54
Show Gist options
  • Save geNAZt/4755698 to your computer and use it in GitHub Desktop.
Save geNAZt/4755698 to your computer and use it in GitHub Desktop.
var vm = require('vm'),
ctx = vm.createContext({setTimeout: setTimeout, console: console}),
script = vm.createScript("now = 1; setTimeout(function() { now = 2; console.log('Inside the VM: ' + now); }, 1000);");
script.runInContext(ctx);
setInterval(function () {
console.log("Outside the VM: " + ctx.now);
}, 500);
@geNAZt
Copy link
Author

geNAZt commented Feb 11, 2013

Outside the VM: 1
Outside the VM: 1
Inside the VM: 2
Outside the VM: 1
Outside the VM: 1
Outside the VM: 1
Outside the VM: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment