summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/inspector_agent.cc27
-rw-r--r--src/inspector_agent.h8
-rw-r--r--src/inspector_io.cc8
-rw-r--r--src/inspector_io.h8
-rw-r--r--src/node.cc2
-rw-r--r--src/node.h4
-rw-r--r--src/node_platform.h6
7 files changed, 26 insertions, 37 deletions
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index 058a665e56..2b03fd05b1 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<V8Inspector> 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<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));
@@ -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;
@@ -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 21cf4c9f12..7295d048b6 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<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_;
};
diff --git a/src/inspector_io.cc b/src/inspector_io.cc
index 8f861316da..01d78d177d 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 9d27fc557b..c897a44a52 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<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_;
diff --git a/src/node.cc b/src/node.cc
index e5ed352786..292307e9da 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -317,7 +317,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 deaafb009d..90b2a8cbf6 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 f6a177c924..77826e0577 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;