diff --git a/lib/execjs/support/node_runner.js b/lib/execjs/support/node_runner.js index ab0c6ec..d3e3551 100644 --- a/lib/execjs/support/node_runner.js +++ b/lib/execjs/support/node_runner.js @@ -4,7 +4,16 @@ process.stdout.write('' + string); }; try { + var stdoutWrite = process.stdout.write; + var stderrWrite = process.stderr.write; + + process.stdout.write = process.stderr.write = function () {} + result = program(); + + process.stdout.write = stdoutWrite; + process.stderr.write = stderrWrite; + if (typeof result == 'undefined' && result !== null) { print('["ok"]'); } else { diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 7fd967f..6f9b6fe 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -376,4 +376,30 @@ def test_uglify assert_equal "function foo(bar){return bar}", context.call("uglify", "function foo(bar) {\n return bar;\n}") end + + def test_compiler_writing_to_stdout + skip if ExecJS.runtime.is_a?(ExecJS::RubyRhinoRuntime) + + ENV['EXECJS_RUNTIME'] = 'Node' + + old_runtime = ExecJS.runtime.to_s + ExecJS.runtime = ExecJS::Runtimes.from_environment + + source = <<-JS + process.stdout.write('WARNING'); + process.stderr.write('ERROR'); + + function compile(code) { + return code; + } + JS + + begin + context = ExecJS.compile(source) + assert_equal "foo()", context.call("compile", "foo()") + ensure + ENV['EXECJS_RUNTIME'] = nil + ExecJS.runtime = ExecJS::Runtimes.autodetect + end + end end