diff --git a/lib/execjs/support/node_runner.js b/lib/execjs/support/node_runner.js index 2987d9f..4c8cacf 100644 --- a/lib/execjs/support/node_runner.js +++ b/lib/execjs/support/node_runner.js @@ -1,20 +1,17 @@ -(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source} -}, function(program) { +(function(execJS) { execJS() })(function() { + var source = #{::JSON.dump(source)}; + source = "(function(){"+ source + "})()"; + var output, print = function(string) { process.stdout.write('' + string); }; try { - var __process__ = process; - delete this.process; - delete this.console; - delete this.setTimeout; - delete this.setInterval; - delete this.clearTimeout; - delete this.clearInterval; - delete this.setImmediate; - delete this.clearImmediate; + var program = function(){ + var vm = require('vm'); + var context = vm.createContext(); + return vm.runInNewContext(source, context, "(execjs)"); + } result = program(); - this.process = __process__; if (typeof result == 'undefined' && result !== null) { print('["ok"]'); } else { @@ -25,7 +22,6 @@ } } } catch (err) { - this.process = __process__; print(JSON.stringify(['err', '' + err, err.stack])); } });