mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Merge branch 'node_vm' of https://github.com/jhawthorn/execjs into jhawthorn-node_vm
This commit is contained in:
commit
08e7cd6456
1 changed files with 9 additions and 13 deletions
|
@ -1,20 +1,17 @@
|
||||||
(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
|
(function(execJS) { execJS() })(function() {
|
||||||
}, function(program) {
|
var source = #{::JSON.dump(source)};
|
||||||
|
source = "(function(){"+ source + "})()";
|
||||||
|
|
||||||
var output, print = function(string) {
|
var output, print = function(string) {
|
||||||
process.stdout.write('' + string);
|
process.stdout.write('' + string);
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
var __process__ = process;
|
var program = function(){
|
||||||
delete this.process;
|
var vm = require('vm');
|
||||||
delete this.console;
|
var context = vm.createContext();
|
||||||
delete this.setTimeout;
|
return vm.runInNewContext(source, context, "(execjs)");
|
||||||
delete this.setInterval;
|
}
|
||||||
delete this.clearTimeout;
|
|
||||||
delete this.clearInterval;
|
|
||||||
delete this.setImmediate;
|
|
||||||
delete this.clearImmediate;
|
|
||||||
result = program();
|
result = program();
|
||||||
this.process = __process__;
|
|
||||||
if (typeof result == 'undefined' && result !== null) {
|
if (typeof result == 'undefined' && result !== null) {
|
||||||
print('["ok"]');
|
print('["ok"]');
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +22,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.process = __process__;
|
|
||||||
print(JSON.stringify(['err', '' + err, err.stack]));
|
print(JSON.stringify(['err', '' + err, err.stack]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue