diff --git a/include/v8-inspector.h b/include/v8-inspector.h index 2c30401473..be2c20bbcf 100644 --- a/include/v8-inspector.h +++ b/include/v8-inspector.h @@ -152,6 +152,10 @@ class V8_EXPORT V8InspectorSession { virtual v8::Local get(v8::Local) = 0; virtual ~Inspectable() = default; }; + class V8_EXPORT CommandLineAPIScope { + public: + virtual ~CommandLineAPIScope() = default; + }; virtual void addInspectedObject(std::unique_ptr) = 0; // Dispatching protocol messages. @@ -163,6 +167,8 @@ class V8_EXPORT V8InspectorSession { virtual v8::Local createCommandLineAPI( v8::Local context) = 0; + virtual std::unique_ptr + initializeCommandLineAPIScope(int executionContextId) = 0; // Debugger actions. virtual void schedulePauseOnNextStatement(StringView breakReason, diff --git a/src/inspector/injected-script.h b/src/inspector/injected-script.h index 437fc69455..7f8f41e260 100644 --- a/src/inspector/injected-script.h +++ b/src/inspector/injected-script.h @@ -173,7 +173,8 @@ class InjectedScript final { int m_sessionId; }; - class ContextScope : public Scope { + class ContextScope : public Scope, + public V8InspectorSession::CommandLineAPIScope { public: ContextScope(V8InspectorSessionImpl*, int executionContextId); ~ContextScope() override; diff --git a/src/inspector/v8-inspector-session-impl.cc b/src/inspector/v8-inspector-session-impl.cc index ba3161e602..ae88d26b2f 100644 --- a/src/inspector/v8-inspector-session-impl.cc +++ b/src/inspector/v8-inspector-session-impl.cc @@ -155,6 +155,20 @@ V8InspectorSessionImpl::~V8InspectorSessionImpl() { m_inspector->disconnect(this); } +std::unique_ptr +V8InspectorSessionImpl::initializeCommandLineAPIScope(int executionContextId) { + auto scope = + std::make_unique(this, executionContextId); + auto result = scope->initialize(); + if (!result.IsSuccess()) { + return nullptr; + } + + scope->installCommandLineAPI(); + + return scope; +} + v8::Local V8InspectorSessionImpl::createCommandLineAPI( v8::Local context) { return inspector()->console()->createCommandLineAPI(context, sessionId()); diff --git a/src/inspector/v8-inspector-session-impl.h b/src/inspector/v8-inspector-session-impl.h index af67759b3d..5e3b79cf07 100644 --- a/src/inspector/v8-inspector-session-impl.h +++ b/src/inspector/v8-inspector-session-impl.h @@ -53,6 +53,9 @@ class V8InspectorSessionImpl : public V8InspectorSession, v8::Local createCommandLineAPI( v8::Local context) override; + std::unique_ptr + initializeCommandLineAPIScope(int executionContextId) override; + Response findInjectedScript(int contextId, InjectedScript*&); Response findInjectedScript(RemoteObjectIdBase*, InjectedScript*&); void reset();