Skip to content

Commit

Permalink
Work around node.js output flush bug nodejs/node-v0.x-archive#1669 to…
Browse files Browse the repository at this point in the history
… fix other.test_warn_undefined on Windows. The end of the output buffer would not get printed during the test, which would cause the test to fail. See also #2582
  • Loading branch information
juj committed Jul 31, 2014
1 parent 50708bc commit 6579bdb
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,29 @@ try {
}
}
} catch(err) {
printErr('Internal compiler error in src/compiler.js! Please raise a bug report at https://github.com/kripken/emscripten/issues/ with a log of the build and the input files used to run. Exception message: ' + err + ' | ' + err.stack);
if (ENVIRONMENT_IS_NODE) process.exit(1);
else throw err;
if (err.indexOf('Aborting compilation due to previous errors') != -1) {
// Compiler failed on user error, print out the error message.
printErr(err + ' | ' + err.stack);
} else {
// Compiler failed on internal compiler error!
printErr('Internal compiler error in src/compiler.js! Please raise a bug report at https://github.com/kripken/emscripten/issues/ with a log of the build and the input files used to run. Exception message: ' + err + ' | ' + err.stack);
}

if (ENVIRONMENT_IS_NODE) {
// Work around a node.js bug where stdout buffer is not flushed at process exit:
// Instead of process.exit() directly, wait for stdout flush event.
// See https://github.com/joyent/node/issues/1669 and https://github.com/kripken/emscripten/issues/2582
// Workaround is based on https://github.com/RReverser/acorn/commit/50ab143cecc9ed71a2d66f78b4aec3bb2e9844f6
process['stdout']['once']('drain', function () {
process['exit'](1);
});
console.log(' '); // Make sure to print something to force the drain event to occur, in case the stdout buffer was empty.
// Work around another node bug where sometimes 'drain' is never fired - make another effort
// to emit the exit status, after a significant delay (if node hasn't fired drain by then, give up)
setTimeout(function() {
process['exit'](1);
}, 500);
} else throw err;
}

//var M = keys(tokenCacheMisses).map(function(m) { return [m, misses[m]] }).sort(function(a, b) { return a[1] - b[1] });
Expand Down

0 comments on commit 6579bdb

Please sign in to comment.