diff --git a/lib/execjs/support/node_runner.js b/lib/execjs/support/node_runner.js index dc1b677..a70e20e 100644 --- a/lib/execjs/support/node_runner.js +++ b/lib/execjs/support/node_runner.js @@ -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); }); diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 1ff9319..99d8f0a 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -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(")")