Permalink
Browse files

inspector: stop dragging platform pointer

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 committed Jun 8, 2018
1 parent baadc7a commit 8941fb71a6b82700620fb87c250f731b78cfc78c
Showing with 26 additions and 37 deletions.
  1. +9 −18 src/inspector_agent.cc
  2. +3 −5 src/inspector_agent.h
  3. +4 −4 src/inspector_io.cc
  4. +4 −4 src/inspector_io.h
  5. +1 −1 src/node.cc
  6. +4 −0 src/node.h
  7. +1 −5 src/node_platform.h
@@ -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);
}
@@ -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_;
};
@@ -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()) {
@@ -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_;
@@ -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) {
@@ -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;
@@ -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;

1 comment on commit 8941fb7

@targos

This comment has been minimized.

Member

targos commented on 8941fb7 Jun 16, 2018

PR-URL: #21224

Please sign in to comment.