From 296fd57324ac1ae136b13ae405aa27b98a237ccb Mon Sep 17 00:00:00 2001 From: Eugene Ostroukhov Date: Fri, 8 Jun 2018 14:43:21 -0700 Subject: [PATCH] inspector: stop dragging platform pointer It is now easily accessible from the Environment Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Ali Ijaz Sheikh --- src/inspector_agent.cc | 27 +++++++++------------------ src/inspector_agent.h | 8 +++----- src/inspector_io.cc | 8 ++++---- src/inspector_io.h | 8 ++++---- src/node.cc | 2 +- src/node.h | 4 ++++ src/node_platform.h | 6 +----- 7 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 058a665e5630ab..2b03fd05b115a3 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -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()); @@ -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; @@ -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 client_; @@ -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( - new NodeInspectorClient(parent_env_, platform)); - platform_ = platform; + client_ = std::make_shared(parent_env_); CHECK_EQ(0, uv_async_init(uv_default_loop(), &start_io_thread_async, StartIoThreadAsyncCallback)); @@ -565,8 +556,7 @@ bool Agent::StartIoThread(bool wait_for_connect) { CHECK_NOT_NULL(client_); io_ = std::unique_ptr( - 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; @@ -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); } diff --git a/src/inspector_agent.h b/src/inspector_agent.h index 21cf4c9f1253da..7295d048b64357 100644 --- a/src/inspector_agent.h +++ b/src/inspector_agent.h @@ -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(); @@ -108,12 +107,11 @@ class Agent { node::Environment* parent_env_; std::shared_ptr client_; std::unique_ptr 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 enable_async_hook_function_; node::Persistent disable_async_hook_function_; }; diff --git a/src/inspector_io.cc b/src/inspector_io.cc index 8f861316dadb81..01d78d177de1a6 100644 --- a/src/inspector_io.cc +++ b/src/inspector_io.cc @@ -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()) { diff --git a/src/inspector_io.h b/src/inspector_io.h index 9d27fc557b7b25..c897a44a528ec2 100644 --- a/src/inspector_io.h +++ b/src/inspector_io.h @@ -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, @@ -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* 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_; diff --git a/src/node.cc b/src/node.cc index 26c6df9a8a7e86..b562e3112da72c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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) { diff --git a/src/node.h b/src/node.h index deaafb009d9713..90b2a8cbf690ce 100644 --- a/src/node.h +++ b/src/node.h @@ -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; diff --git a/src/node_platform.h b/src/node_platform.h index f6a177c9242324..77826e057771b0 100644 --- a/src/node_platform.h +++ b/src/node_platform.h @@ -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;