diff --git a/src/api/environment.cc b/src/api/environment.cc index 8e5caac20bd3a6..a99201e76218cd 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -43,6 +43,7 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) { Environment* env = Environment::GetCurrent(isolate); return env != nullptr && (env->is_main_thread() || !env->is_stopping()) && + env->abort_on_uncaught_exception() && env->should_abort_on_uncaught_toggle()[0] && !env->inside_should_not_abort_on_uncaught_scope(); } diff --git a/src/env.cc b/src/env.cc index eb0fb2992502b9..58681cdcccc12d 100644 --- a/src/env.cc +++ b/src/env.cc @@ -359,7 +359,7 @@ Environment::Environment(IsolateData* isolate_data, inspector_host_port_.reset( new ExclusiveAccess(options_->debug_options().host_port)); - if (flags & EnvironmentFlags::kOwnsProcessState) { + if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) { set_abort_on_uncaught_exception(false); } diff --git a/test/parallel/test-worker-abort-on-uncaught-exception.js b/test/parallel/test-worker-abort-on-uncaught-exception.js new file mode 100644 index 00000000000000..7518d37552f24b --- /dev/null +++ b/test/parallel/test-worker-abort-on-uncaught-exception.js @@ -0,0 +1,12 @@ +// Flags: --abort-on-uncaught-exception +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker } = require('worker_threads'); + +// Tests that --abort-on-uncaught-exception does not apply to +// Workers. + +const w = new Worker('throw new Error()', { eval: true }); +w.on('error', common.mustCall()); +w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));