Skip to content

Commit

Permalink
inspector: stop dragging platform pointer
Browse files Browse the repository at this point in the history
It is now easily accessible from the Environment

Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
  • Loading branch information
eugeneo authored and targos committed Jun 15, 2018
1 parent df0f7a3 commit 296fd57
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 37 deletions.
27 changes: 9 additions & 18 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ class InspectorTimerHandle {

class NodeInspectorClient : public V8InspectorClient {
public:
NodeInspectorClient(node::Environment* env, node::NodePlatform* platform)
: env_(env), platform_(platform) {
explicit NodeInspectorClient(node::Environment* env) : env_(env) {
client_ = V8Inspector::create(env->isolate(), this);
// TODO(bnoordhuis) Make name configurable from src/node.cc.
ContextInfo info(GetHumanReadableProcessName());
Expand All @@ -346,8 +345,9 @@ class NodeInspectorClient : public V8InspectorClient {
return;
terminated_ = false;
running_nested_loop_ = true;
MultiIsolatePlatform* platform = env_->isolate_data()->platform();
while ((ignore_terminated || !terminated_) && waitForFrontendEvent()) {
while (platform_->FlushForegroundTasks(env_->isolate())) {}
while (platform->FlushForegroundTasks(env_->isolate())) {}
}
terminated_ = false;
running_nested_loop_ = false;
Expand Down Expand Up @@ -514,7 +514,6 @@ class NodeInspectorClient : public V8InspectorClient {

private:
node::Environment* env_;
node::NodePlatform* platform_;
bool terminated_ = false;
bool running_nested_loop_ = false;
std::unique_ptr<V8Inspector> client_;
Expand All @@ -524,25 +523,17 @@ class NodeInspectorClient : public V8InspectorClient {
bool events_dispatched_ = false;
};

Agent::Agent(Environment* env) : parent_env_(env),
client_(nullptr),
platform_(nullptr),
pending_enable_async_hook_(false),
pending_disable_async_hook_(false) {}
Agent::Agent(Environment* env) : parent_env_(env) {}

// Destructor needs to be defined here in implementation file as the header
// does not have full definition of some classes.
Agent::~Agent() {
}

bool Agent::Start(node::NodePlatform* platform, const char* path,
const DebugOptions& options) {
bool Agent::Start(const char* path, const DebugOptions& options) {
path_ = path == nullptr ? "" : path;
debug_options_ = options;
client_ =
std::shared_ptr<NodeInspectorClient>(
new NodeInspectorClient(parent_env_, platform));
platform_ = platform;
client_ = std::make_shared<NodeInspectorClient>(parent_env_);
CHECK_EQ(0, uv_async_init(uv_default_loop(),
&start_io_thread_async,
StartIoThreadAsyncCallback));
Expand All @@ -565,8 +556,7 @@ bool Agent::StartIoThread(bool wait_for_connect) {
CHECK_NOT_NULL(client_);

io_ = std::unique_ptr<InspectorIo>(
new InspectorIo(parent_env_, platform_, path_, debug_options_,
wait_for_connect));
new InspectorIo(parent_env_, path_, debug_options_, wait_for_connect));
if (!io_->Start()) {
client_.reset();
return false;
Expand Down Expand Up @@ -716,7 +706,8 @@ void Agent::RequestIoThreadStart() {
// for IO events)
uv_async_send(&start_io_thread_async);
v8::Isolate* isolate = parent_env_->isolate();
platform_->CallOnForegroundThread(isolate, new StartIoTask(this));
v8::Platform* platform = parent_env_->isolate_data()->platform();
platform->CallOnForegroundThread(isolate, new StartIoTask(this));
isolate->RequestInterrupt(StartIoInterrupt, this);
uv_async_send(&start_io_thread_async);
}
Expand Down
8 changes: 3 additions & 5 deletions src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class Agent {
~Agent();

// Create client_, may create io_ if option enabled
bool Start(node::NodePlatform* platform, const char* path,
const DebugOptions& options);
bool Start(const char* path, const DebugOptions& options);
// Stop and destroy io_
void Stop();

Expand Down Expand Up @@ -108,12 +107,11 @@ class Agent {
node::Environment* parent_env_;
std::shared_ptr<NodeInspectorClient> client_;
std::unique_ptr<InspectorIo> io_;
v8::Platform* platform_;
std::string path_;
DebugOptions debug_options_;

bool pending_enable_async_hook_;
bool pending_disable_async_hook_;
bool pending_enable_async_hook_ = false;
bool pending_disable_async_hook_ = false;
node::Persistent<v8::Function> enable_async_hook_function_;
node::Persistent<v8::Function> disable_async_hook_function_;
};
Expand Down
8 changes: 4 additions & 4 deletions src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ class DispatchMessagesTask : public v8::Task {
Agent* agent_;
};

InspectorIo::InspectorIo(Environment* env, v8::Platform* platform,
const std::string& path, const DebugOptions& options,
bool wait_for_connect)
InspectorIo::InspectorIo(Environment* env, const std::string& path,
const DebugOptions& options, bool wait_for_connect)
: options_(options), thread_(), state_(State::kNew),
parent_env_(env), thread_req_(), platform_(platform),
parent_env_(env), thread_req_(),
platform_(parent_env_->isolate_data()->platform()),
dispatching_messages_(false), script_name_(path),
wait_for_connect_(wait_for_connect), port_(-1),
id_(GenerateID()) {
Expand Down
8 changes: 4 additions & 4 deletions src/inspector_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ enum class TransportAction {

class InspectorIo {
public:
InspectorIo(node::Environment* env, v8::Platform* platform,
const std::string& path, const DebugOptions& options,
bool wait_for_connect);
InspectorIo(node::Environment* env, const std::string& path,
const DebugOptions& options, bool wait_for_connect);

~InspectorIo();
// Start the inspector agent thread, waiting for it to initialize,
Expand Down Expand Up @@ -142,7 +141,8 @@ class InspectorIo {
// Note that this will live while the async is being closed - likely, past
// the parent object lifespan
std::pair<uv_async_t, Agent*>* main_thread_req_;
v8::Platform* platform_;
// Will be used to post tasks from another thread
v8::Platform* const platform_;

// Message queues
ConditionVariable incoming_message_cond_;
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static struct {
// Inspector agent can't fail to start, but if it was configured to listen
// right away on the websocket port and fails to bind/etc, this will return
// false.
return env->inspector_agent()->Start(platform_, script_path, options);
return env->inspector_agent()->Start(script_path, options);
}

bool InspectorStarted(Environment* env) {
Expand Down
4 changes: 4 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class Environment;
class MultiIsolatePlatform : public v8::Platform {
public:
virtual ~MultiIsolatePlatform() { }
// Returns true if work was dispatched or executed. New tasks that are
// posted during flushing of the queue are postponed until the next
// flushing.
virtual bool FlushForegroundTasks(v8::Isolate* isolate) = 0;
virtual void DrainBackgroundTasks(v8::Isolate* isolate) = 0;
virtual void CancelPendingDelayedTasks(v8::Isolate* isolate) = 0;

Expand Down
6 changes: 1 addition & 5 deletions src/node_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ class NodePlatform : public MultiIsolatePlatform {
double MonotonicallyIncreasingTime() override;
double CurrentClockTimeMillis() override;
v8::TracingController* GetTracingController() override;

// Returns true if work was dispatched or executed. New tasks that are
// posted during flushing of the queue are postponed until the next
// flushing.
bool FlushForegroundTasks(v8::Isolate* isolate);
bool FlushForegroundTasks(v8::Isolate* isolate) override;

void RegisterIsolate(IsolateData* isolate_data, uv_loop_t* loop) override;
void UnregisterIsolate(IsolateData* isolate_data) override;
Expand Down

0 comments on commit 296fd57

Please sign in to comment.