Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,12 @@ std::unique_ptr<InspectorSession> Agent::ConnectToMainThread(
ThrowUninitializedInspectorError(parent_env_);
return std::unique_ptr<InspectorSession>{};
}
if (!parent_handle_) {
THROW_ERR_INSPECTOR_NOT_AVAILABLE(
parent_env_, "The parent thread's inspector is not available");
return std::unique_ptr<InspectorSession>{};
}

CHECK_NOT_NULL(parent_handle_);
CHECK_NOT_NULL(client_);
auto thread_safe_delegate =
client_->getThreadHandle()->MakeDelegateThreadSafe(std::move(delegate));
Expand Down
1 change: 1 addition & 0 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
V(ERR_HEAP_PROFILE_HAVE_BEEN_STARTED, Error) \
V(ERR_HEAP_PROFILE_NOT_STARTED, Error) \
V(ERR_ILLEGAL_CONSTRUCTOR, Error) \
V(ERR_INSPECTOR_NOT_AVAILABLE, Error) \
V(ERR_INVALID_ADDRESS, Error) \
V(ERR_INVALID_ARG_VALUE, TypeError) \
V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \
Expand Down
21 changes: 21 additions & 0 deletions test/cctest/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,27 @@ TEST_F(EnvironmentTest, CollectExternalReferencesFromSeveralThreads) {
EXPECT_EQ(node::SnapshotBuilder::CollectExternalReferences().back(), 0);
}

#if HAVE_INSPECTOR
TEST_F(EnvironmentTest, WorkerConnectToMainThreadWithoutInspector) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env{handle_scope, argv, node::EnvironmentFlags::kNoCreateInspector};
node::LoadEnvironment(
*env,
"const { Worker } = require('worker_threads');"
"const w = new Worker(`"
" const { Session } = require('inspector');"
" try { new Session().connectToMainThread(); }"
" catch (e) { process.exit(e.code === 'ERR_INSPECTOR_NOT_AVAILABLE' ?"
" 0 : 2); }"
" process.exit(3);"
"`, { eval: true });"
"w.on('exit', (code) => { process.exitCode = code; });")
.ToLocalChecked();
EXPECT_EQ(node::SpinEventLoop(*env).FromJust(), 0);
}
#endif // HAVE_INSPECTOR

TEST_F(EnvironmentTest, NoEnvironmentSanity) {
const v8::HandleScope handle_scope(isolate_);
v8::Local<v8::Context> context = v8::Context::New(isolate_);
Expand Down
Loading