summaryrefslogtreecommitdiff
path: root/src/inspector_io.cc
diff options
context:
space:
mode:
authorEugene Ostroukhov <eostroukhov@chromium.org>2017-05-31 15:14:52 -0700
committerEugene Ostroukhov <eostroukhov@chromium.org>2017-06-05 08:47:43 -0700
commite6dcc3dfa9dbbf59cf6f67425e47c47bea70fe2c (patch)
tree1b34b15cf54eba71bf5e3f21aa16d6e5c4ada01a /src/inspector_io.cc
parent5d9dc94509253845642e617f9d6d47ce0d09d7da (diff)
downloadnode-new-e6dcc3dfa9dbbf59cf6f67425e47c47bea70fe2c.tar.gz
inspector: Allows reentry when paused
This change allows reentering the message dispatch loop when the Node is paused. This is necessary when the pause happened as a result of the message sent by a debug frontend, such as evaluating a function with a breakpoint inside. Fixes: https://github.com/nodejs/node/issues/13320 PR-URL: https://github.com/nodejs/node/pull/13350 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_io.cc')
-rw-r--r--src/inspector_io.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/inspector_io.cc b/src/inspector_io.cc
index 9766faa39a..a558205a18 100644
--- a/src/inspector_io.cc
+++ b/src/inspector_io.cc
@@ -134,7 +134,7 @@ std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string& message) {
class IoSessionDelegate : public InspectorSessionDelegate {
public:
explicit IoSessionDelegate(InspectorIo* io) : io_(io) { }
- bool WaitForFrontendMessage() override;
+ bool WaitForFrontendMessageWhilePaused() override;
void SendMessageToFrontend(const v8_inspector::StringView& message) override;
private:
InspectorIo* io_;
@@ -354,7 +354,8 @@ void InspectorIo::PostIncomingMessage(InspectorAction action, int session_id,
NotifyMessageReceived();
}
-void InspectorIo::WaitForIncomingMessage() {
+void InspectorIo::WaitForFrontendMessageWhilePaused() {
+ dispatching_messages_ = false;
Mutex::ScopedLock scoped_lock(state_lock_);
if (incoming_message_queue_.empty())
incoming_message_cond_.Wait(scoped_lock);
@@ -373,11 +374,15 @@ void InspectorIo::DispatchMessages() {
if (dispatching_messages_)
return;
dispatching_messages_ = true;
- MessageQueue<InspectorAction> tasks;
+ bool had_messages = false;
do {
- tasks.clear();
- SwapBehindLock(&incoming_message_queue_, &tasks);
- for (const auto& task : tasks) {
+ if (dispatching_message_queue_.empty())
+ SwapBehindLock(&incoming_message_queue_, &dispatching_message_queue_);
+ had_messages = !dispatching_message_queue_.empty();
+ while (!dispatching_message_queue_.empty()) {
+ MessageQueue<InspectorAction>::value_type task;
+ std::swap(dispatching_message_queue_.front(), task);
+ dispatching_message_queue_.pop_front();
StringView message = std::get<2>(task)->string();
switch (std::get<0>(task)) {
case InspectorAction::kStartSession:
@@ -404,7 +409,7 @@ void InspectorIo::DispatchMessages() {
break;
}
}
- } while (!tasks.empty());
+ } while (had_messages);
dispatching_messages_ = false;
}
@@ -485,8 +490,8 @@ std::string InspectorIoDelegate::GetTargetUrl(const std::string& id) {
return "file://" + script_path_;
}
-bool IoSessionDelegate::WaitForFrontendMessage() {
- io_->WaitForIncomingMessage();
+bool IoSessionDelegate::WaitForFrontendMessageWhilePaused() {
+ io_->WaitForFrontendMessageWhilePaused();
return true;
}