summaryrefslogtreecommitdiff
path: root/src/inspector_agent.cc
diff options
context:
space:
mode:
authorShelley Vohr <shelley.vohr@gmail.com>2022-02-24 00:32:30 +0100
committerGitHub <noreply@github.com>2022-02-23 23:32:30 +0000
commit0367b5c35ea0f98b323175a4aaa8e651af7a91e7 (patch)
tree7df0351688e59aa7fd8d90e7585486dbe9d753cb /src/inspector_agent.cc
parent7efef7458573281db07327bbc3408f7806466468 (diff)
downloadnode-new-0367b5c35ea0f98b323175a4aaa8e651af7a91e7.tar.gz
src: allow preventing InitializeInspector in env
PR-URL: https://github.com/nodejs/node/pull/35025 Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_agent.cc')
-rw-r--r--src/inspector_agent.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index fd9f514b9b..5fc533741d 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -368,6 +368,16 @@ bool IsFilePath(const std::string& path) {
}
#endif // __POSIX__
+void ThrowUninitializedInspectorError(Environment* env) {
+ HandleScope scope(env->isolate());
+
+ const char* msg = "This Environment was initialized without a V8::Inspector";
+ Local<Value> exception =
+ v8::String::NewFromUtf8(env->isolate(), msg).ToLocalChecked();
+
+ env->isolate()->ThrowException(exception);
+}
+
} // namespace
class NodeInspectorClient : public V8InspectorClient {
@@ -728,6 +738,11 @@ bool Agent::StartIoThread() {
if (io_ != nullptr)
return true;
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return false;
+ }
+
CHECK_NOT_NULL(client_);
io_ = InspectorIo::Start(client_->getThreadHandle(),
@@ -748,7 +763,13 @@ void Agent::Stop() {
std::unique_ptr<InspectorSession> Agent::Connect(
std::unique_ptr<InspectorSessionDelegate> delegate,
bool prevent_shutdown) {
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return std::unique_ptr<InspectorSession>{};
+ }
+
CHECK_NOT_NULL(client_);
+
int session_id = client_->connectFrontend(std::move(delegate),
prevent_shutdown);
return std::unique_ptr<InspectorSession>(
@@ -758,6 +779,11 @@ std::unique_ptr<InspectorSession> Agent::Connect(
std::unique_ptr<InspectorSession> Agent::ConnectToMainThread(
std::unique_ptr<InspectorSessionDelegate> delegate,
bool prevent_shutdown) {
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return std::unique_ptr<InspectorSession>{};
+ }
+
CHECK_NOT_NULL(parent_handle_);
CHECK_NOT_NULL(client_);
auto thread_safe_delegate =
@@ -767,6 +793,11 @@ std::unique_ptr<InspectorSession> Agent::ConnectToMainThread(
}
void Agent::WaitForDisconnect() {
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return;
+ }
+
CHECK_NOT_NULL(client_);
bool is_worker = parent_handle_ != nullptr;
parent_handle_.reset();
@@ -912,6 +943,12 @@ void Agent::SetParentHandle(
std::unique_ptr<ParentInspectorHandle> Agent::GetParentHandle(
uint64_t thread_id, const std::string& url) {
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return std::unique_ptr<ParentInspectorHandle>{};
+ }
+
+ CHECK_NOT_NULL(client_);
if (!parent_handle_) {
return client_->getWorkerManager()->NewParentHandle(thread_id, url);
} else {
@@ -920,11 +957,21 @@ std::unique_ptr<ParentInspectorHandle> Agent::GetParentHandle(
}
void Agent::WaitForConnect() {
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return;
+ }
+
CHECK_NOT_NULL(client_);
client_->waitForFrontend();
}
std::shared_ptr<WorkerManager> Agent::GetWorkerManager() {
+ if (!parent_env_->should_create_inspector() && !client_) {
+ ThrowUninitializedInspectorError(parent_env_);
+ return std::unique_ptr<WorkerManager>{};
+ }
+
CHECK_NOT_NULL(client_);
return client_->getWorkerManager();
}