Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Node.js compilers writing to STDOUT and/or STDERR during compilation #42

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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