Implement V8InspectorSession::initializeCommandLineAPIScope
In https://crrev.com/c/2842128, a concern was raised that using `V8InspectorSession::createCommandLineAPI` directly would not cache the command line API definitions and V8 could expose a higher level API for this use case. This CL exposes `InjectedScript::ContextScope` via V8InspectorSession. If this approach is approved, V8InspectorSession::createCommandLineAPI could be removed. Example usage: https://crrev.com/c/2858964 Bug: chromium:1200705 Change-Id: Ib9fcadcb9bbd75c08f0122b0e4ee61e2874c4f8a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2857640 Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#74289}
This commit is contained in:
parent
1a5d2e31c6
commit
7d5e5f6c62
@ -152,6 +152,10 @@ class V8_EXPORT V8InspectorSession {
|
||||
virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
|
||||
virtual ~Inspectable() = default;
|
||||
};
|
||||
class V8_EXPORT CommandLineAPIScope {
|
||||
public:
|
||||
virtual ~CommandLineAPIScope() = default;
|
||||
};
|
||||
virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
|
||||
|
||||
// Dispatching protocol messages.
|
||||
@ -163,6 +167,8 @@ class V8_EXPORT V8InspectorSession {
|
||||
|
||||
virtual v8::Local<v8::Object> createCommandLineAPI(
|
||||
v8::Local<v8::Context> context) = 0;
|
||||
virtual std::unique_ptr<V8InspectorSession::CommandLineAPIScope>
|
||||
initializeCommandLineAPIScope(int executionContextId) = 0;
|
||||
|
||||
// Debugger actions.
|
||||
virtual void schedulePauseOnNextStatement(StringView breakReason,
|
||||
|
@ -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;
|
||||
|
@ -155,6 +155,20 @@ V8InspectorSessionImpl::~V8InspectorSessionImpl() {
|
||||
m_inspector->disconnect(this);
|
||||
}
|
||||
|
||||
std::unique_ptr<V8InspectorSession::CommandLineAPIScope>
|
||||
V8InspectorSessionImpl::initializeCommandLineAPIScope(int executionContextId) {
|
||||
auto scope =
|
||||
std::make_unique<InjectedScript::ContextScope>(this, executionContextId);
|
||||
auto result = scope->initialize();
|
||||
if (!result.IsSuccess()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
scope->installCommandLineAPI();
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> V8InspectorSessionImpl::createCommandLineAPI(
|
||||
v8::Local<v8::Context> context) {
|
||||
return inspector()->console()->createCommandLineAPI(context, sessionId());
|
||||
|
@ -53,6 +53,9 @@ class V8InspectorSessionImpl : public V8InspectorSession,
|
||||
v8::Local<v8::Object> createCommandLineAPI(
|
||||
v8::Local<v8::Context> context) override;
|
||||
|
||||
std::unique_ptr<V8InspectorSession::CommandLineAPIScope>
|
||||
initializeCommandLineAPIScope(int executionContextId) override;
|
||||
|
||||
Response findInjectedScript(int contextId, InjectedScript*&);
|
||||
Response findInjectedScript(RemoteObjectIdBase*, InjectedScript*&);
|
||||
void reset();
|
||||
|
Loading…
Reference in New Issue
Block a user