Skip to content

Commit

Permalink
Fixes Node.js compilers writing to STDOUT and/or STDERR during compil…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
alexgorbatchev committed Jun 1, 2016
1 parent 4f2fc87 commit 029378b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/execjs/support/node_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions test/test_execjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 029378b

Please sign in to comment.