Index: src/inspector/v8-runtime-agent-impl.cc |
diff --git a/src/inspector/v8-runtime-agent-impl.cc b/src/inspector/v8-runtime-agent-impl.cc |
index 9b4944aa575ceacb14f4b0367540662b4c127d75..cfdef02618d5309bb66cc7343c3f2789b4ffaca2 100644 |
--- a/src/inspector/v8-runtime-agent-impl.cc |
+++ b/src/inspector/v8-runtime-agent-impl.cc |
@@ -61,12 +61,12 @@ namespace { |
template <typename Callback> |
class ProtocolPromiseHandler { |
public: |
- static void add(V8InspectorImpl* inspector, v8::Local<v8::Context> context, |
+ static void add(V8InspectorSessionImpl* session, |
+ v8::Local<v8::Context> context, |
v8::MaybeLocal<v8::Value> value, |
- const String16& notPromiseError, int contextGroupId, |
- int executionContextId, const String16& objectGroup, |
- bool returnByValue, bool generatePreview, |
- std::unique_ptr<Callback> callback) { |
+ const String16& notPromiseError, int executionContextId, |
+ const String16& objectGroup, bool returnByValue, |
+ bool generatePreview, std::unique_ptr<Callback> callback) { |
if (value.IsEmpty()) { |
callback->sendFailure(Response::InternalError()); |
return; |
@@ -75,14 +75,15 @@ class ProtocolPromiseHandler { |
callback->sendFailure(Response::Error(notPromiseError)); |
return; |
} |
+ V8InspectorImpl* inspector = session->inspector(); |
v8::MicrotasksScope microtasks_scope(inspector->isolate(), |
v8::MicrotasksScope::kRunMicrotasks); |
v8::Local<v8::Promise> promise = |
v8::Local<v8::Promise>::Cast(value.ToLocalChecked()); |
Callback* rawCallback = callback.get(); |
ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler( |
- inspector, contextGroupId, executionContextId, objectGroup, |
- returnByValue, generatePreview, std::move(callback)); |
+ session, executionContextId, objectGroup, returnByValue, |
+ generatePreview, std::move(callback)); |
v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate()); |
v8::Local<v8::Function> thenCallbackFunction = |
@@ -154,19 +155,19 @@ class ProtocolPromiseHandler { |
std::move(exceptionDetails)); |
} |
- ProtocolPromiseHandler(V8InspectorImpl* inspector, int contextGroupId, |
+ ProtocolPromiseHandler(V8InspectorSessionImpl* session, |
int executionContextId, const String16& objectGroup, |
bool returnByValue, bool generatePreview, |
std::unique_ptr<Callback> callback) |
- : m_inspector(inspector), |
- m_contextGroupId(contextGroupId), |
+ : m_inspector(session->inspector()), |
+ m_sessionId(session->sessionId()), |
m_executionContextId(executionContextId), |
m_objectGroup(objectGroup), |
m_returnByValue(returnByValue), |
m_generatePreview(generatePreview), |
m_callback(std::move(callback)), |
- m_wrapper(inspector->isolate(), |
- v8::External::New(inspector->isolate(), this)) { |
+ m_wrapper(m_inspector->isolate(), |
+ v8::External::New(m_inspector->isolate(), this)) { |
m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); |
} |
@@ -184,8 +185,12 @@ class ProtocolPromiseHandler { |
std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( |
v8::Local<v8::Value> value) { |
- InjectedScript::ContextScope scope(m_inspector, m_contextGroupId, |
- m_executionContextId); |
+ V8InspectorSessionImpl* session = m_inspector->sessionById(m_sessionId); |
+ if (!session) { |
+ m_callback->sendFailure(Response::Error("No session")); |
+ return nullptr; |
+ } |
+ InjectedScript::ContextScope scope(session, m_executionContextId); |
Response response = scope.initialize(); |
if (!response.isSuccess()) { |
m_callback->sendFailure(response); |
@@ -203,7 +208,7 @@ class ProtocolPromiseHandler { |
} |
V8InspectorImpl* m_inspector; |
- int m_contextGroupId; |
+ int m_sessionId; |
int m_executionContextId; |
String16 m_objectGroup; |
bool m_returnByValue; |
@@ -276,8 +281,7 @@ void V8RuntimeAgentImpl::evaluate( |
return; |
} |
- InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(), |
- contextId); |
+ InjectedScript::ContextScope scope(m_session, contextId); |
response = scope.initialize(); |
if (!response.isSuccess()) { |
callback->sendFailure(response); |
@@ -320,8 +324,8 @@ void V8RuntimeAgentImpl::evaluate( |
return; |
} |
ProtocolPromiseHandler<EvaluateCallback>::add( |
- m_inspector, scope.context(), maybeResultValue, |
- "Result of the evaluation is not a promise", m_session->contextGroupId(), |
+ m_session, scope.context(), maybeResultValue, |
+ "Result of the evaluation is not a promise", |
scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), |
returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
std::move(callback)); |
@@ -331,16 +335,15 @@ void V8RuntimeAgentImpl::awaitPromise( |
const String16& promiseObjectId, Maybe<bool> returnByValue, |
Maybe<bool> generatePreview, |
std::unique_ptr<AwaitPromiseCallback> callback) { |
- InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), |
- promiseObjectId); |
+ InjectedScript::ObjectScope scope(m_session, promiseObjectId); |
Response response = scope.initialize(); |
if (!response.isSuccess()) { |
callback->sendFailure(response); |
return; |
} |
ProtocolPromiseHandler<AwaitPromiseCallback>::add( |
- m_inspector, scope.context(), scope.object(), |
- "Could not find promise with given id", m_session->contextGroupId(), |
+ m_session, scope.context(), scope.object(), |
+ "Could not find promise with given id", |
scope.injectedScript()->context()->contextId(), scope.objectGroupName(), |
returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
std::move(callback)); |
@@ -352,8 +355,7 @@ void V8RuntimeAgentImpl::callFunctionOn( |
Maybe<bool> silent, Maybe<bool> returnByValue, Maybe<bool> generatePreview, |
Maybe<bool> userGesture, Maybe<bool> awaitPromise, |
std::unique_ptr<CallFunctionOnCallback> callback) { |
- InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), |
- objectId); |
+ InjectedScript::ObjectScope scope(m_session, objectId); |
Response response = scope.initialize(); |
if (!response.isSuccess()) { |
callback->sendFailure(response); |
@@ -438,9 +440,8 @@ void V8RuntimeAgentImpl::callFunctionOn( |
} |
ProtocolPromiseHandler<CallFunctionOnCallback>::add( |
- m_inspector, scope.context(), maybeResultValue, |
+ m_session, scope.context(), maybeResultValue, |
"Result of the function call is not a promise", |
- m_session->contextGroupId(), |
scope.injectedScript()->context()->contextId(), scope.objectGroupName(), |
returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
std::move(callback)); |
@@ -456,8 +457,7 @@ Response V8RuntimeAgentImpl::getProperties( |
Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { |
using protocol::Runtime::InternalPropertyDescriptor; |
- InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), |
- objectId); |
+ InjectedScript::ObjectScope scope(m_session, objectId); |
Response response = scope.initialize(); |
if (!response.isSuccess()) return response; |
@@ -507,8 +507,7 @@ Response V8RuntimeAgentImpl::getProperties( |
} |
Response V8RuntimeAgentImpl::releaseObject(const String16& objectId) { |
- InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), |
- objectId); |
+ InjectedScript::ObjectScope scope(m_session, objectId); |
Response response = scope.initialize(); |
if (!response.isSuccess()) return response; |
scope.injectedScript()->releaseObject(objectId); |
@@ -550,8 +549,7 @@ Response V8RuntimeAgentImpl::compileScript( |
Response response = ensureContext(m_inspector, m_session->contextGroupId(), |
std::move(executionContextId), &contextId); |
if (!response.isSuccess()) return response; |
- InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(), |
- contextId); |
+ InjectedScript::ContextScope scope(m_session, contextId); |
response = scope.initialize(); |
if (!response.isSuccess()) return response; |
@@ -607,8 +605,7 @@ void V8RuntimeAgentImpl::runScript( |
return; |
} |
- InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(), |
- contextId); |
+ InjectedScript::ContextScope scope(m_session, contextId); |
response = scope.initialize(); |
if (!response.isSuccess()) { |
callback->sendFailure(response); |
@@ -650,9 +647,8 @@ void V8RuntimeAgentImpl::runScript( |
return; |
} |
ProtocolPromiseHandler<RunScriptCallback>::add( |
- m_inspector, scope.context(), maybeResultValue.ToLocalChecked(), |
+ m_session, scope.context(), maybeResultValue.ToLocalChecked(), |
"Result of the script execution is not a promise", |
- m_session->contextGroupId(), |
scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), |
returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
std::move(callback)); |
@@ -700,10 +696,9 @@ Response V8RuntimeAgentImpl::disable() { |
void V8RuntimeAgentImpl::reset() { |
m_compiledScripts.clear(); |
if (m_enabled) { |
- if (const V8InspectorImpl::ContextByIdMap* contexts = |
- m_inspector->contextGroup(m_session->contextGroupId())) { |
- for (auto& idContext : *contexts) idContext.second->setReported(false); |
- } |
+ m_inspector->forEachContext( |
+ m_session->contextGroupId(), |
+ [](InspectedContext* context) { context->setReported(false); }); |
m_frontend.executionContextsCleared(); |
} |
} |