diff options
author | Eugene Ostroukhov <eostroukhov@chromium.org> | 2018-04-24 11:16:55 -0700 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2018-05-04 11:54:32 -0400 |
commit | 149016423005afb819dd81b679ca84bc4c165492 (patch) | |
tree | 5a297eba6db58fd6b972e305ffe045929afd4d96 /src/inspector_js_api.cc | |
parent | 14188b12664c5e4fe3ce3a77bd2d61b6eb303d89 (diff) | |
download | node-new-149016423005afb819dd81b679ca84bc4c165492.tar.gz |
inspector: allow concurrent inspector sessions
This change enables concurrent inspector sessions, through WebSocket
interface as well as JS interface, in any combination.
PR-URL: https://github.com/nodejs/node/pull/20137
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/inspector_js_api.cc')
-rw-r--r-- | src/inspector_js_api.cc | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 9a380bb2df..3d05b2f6fe 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -42,10 +42,6 @@ class JSBindingsConnection : public AsyncWrap { connection_(connection) { } - bool WaitForFrontendMessageWhilePaused() override { - return false; - } - void SendMessageToFrontend(const v8_inspector::StringView& message) override { Isolate* isolate = env_->isolate(); @@ -58,12 +54,6 @@ class JSBindingsConnection : public AsyncWrap { connection_->OnMessage(argument); } - void Disconnect() { - Agent* agent = env_->inspector_agent(); - if (agent->delegate() == this) - agent->Disconnect(); - } - private: Environment* env_; JSBindingsConnection* connection_; @@ -73,31 +63,17 @@ class JSBindingsConnection : public AsyncWrap { Local<Object> wrap, Local<Function> callback) : AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING), - delegate_(env, this), callback_(env->isolate(), callback) { Wrap(wrap, this); - Agent* inspector = env->inspector_agent(); - if (inspector->delegate() != nullptr) { - // This signals JS code that it has to throw an error. - Local<String> session_attached = - FIXED_ONE_BYTE_STRING(env->isolate(), "sessionAttached"); - wrap->Set(env->context(), session_attached, - Boolean::New(env->isolate(), true)).ToChecked(); - return; - } - inspector->Connect(&delegate_); + session_ = inspector->Connect( + std::make_unique<JSBindingsSessionDelegate>(env, this)); } void OnMessage(Local<Value> value) { MakeCallback(callback_.Get(env()->isolate()), 1, &value); } - void CheckIsCurrent() { - Agent* inspector = env()->inspector_agent(); - CHECK_EQ(&delegate_, inspector->delegate()); - } - static void New(const FunctionCallbackInfo<Value>& info) { Environment* env = Environment::GetCurrent(info); CHECK(info[0]->IsFunction()); @@ -106,7 +82,7 @@ class JSBindingsConnection : public AsyncWrap { } void Disconnect() { - delegate_.Disconnect(); + session_.reset(); if (!persistent().IsEmpty()) { ClearWrap(object()); } @@ -125,18 +101,23 @@ class JSBindingsConnection : public AsyncWrap { ASSIGN_OR_RETURN_UNWRAP(&session, info.Holder()); CHECK(info[0]->IsString()); - session->CheckIsCurrent(); - Agent* inspector = env->inspector_agent(); - inspector->Dispatch(ToProtocolString(env->isolate(), info[0])->string()); + if (session->session_) { + session->session_->Dispatch( + ToProtocolString(env->isolate(), info[0])->string()); + } } size_t self_size() const override { return sizeof(*this); } private: - JSBindingsSessionDelegate delegate_; + std::unique_ptr<InspectorSession> session_; Persistent<Function> callback_; }; +static bool InspectorEnabled(Environment* env) { + Agent* agent = env->inspector_agent(); + return agent->io() != nullptr || agent->HasConnectedSessions(); +} void AddCommandLineAPI(const FunctionCallbackInfo<Value>& info) { auto env = Environment::GetCurrent(info); @@ -178,7 +159,7 @@ void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) { call_args.push_back(info[i]); } Environment* env = Environment::GetCurrent(isolate); - if (env->inspector_agent()->enabled()) { + if (InspectorEnabled(env)) { Local<Value> inspector_method = info[0]; CHECK(inspector_method->IsFunction()); Local<Value> config_value = info[2]; @@ -256,7 +237,7 @@ static void RegisterAsyncHookWrapper(const FunctionCallbackInfo<Value>& args) { void IsEnabled(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - args.GetReturnValue().Set(env->inspector_agent()->enabled()); + args.GetReturnValue().Set(InspectorEnabled(env)); } void Open(const FunctionCallbackInfo<Value>& args) { |