| Index: src/inspector/v8-inspector-impl.cc
|
| diff --git a/src/inspector/v8-inspector-impl.cc b/src/inspector/v8-inspector-impl.cc
|
| index ad7d27d9caba558679ce77ae91d86f1974a3987d..34e41208acd7cbe788a79b3f0afb63e49463b438 100644
|
| --- a/src/inspector/v8-inspector-impl.cc
|
| +++ b/src/inspector/v8-inspector-impl.cc
|
| @@ -54,10 +54,21 @@ V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate,
|
| m_client(client),
|
| m_debugger(new V8Debugger(isolate, this)),
|
| m_capturingStackTracesCount(0),
|
| - m_lastExceptionId(0) {}
|
| + m_lastExceptionId(0),
|
| + m_lastContextId(0) {}
|
|
|
| V8InspectorImpl::~V8InspectorImpl() {}
|
|
|
| +int V8InspectorImpl::contextGroupId(v8::Local<v8::Context> context) {
|
| + return contextGroupId(InspectedContext::contextId(context));
|
| +}
|
| +
|
| +int V8InspectorImpl::contextGroupId(int contextId) {
|
| + protocol::HashMap<int, int>::iterator it =
|
| + m_contextIdToGroupIdMap.find(contextId);
|
| + return it != m_contextIdToGroupIdMap.end() ? it->second : 0;
|
| +}
|
| +
|
| V8DebuggerAgentImpl* V8InspectorImpl::enabledDebuggerAgentForGroup(
|
| int contextGroupId) {
|
| V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId);
|
| @@ -83,7 +94,7 @@ v8::MaybeLocal<v8::Value> V8InspectorImpl::runCompiledScript(
|
| v8::Local<v8::Context> context, v8::Local<v8::Script> script) {
|
| v8::MicrotasksScope microtasksScope(m_isolate,
|
| v8::MicrotasksScope::kRunMicrotasks);
|
| - int groupId = V8Debugger::getGroupId(context);
|
| + int groupId = contextGroupId(context);
|
| if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
|
| agent->willExecuteScript(script->GetUnboundScript()->GetId());
|
| v8::MaybeLocal<v8::Value> result = script->Run(context);
|
| @@ -113,7 +124,7 @@ v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(
|
| v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[],
|
| v8::MicrotasksScope::Type runMicrotasks) {
|
| v8::MicrotasksScope microtasksScope(m_isolate, runMicrotasks);
|
| - int groupId = V8Debugger::getGroupId(context);
|
| + int groupId = contextGroupId(context);
|
| if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
|
| agent->willExecuteScript(function->ScriptId());
|
| v8::MaybeLocal<v8::Value> result =
|
| @@ -226,7 +237,9 @@ InspectedContext* V8InspectorImpl::getContext(int groupId,
|
| }
|
|
|
| void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
|
| - int contextId = m_debugger->markContext(info);
|
| + int contextId = ++m_lastContextId;
|
| + InspectedContext* context = new InspectedContext(this, info, contextId);
|
| + m_contextIdToGroupIdMap[contextId] = info.contextGroupId;
|
|
|
| ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId);
|
| if (contextIt == m_contexts.end())
|
| @@ -235,11 +248,9 @@ void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
|
| info.contextGroupId,
|
| std::unique_ptr<ContextByIdMap>(new ContextByIdMap())))
|
| .first;
|
| -
|
| const auto& contextById = contextIt->second;
|
|
|
| DCHECK(contextById->find(contextId) == contextById->cend());
|
| - InspectedContext* context = new InspectedContext(this, info, contextId);
|
| (*contextById)[contextId].reset(context);
|
| SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId);
|
| if (sessionIt != m_sessions.end())
|
| @@ -247,22 +258,22 @@ void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
|
| }
|
|
|
| void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) {
|
| - int contextId = V8Debugger::contextId(context);
|
| - int contextGroupId = V8Debugger::getGroupId(context);
|
| + int contextId = InspectedContext::contextId(context);
|
| + int groupId = contextGroupId(context);
|
| + m_contextIdToGroupIdMap.erase(contextId);
|
|
|
| - ConsoleStorageMap::iterator storageIt =
|
| - m_consoleStorageMap.find(contextGroupId);
|
| + ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(groupId);
|
| if (storageIt != m_consoleStorageMap.end())
|
| storageIt->second->contextDestroyed(contextId);
|
|
|
| - InspectedContext* inspectedContext = getContext(contextGroupId, contextId);
|
| + InspectedContext* inspectedContext = getContext(groupId, contextId);
|
| if (!inspectedContext) return;
|
|
|
| - SessionMap::iterator iter = m_sessions.find(contextGroupId);
|
| + SessionMap::iterator iter = m_sessions.find(groupId);
|
| if (iter != m_sessions.end())
|
| iter->second->runtimeAgent()->reportExecutionContextDestroyed(
|
| inspectedContext);
|
| - discardInspectedContext(contextGroupId, contextId);
|
| + discardInspectedContext(groupId, contextId);
|
| }
|
|
|
| void V8InspectorImpl::resetContextGroup(int contextGroupId) {
|
| @@ -277,14 +288,16 @@ void V8InspectorImpl::resetContextGroup(int contextGroupId) {
|
| void V8InspectorImpl::willExecuteScript(v8::Local<v8::Context> context,
|
| int scriptId) {
|
| if (V8DebuggerAgentImpl* agent =
|
| - enabledDebuggerAgentForGroup(V8Debugger::getGroupId(context)))
|
| + enabledDebuggerAgentForGroup(contextGroupId(context))) {
|
| agent->willExecuteScript(scriptId);
|
| + }
|
| }
|
|
|
| void V8InspectorImpl::didExecuteScript(v8::Local<v8::Context> context) {
|
| if (V8DebuggerAgentImpl* agent =
|
| - enabledDebuggerAgentForGroup(V8Debugger::getGroupId(context)))
|
| + enabledDebuggerAgentForGroup(contextGroupId(context))) {
|
| agent->didExecuteScript();
|
| + }
|
| }
|
|
|
| void V8InspectorImpl::idleStarted() {
|
| @@ -304,8 +317,8 @@ unsigned V8InspectorImpl::exceptionThrown(
|
| v8::Local<v8::Value> exception, const StringView& detailedMessage,
|
| const StringView& url, unsigned lineNumber, unsigned columnNumber,
|
| std::unique_ptr<V8StackTrace> stackTrace, int scriptId) {
|
| - int contextGroupId = V8Debugger::getGroupId(context);
|
| - if (!contextGroupId || m_muteExceptionsMap[contextGroupId]) return 0;
|
| + int groupId = contextGroupId(context);
|
| + if (!groupId || m_muteExceptionsMap[groupId]) return 0;
|
| std::unique_ptr<V8StackTraceImpl> stackTraceImpl(
|
| static_cast<V8StackTraceImpl*>(stackTrace.release()));
|
| unsigned exceptionId = nextExceptionId();
|
| @@ -314,23 +327,21 @@ unsigned V8InspectorImpl::exceptionThrown(
|
| m_client->currentTimeMS(), toString16(detailedMessage),
|
| toString16(url), lineNumber, columnNumber, std::move(stackTraceImpl),
|
| scriptId, m_isolate, toString16(message),
|
| - V8Debugger::contextId(context), exception, exceptionId);
|
| - ensureConsoleMessageStorage(contextGroupId)
|
| - ->addMessage(std::move(consoleMessage));
|
| + InspectedContext::contextId(context), exception, exceptionId);
|
| + ensureConsoleMessageStorage(groupId)->addMessage(std::move(consoleMessage));
|
| return exceptionId;
|
| }
|
|
|
| void V8InspectorImpl::exceptionRevoked(v8::Local<v8::Context> context,
|
| unsigned exceptionId,
|
| const StringView& message) {
|
| - int contextGroupId = V8Debugger::getGroupId(context);
|
| - if (!contextGroupId) return;
|
| + int groupId = contextGroupId(context);
|
| + if (!groupId) return;
|
|
|
| std::unique_ptr<V8ConsoleMessage> consoleMessage =
|
| V8ConsoleMessage::createForRevokedException(
|
| m_client->currentTimeMS(), toString16(message), exceptionId);
|
| - ensureConsoleMessageStorage(contextGroupId)
|
| - ->addMessage(std::move(consoleMessage));
|
| + ensureConsoleMessageStorage(groupId)->addMessage(std::move(consoleMessage));
|
| }
|
|
|
| std::unique_ptr<V8StackTrace> V8InspectorImpl::captureStackTrace(
|
|
|