Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Fix return code from uncaught exception handler #70

Closed
wants to merge 1 commit into from
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
7 changes: 5 additions & 2 deletions src/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ bool OnUncaughtException(v8::Isolate* isolate) {
(commandline_string.find("abort_on_uncaught_exception") != std::string::npos)) {
return true; // abort required
}
// On V8 versions earlier than 5.4 we need to print the exception backtrace
// to stderr, as V8 does not do so (unless we trigger an abort, as above).
// On versions earlier than 5.4, V8 does not provide the default behaviour
// for uncaught exception on return from this callback. Default behaviour is
// to print a stack trace and exit with rc=1, so we need to mimic that here.
int v8_major, v8_minor;
if (sscanf(v8::V8::GetVersion(), "%d.%d", &v8_major, &v8_minor) == 2) {
if (v8_major < 5 || (v8_major == 5 && v8_minor < 4)) {
Expand All @@ -184,6 +185,8 @@ bool OnUncaughtException(v8::Isolate* isolate) {
// On other platforms use the Message API
Message::PrintCurrentStackTrace(isolate, stderr);
#endif
// exit direct from this callback with rc=1, to mimic V8 behaviour
exit(1);
}
}
return false;
Expand Down
8 changes: 1 addition & 7 deletions test/test-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ if (process.argv[2] === 'child') {
});
child.on('exit', (code) => {
tap.plan(4);
// Verify exit code. Note that behaviour changed in V8 v5.4
const v8_version = (process.versions.v8).match(/\d+/g);
if (v8_version[0] < 5 || (v8_version[0] == 5 && v8_version[1] < 4)) {
tap.equal(code, 0, 'Check for expected process exit code');
} else {
tap.equal(code, 1, 'Check for expected process exit code');
}
tap.equal(code, 1, 'Check for expected process exit code');
tap.match(stderr, /myException/,
'Check for expected stack trace frame in stderr');
const reports = common.findReports(child.pid);
Expand Down