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 a8e0781
Show file tree
Hide file tree
Showing 2 changed files with 25 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
16 changes: 16 additions & 0 deletions test/test_execjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,20 @@ def test_uglify
assert_equal "function foo(bar){return bar}",
context.call("uglify", "function foo(bar) {\n return bar;\n}")
end

def test_node_runtime_with_compiler_writing_to_stdio
skip if not ExecJS.runtime.name =~ /Node/

source = <<-JS
process.stdout.write('WARNING');
process.stderr.write('ERROR');
function compile(code) {
return code;
}
JS

context = ExecJS.compile(source)
assert_equal "foo()", context.call("compile", "foo()")
end
end

0 comments on commit a8e0781

Please sign in to comment.