Skip to content

Commit

Permalink
inspector: code cleanup
Browse files Browse the repository at this point in the history
1. Do not rely on a string comparison to identify when
   the frontend is ready to run and override a callback instead.
2. Remove unused boolean flag.

PR-URL: #27591
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com>
  • Loading branch information
Eugene Ostroukhov authored and targos committed May 10, 2019
1 parent 2f512e3 commit d2d3bf8
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
worker_agent_.reset(); // Dispose before the dispatchers
}

std::string dispatchProtocolMessage(const StringView& message) {
void dispatchProtocolMessage(const StringView& message) {
std::string raw_message = protocol::StringUtil::StringViewToUtf8(message);
std::unique_ptr<protocol::DictionaryValue> value =
protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage(
Expand All @@ -252,7 +252,6 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
node_dispatcher_->dispatch(call_id, method, std::move(value),
raw_message);
}
return method;
}

void schedulePauseOnNextStatement(const std::string& reason) {
Expand Down Expand Up @@ -494,9 +493,12 @@ class NodeInspectorClient : public V8InspectorClient {
waiting_for_resume_ = false;
}

void runIfWaitingForDebugger(int context_group_id) override {
waiting_for_frontend_ = false;
}

int connectFrontend(std::unique_ptr<InspectorSessionDelegate> delegate,
bool prevent_shutdown) {
events_dispatched_ = true;
int session_id = next_session_id_++;
channels_[session_id] = std::make_unique<ChannelImpl>(env_,
client_,
Expand All @@ -508,16 +510,11 @@ class NodeInspectorClient : public V8InspectorClient {
}

void disconnectFrontend(int session_id) {
events_dispatched_ = true;
channels_.erase(session_id);
}

void dispatchMessageFromFrontend(int session_id, const StringView& message) {
events_dispatched_ = true;
std::string method =
channels_[session_id]->dispatchProtocolMessage(message);
if (waiting_for_frontend_)
waiting_for_frontend_ = method != "Runtime.runIfWaitingForDebugger";
channels_[session_id]->dispatchProtocolMessage(message);
}

Local<Context> ensureDefaultContextInGroup(int contextGroupId) override {
Expand Down Expand Up @@ -678,7 +675,6 @@ class NodeInspectorClient : public V8InspectorClient {
std::unordered_map<int, std::unique_ptr<ChannelImpl>> channels_;
std::unordered_map<void*, InspectorTimerHandle> timers_;
int next_session_id_ = 1;
bool events_dispatched_ = false;
bool waiting_for_resume_ = false;
bool waiting_for_frontend_ = false;
bool waiting_for_io_shutdown_ = false;
Expand Down

0 comments on commit d2d3bf8

Please sign in to comment.