Skip to content
Closed
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
inspector: reduce InspectorIo API surface
This is a cleanup, allowing for a better separation of concerns.
  • Loading branch information
eugeneo committed Jul 3, 2019
commit 71eb9afd36d10bc76d189dbff4831b43e95b1e44
8 changes: 6 additions & 2 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,12 @@ std::shared_ptr<WorkerManager> Agent::GetWorkerManager() {
return client_->getWorkerManager();
}

std::string Agent::GetWsUrl() const {
if (io_ == nullptr)
return "";
return io_->GetWsUrl();
}

SameThreadInspectorSession::~SameThreadInspectorSession() {
auto client = client_.lock();
if (client)
Expand All @@ -990,7 +996,5 @@ void SameThreadInspectorSession::Dispatch(
client->dispatchMessageFromFrontend(session_id_, message);
}



} // namespace inspector
} // namespace node
4 changes: 1 addition & 3 deletions src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ class Agent {

void PauseOnNextJavascriptStatement(const std::string& reason);

InspectorIo* io() {
return io_.get();
}
std::string GetWsUrl() const;

// Can only be called from the main thread.
bool StartIoThread();
Expand Down
13 changes: 5 additions & 8 deletions src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace {
using v8_inspector::StringBuffer;
using v8_inspector::StringView;

// kKill closes connections and stops the server, kStop only stops the server
enum class TransportAction { kKill, kSendMessage, kStop };

std::string ScriptPath(uv_loop_t* loop, const std::string& script_name) {
std::string script_path;

Expand Down Expand Up @@ -177,12 +180,6 @@ class RequestQueue {
data_->Post(session_id, action, std::move(message));
}

void SetServer(InspectorSocketServer* server) {
Mutex::ScopedLock scoped_lock(lock_);
if (data_ != nullptr)
data_->SetServer(server);
}

bool Expired() {
Mutex::ScopedLock scoped_lock(lock_);
return data_ == nullptr;
Expand Down Expand Up @@ -315,8 +312,8 @@ void InspectorIo::ThreadMain() {
CheckedUvLoopClose(&loop);
}

std::vector<std::string> InspectorIo::GetTargetIds() const {
return { id_ };
std::string InspectorIo::GetWsUrl() const {
return FormatWsAddress(host_port_->host(), host_port_->port(), id_, true);
}

InspectorIoDelegate::InspectorIoDelegate(
Expand Down
22 changes: 1 addition & 21 deletions src/inspector_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,14 @@
#include <cstddef>
#include <memory>


namespace v8_inspector {
class StringBuffer;
class StringView;
} // namespace v8_inspector

namespace node {
// Forward declaration to break recursive dependency chain with src/env.h.
class Environment;
namespace inspector {

std::string FormatWsAddress(const std::string& host, int port,
const std::string& target_id,
bool include_protocol);

class InspectorIoDelegate;
class MainThreadHandle;
class RequestQueue;

// kKill closes connections and stops the server, kStop only stops the server
enum class TransportAction {
kKill,
kSendMessage,
kStop
};

class InspectorIo {
public:
// Start the inspector agent thread, waiting for it to initialize
Expand All @@ -55,9 +37,7 @@ class InspectorIo {
~InspectorIo();

void StopAcceptingNewConnections();
const std::string& host() const { return host_port_->host(); }
int port() const { return host_port_->port(); }
std::vector<std::string> GetTargetIds() const;
std::string GetWsUrl() const;

private:
InspectorIo(std::shared_ptr<MainThreadHandle> handle,
Expand Down
14 changes: 4 additions & 10 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,10 @@ void Open(const FunctionCallbackInfo<Value>& args) {

void Url(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Agent* agent = env->inspector_agent();
InspectorIo* io = agent->io();

if (!io) return;

std::vector<std::string> ids = io->GetTargetIds();

if (ids.empty()) return;

std::string url = FormatWsAddress(io->host(), io->port(), ids[0], true);
std::string url = env->inspector_agent()->GetWsUrl();
if (url.length() == 0) {
return;
}
args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str()));
}

Expand Down
4 changes: 4 additions & 0 deletions src/inspector_socket_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
namespace node {
namespace inspector {

std::string FormatWsAddress(const std::string& host, int port,
const std::string& target_id,
bool include_protocol);

class InspectorSocketServer;
class SocketSession;
class ServerSocket;
Expand Down