Skip to content
Prev Previous commit
Next Next commit
ignore already tracked contexts
  • Loading branch information
TimothyGu committed Jul 15, 2017
commit a08b03eebe7bcbefbee1655229730db7ad0c7483
17 changes: 14 additions & 3 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ void AttachContext(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto info = new node::inspector::ContextInfo(
contextify_context->context(), group_id, name, origin,
"{\"isDefault\":false}");
// Ignore error.
env->inspector_agent()->ContextCreated(info);
}

Expand Down Expand Up @@ -620,9 +621,19 @@ Agent::Agent(Environment* env) : parent_env_(env),
Agent::~Agent() {
}

void Agent::ContextCreated(const node::inspector::ContextInfo* info) {
bool Agent::ContextCreated(const node::inspector::ContextInfo* info) {
auto isolate = parent_env_->isolate();
auto it = std::find_if(
contexts_.begin(), contexts_.end(),
[&] (const node::inspector::ContextInfo*& cur) {
return cur->context(isolate) == info->context(isolate);
});
if (it != contexts_.end()) {
return false;
}
contexts_.push_back(info);
client_->contextCreated(info);
return true;
}

void Agent::ContextDestroyed(Local<Context> context) {
Expand All @@ -646,10 +657,10 @@ bool Agent::Start(v8::Platform* platform, const char* path,
client_ =
std::unique_ptr<NodeInspectorClient>(
new NodeInspectorClient(parent_env_, platform));
ContextCreated(
CHECK(ContextCreated(
new node::inspector::ContextInfo(
parent_env_->context(), CONTEXT_GROUP_ID, "Node.js Main Context",
nullptr, "{\"isDefault\":true}"));
nullptr, "{\"isDefault\":true}")));
platform_ = platform;
CHECK_EQ(0, uv_async_init(uv_default_loop(),
&start_io_thread_async,
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Agent {
// Stop and destroy io_
void Stop();

void ContextCreated(const node::inspector::ContextInfo* info);
bool ContextCreated(const node::inspector::ContextInfo* info);
void ContextDestroyed(v8::Local<v8::Context> context);

bool IsStarted() { return !!client_; }
Expand Down