Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Created July 12, 2012 02:58
Show Gist options
  • Save kevinohara80/3095399 to your computer and use it in GitHub Desktop.
Save kevinohara80/3095399 to your computer and use it in GitHub Desktop.
setTimeout infinite loop
var vm = require('vm');
var code = function run() {
for(var i=0; i<Infinity; i++) {
i++;
}
};
var sandbox = {
setTimeout: setTimeout
}
code = 'setTimeout(function(){throw new Error(\'timeout\')}, 2000);' + ' \n' + code;
code = code + '\nrun();';
console.log(code);
var script = vm.createScript(code);
script.runInNewContext(sandbox);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment