summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-09-19 11:36:02 +0900
committerMichaƫl Zasso <targos@protonmail.com>2019-10-01 14:37:22 +0200
commita86b71f745599435df94b35a5c96ba0f29a45c9d (patch)
tree2ce306f4ecd5b8ce0bb2a49ff758008c6ff72ff4
parent8d880102778b4b57d1bf29f73c5b4309d8ac7059 (diff)
downloadnode-new-a86b71f745599435df94b35a5c96ba0f29a45c9d.tar.gz
src: disconnect inspector before exiting out of fatal exception
So that coverage, .etc are properly written in case of a normal fatal exception. PR-URL: https://github.com/nodejs/node/pull/29611 Fixes: https://github.com/nodejs/node/issues/29570 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com>
-rw-r--r--src/node_errors.cc3
-rw-r--r--test/fixtures/v8-coverage/throw.js7
-rw-r--r--test/parallel/test-v8-coverage.js18
3 files changed, 28 insertions, 0 deletions
diff --git a/src/node_errors.cc b/src/node_errors.cc
index 26ecbc566d..d3a409b1ab 100644
--- a/src/node_errors.cc
+++ b/src/node_errors.cc
@@ -980,6 +980,9 @@ void TriggerUncaughtException(Isolate* isolate,
// Now we are certain that the exception is fatal.
ReportFatalException(env, error, message, EnhanceFatalException::kEnhance);
+#if HAVE_INSPECTOR
+ profiler::EndStartedProfilers(env);
+#endif
// If the global uncaught exception handler sets process.exitCode,
// exit with that code. Otherwise, exit with 1.
diff --git a/test/fixtures/v8-coverage/throw.js b/test/fixtures/v8-coverage/throw.js
new file mode 100644
index 0000000000..7436fc9978
--- /dev/null
+++ b/test/fixtures/v8-coverage/throw.js
@@ -0,0 +1,7 @@
+const a = 99;
+if (true) {
+ const b = 101;
+} else {
+ const c = 102;
+}
+throw new Error('test');
diff --git a/test/parallel/test-v8-coverage.js b/test/parallel/test-v8-coverage.js
index 02ace7af9c..2e70ce91fe 100644
--- a/test/parallel/test-v8-coverage.js
+++ b/test/parallel/test-v8-coverage.js
@@ -35,6 +35,24 @@ function nextdir() {
assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0);
}
+// Outputs coverage when error is thrown in first tick.
+{
+ const coverageDirectory = path.join(tmpdir.path, nextdir());
+ const output = spawnSync(process.execPath, [
+ require.resolve('../fixtures/v8-coverage/throw')
+ ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
+ if (output.status !== 1) {
+ console.log(output.stderr.toString());
+ }
+ assert.strictEqual(output.status, 1);
+ const fixtureCoverage = getFixtureCoverage('throw.js', coverageDirectory);
+ assert.ok(fixtureCoverage, 'coverage not found for file');
+ // First branch executed.
+ assert.strictEqual(fixtureCoverage.functions[0].ranges[0].count, 1);
+ // Second branch did not execute.
+ assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0);
+}
+
// Outputs coverage when process.exit(1) exits process.
{
const coverageDirectory = path.join(tmpdir.path, nextdir());