| Index: src/inspector/v8-inspector-session-impl.cc
|
| diff --git a/src/inspector/v8-inspector-session-impl.cc b/src/inspector/v8-inspector-session-impl.cc
|
| index 2674fc2f63c4575c2a5cdd28a974d908a152f363..a2017a6d98d102578b44be1f860fdf25346272a2 100644
|
| --- a/src/inspector/v8-inspector-session-impl.cc
|
| +++ b/src/inspector/v8-inspector-session-impl.cc
|
| @@ -43,17 +43,19 @@ int V8ContextInfo::executionContextId(v8::Local<v8::Context> context) {
|
| }
|
|
|
| std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(
|
| - V8InspectorImpl* inspector, int contextGroupId,
|
| + V8InspectorImpl* inspector, int contextGroupId, int sessionId,
|
| V8Inspector::Channel* channel, const StringView& state) {
|
| - return std::unique_ptr<V8InspectorSessionImpl>(
|
| - new V8InspectorSessionImpl(inspector, contextGroupId, channel, state));
|
| + return std::unique_ptr<V8InspectorSessionImpl>(new V8InspectorSessionImpl(
|
| + inspector, contextGroupId, sessionId, channel, state));
|
| }
|
|
|
| V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector,
|
| int contextGroupId,
|
| + int sessionId,
|
| V8Inspector::Channel* channel,
|
| const StringView& savedState)
|
| : m_contextGroupId(contextGroupId),
|
| + m_sessionId(sessionId),
|
| m_inspector(inspector),
|
| m_channel(channel),
|
| m_customObjectFormatterEnabled(false),
|
| @@ -181,39 +183,17 @@ void V8InspectorSessionImpl::reset() {
|
|
|
| void V8InspectorSessionImpl::discardInjectedScripts() {
|
| m_inspectedObjects.clear();
|
| - const V8InspectorImpl::ContextByIdMap* contexts =
|
| - m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts) return;
|
| -
|
| - std::vector<int> keys;
|
| - keys.reserve(contexts->size());
|
| - for (auto& idContext : *contexts) keys.push_back(idContext.first);
|
| - for (auto& key : keys) {
|
| - contexts = m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts) continue;
|
| - auto contextIt = contexts->find(key);
|
| - if (contextIt != contexts->end())
|
| - contextIt->second
|
| - ->discardInjectedScript(); // This may destroy some contexts.
|
| - }
|
| + m_inspector->forEachContext(m_contextGroupId, [](InspectedContext* context) {
|
| + context->discardInjectedScript();
|
| + });
|
| }
|
|
|
| Response V8InspectorSessionImpl::findInjectedScript(
|
| int contextId, InjectedScript*& injectedScript) {
|
| injectedScript = nullptr;
|
| - if (!contextId)
|
| - return Response::Error("Cannot find context with specified id");
|
| -
|
| - const V8InspectorImpl::ContextByIdMap* contexts =
|
| - m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts)
|
| - return Response::Error("Cannot find context with specified id");
|
| -
|
| - auto contextsIt = contexts->find(contextId);
|
| - if (contextsIt == contexts->end())
|
| - return Response::Error("Cannot find context with specified id");
|
| -
|
| - const std::unique_ptr<InspectedContext>& context = contextsIt->second;
|
| + InspectedContext* context =
|
| + m_inspector->getContext(m_contextGroupId, contextId);
|
| + if (!context) return Response::Error("Cannot find context with specified id");
|
| if (!context->getInjectedScript()) {
|
| if (!context->createInjectedScript())
|
| return Response::Error("Cannot access specified execution context");
|
| @@ -234,22 +214,11 @@ void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) {
|
| }
|
|
|
| void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) {
|
| - const V8InspectorImpl::ContextByIdMap* contexts =
|
| - m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts) return;
|
| -
|
| - std::vector<int> keys;
|
| - for (auto& idContext : *contexts) keys.push_back(idContext.first);
|
| - for (auto& key : keys) {
|
| - contexts = m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts) continue;
|
| - auto contextsIt = contexts->find(key);
|
| - if (contextsIt == contexts->end()) continue;
|
| - InjectedScript* injectedScript = contextsIt->second->getInjectedScript();
|
| - if (injectedScript)
|
| - injectedScript->releaseObjectGroup(
|
| - objectGroup); // This may destroy some contexts.
|
| - }
|
| + m_inspector->forEachContext(
|
| + m_contextGroupId, [&objectGroup](InspectedContext* context) {
|
| + InjectedScript* injectedScript = context->getInjectedScript();
|
| + if (injectedScript) injectedScript->releaseObjectGroup(objectGroup);
|
| + });
|
| }
|
|
|
| bool V8InspectorSessionImpl::unwrapObject(
|
| @@ -319,22 +288,19 @@ V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context,
|
|
|
| void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) {
|
| m_customObjectFormatterEnabled = enabled;
|
| - const V8InspectorImpl::ContextByIdMap* contexts =
|
| - m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts) return;
|
| - for (auto& idContext : *contexts) {
|
| - InjectedScript* injectedScript = idContext.second->getInjectedScript();
|
| - if (injectedScript)
|
| - injectedScript->setCustomObjectFormatterEnabled(enabled);
|
| - }
|
| + m_inspector->forEachContext(
|
| + m_contextGroupId, [&enabled](InspectedContext* context) {
|
| + InjectedScript* injectedScript = context->getInjectedScript();
|
| + if (injectedScript)
|
| + injectedScript->setCustomObjectFormatterEnabled(enabled);
|
| + });
|
| }
|
|
|
| void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) {
|
| - const V8InspectorImpl::ContextByIdMap* contexts =
|
| - m_inspector->contextGroup(m_contextGroupId);
|
| - if (!contexts) return;
|
| - for (auto& idContext : *contexts)
|
| - agent->reportExecutionContextCreated(idContext.second.get());
|
| + m_inspector->forEachContext(m_contextGroupId,
|
| + [&agent](InspectedContext* context) {
|
| + agent->reportExecutionContextCreated(context);
|
| + });
|
| }
|
|
|
| void V8InspectorSessionImpl::dispatchProtocolMessage(
|
|
|