mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Wait for STDOUT to be flushed before exiting the node runtime
This commit is contained in:
parent
2cac62d20d
commit
a6abf130c7
2 changed files with 15 additions and 8 deletions
|
@ -1,10 +1,13 @@
|
|||
(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
|
||||
}, function(program) {
|
||||
var output, print = function(string) {
|
||||
process.stdout.write('' + string);
|
||||
var __process__ = process;
|
||||
|
||||
var printFinal = function(string) {
|
||||
process.stdout.write('' + string, function() {
|
||||
__process__.exit(0);
|
||||
});
|
||||
};
|
||||
try {
|
||||
var __process__ = process;
|
||||
delete this.process;
|
||||
delete this.console;
|
||||
delete this.setTimeout;
|
||||
|
@ -16,17 +19,16 @@
|
|||
result = program();
|
||||
this.process = __process__;
|
||||
if (typeof result == 'undefined' && result !== null) {
|
||||
print('["ok"]');
|
||||
printFinal('["ok"]');
|
||||
} else {
|
||||
try {
|
||||
print(JSON.stringify(['ok', result]));
|
||||
printFinal(JSON.stringify(['ok', result]));
|
||||
} catch (err) {
|
||||
print(JSON.stringify(['err', '' + err, err.stack]));
|
||||
printFinal(JSON.stringify(['err', '' + err, err.stack]));
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
this.process = __process__;
|
||||
print(JSON.stringify(['err', '' + err, err.stack]));
|
||||
printFinal(JSON.stringify(['err', '' + err, err.stack]));
|
||||
}
|
||||
__process__.exit(0);
|
||||
});
|
||||
|
|
|
@ -306,6 +306,11 @@ class TestExecJS < Test
|
|||
assert ExecJS.exec("function foo() {\n#{body}\n};\nreturn true")
|
||||
end
|
||||
|
||||
def test_large_return_value
|
||||
string = ExecJS.eval('(new Array(100001)).join("abcdef")')
|
||||
assert_equal 600_000, string.size
|
||||
end
|
||||
|
||||
def test_exec_syntax_error
|
||||
begin
|
||||
ExecJS.exec(")")
|
||||
|
|
Loading…
Reference in a new issue