1
0
Fork 0
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:
Jean Boussier 2021-05-14 08:56:09 +02:00
parent 2cac62d20d
commit a6abf130c7
2 changed files with 15 additions and 8 deletions

View file

@ -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, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
}, function(program) { }, function(program) {
var output, print = function(string) { var __process__ = process;
process.stdout.write('' + string);
var printFinal = function(string) {
process.stdout.write('' + string, function() {
__process__.exit(0);
});
}; };
try { try {
var __process__ = process;
delete this.process; delete this.process;
delete this.console; delete this.console;
delete this.setTimeout; delete this.setTimeout;
@ -16,17 +19,16 @@
result = program(); result = program();
this.process = __process__; this.process = __process__;
if (typeof result == 'undefined' && result !== null) { if (typeof result == 'undefined' && result !== null) {
print('["ok"]'); printFinal('["ok"]');
} else { } else {
try { try {
print(JSON.stringify(['ok', result])); printFinal(JSON.stringify(['ok', result]));
} catch (err) { } catch (err) {
print(JSON.stringify(['err', '' + err, err.stack])); printFinal(JSON.stringify(['err', '' + err, err.stack]));
} }
} }
} catch (err) { } catch (err) {
this.process = __process__; this.process = __process__;
print(JSON.stringify(['err', '' + err, err.stack])); printFinal(JSON.stringify(['err', '' + err, err.stack]));
} }
__process__.exit(0);
}); });

View file

@ -306,6 +306,11 @@ class TestExecJS < Test
assert ExecJS.exec("function foo() {\n#{body}\n};\nreturn true") assert ExecJS.exec("function foo() {\n#{body}\n};\nreturn true")
end 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 def test_exec_syntax_error
begin begin
ExecJS.exec(")") ExecJS.exec(")")