| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 std::unique_ptr<V8StackTrace> V8InspectorImpl::createStackTrace( | 146 std::unique_ptr<V8StackTrace> V8InspectorImpl::createStackTrace( |
| 147 v8::Local<v8::StackTrace> stackTrace) { | 147 v8::Local<v8::StackTrace> stackTrace) { |
| 148 return m_debugger->createStackTrace(stackTrace); | 148 return m_debugger->createStackTrace(stackTrace); |
| 149 } | 149 } |
| 150 | 150 |
| 151 std::unique_ptr<V8InspectorSession> V8InspectorImpl::connect( | 151 std::unique_ptr<V8InspectorSession> V8InspectorImpl::connect( |
| 152 int contextGroupId, V8Inspector::Channel* channel, | 152 int contextGroupId, V8Inspector::Channel* channel, |
| 153 const StringView& state) { | 153 const StringView& state) { |
| 154 DCHECK(m_sessions.find(contextGroupId) == m_sessions.cend()); | |
| 155 int sessionId = ++m_lastSessionId; | 154 int sessionId = ++m_lastSessionId; |
| 156 std::unique_ptr<V8InspectorSessionImpl> session = | 155 std::unique_ptr<V8InspectorSessionImpl> session = |
| 157 V8InspectorSessionImpl::create(this, contextGroupId, sessionId, channel, | 156 V8InspectorSessionImpl::create(this, contextGroupId, sessionId, channel, |
| 158 state); | 157 state); |
| 159 m_sessions[contextGroupId] = session.get(); | 158 m_sessions[contextGroupId][sessionId] = session.get(); |
| 160 m_sessionById[sessionId] = session.get(); | |
| 161 return std::move(session); | 159 return std::move(session); |
| 162 } | 160 } |
| 163 | 161 |
| 164 void V8InspectorImpl::disconnect(V8InspectorSessionImpl* session) { | 162 void V8InspectorImpl::disconnect(V8InspectorSessionImpl* session) { |
| 165 DCHECK(m_sessions.find(session->contextGroupId()) != m_sessions.end()); | 163 auto& map = m_sessions[session->contextGroupId()]; |
| 166 m_sessions.erase(session->contextGroupId()); | 164 map.erase(session->sessionId()); |
| 167 m_sessionById.erase(session->sessionId()); | 165 if (map.empty()) m_sessions.erase(session->contextGroupId()); |
| 168 } | 166 } |
| 169 | 167 |
| 170 InspectedContext* V8InspectorImpl::getContext(int groupId, | 168 InspectedContext* V8InspectorImpl::getContext(int groupId, |
| 171 int contextId) const { | 169 int contextId) const { |
| 172 if (!groupId || !contextId) return nullptr; | 170 if (!groupId || !contextId) return nullptr; |
| 173 | 171 |
| 174 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId); | 172 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId); |
| 175 if (contextGroupIt == m_contexts.end()) return nullptr; | 173 if (contextGroupIt == m_contexts.end()) return nullptr; |
| 176 | 174 |
| 177 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId); | 175 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 189 if (contextIt == m_contexts.end()) | 187 if (contextIt == m_contexts.end()) |
| 190 contextIt = m_contexts | 188 contextIt = m_contexts |
| 191 .insert(std::make_pair( | 189 .insert(std::make_pair( |
| 192 info.contextGroupId, | 190 info.contextGroupId, |
| 193 std::unique_ptr<ContextByIdMap>(new ContextByIdMap()))) | 191 std::unique_ptr<ContextByIdMap>(new ContextByIdMap()))) |
| 194 .first; | 192 .first; |
| 195 const auto& contextById = contextIt->second; | 193 const auto& contextById = contextIt->second; |
| 196 | 194 |
| 197 DCHECK(contextById->find(contextId) == contextById->cend()); | 195 DCHECK(contextById->find(contextId) == contextById->cend()); |
| 198 (*contextById)[contextId].reset(context); | 196 (*contextById)[contextId].reset(context); |
| 199 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId); | 197 forEachSession( |
| 200 if (sessionIt != m_sessions.end()) | 198 info.contextGroupId, [&context](V8InspectorSessionImpl* session) { |
| 201 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context); | 199 session->runtimeAgent()->reportExecutionContextCreated(context); |
| 200 }); |
| 202 } | 201 } |
| 203 | 202 |
| 204 void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) { | 203 void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) { |
| 205 int contextId = InspectedContext::contextId(context); | 204 int contextId = InspectedContext::contextId(context); |
| 206 int groupId = contextGroupId(context); | 205 int groupId = contextGroupId(context); |
| 207 m_contextIdToGroupIdMap.erase(contextId); | 206 m_contextIdToGroupIdMap.erase(contextId); |
| 208 | 207 |
| 209 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(groupId); | 208 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(groupId); |
| 210 if (storageIt != m_consoleStorageMap.end()) | 209 if (storageIt != m_consoleStorageMap.end()) |
| 211 storageIt->second->contextDestroyed(contextId); | 210 storageIt->second->contextDestroyed(contextId); |
| 212 | 211 |
| 213 InspectedContext* inspectedContext = getContext(groupId, contextId); | 212 InspectedContext* inspectedContext = getContext(groupId, contextId); |
| 214 if (!inspectedContext) return; | 213 if (!inspectedContext) return; |
| 215 | 214 |
| 216 SessionMap::iterator iter = m_sessions.find(groupId); | 215 forEachSession(groupId, [&inspectedContext](V8InspectorSessionImpl* session) { |
| 217 if (iter != m_sessions.end()) | 216 session->runtimeAgent()->reportExecutionContextDestroyed(inspectedContext); |
| 218 iter->second->runtimeAgent()->reportExecutionContextDestroyed( | 217 }); |
| 219 inspectedContext); | |
| 220 discardInspectedContext(groupId, contextId); | 218 discardInspectedContext(groupId, contextId); |
| 221 } | 219 } |
| 222 | 220 |
| 223 void V8InspectorImpl::resetContextGroup(int contextGroupId) { | 221 void V8InspectorImpl::resetContextGroup(int contextGroupId) { |
| 224 m_consoleStorageMap.erase(contextGroupId); | 222 m_consoleStorageMap.erase(contextGroupId); |
| 225 m_muteExceptionsMap.erase(contextGroupId); | 223 m_muteExceptionsMap.erase(contextGroupId); |
| 226 SessionMap::iterator session = m_sessions.find(contextGroupId); | 224 forEachSession(contextGroupId, |
| 227 if (session != m_sessions.end()) session->second->reset(); | 225 [](V8InspectorSessionImpl* session) { session->reset(); }); |
| 228 m_contexts.erase(contextGroupId); | 226 m_contexts.erase(contextGroupId); |
| 229 m_debugger->wasmTranslation()->Clear(); | 227 m_debugger->wasmTranslation()->Clear(); |
| 230 } | 228 } |
| 231 | 229 |
| 232 void V8InspectorImpl::idleStarted() { | 230 void V8InspectorImpl::idleStarted() { |
| 233 for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) { | 231 for (auto& it : m_sessions) { |
| 234 if (it->second->profilerAgent()->idleStarted()) return; | 232 for (auto& it2 : it.second) { |
| 233 if (it2.second->profilerAgent()->idleStarted()) return; |
| 234 } |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 void V8InspectorImpl::idleFinished() { | 238 void V8InspectorImpl::idleFinished() { |
| 239 for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) { | 239 for (auto& it : m_sessions) { |
| 240 if (it->second->profilerAgent()->idleFinished()) return; | 240 for (auto& it2 : it.second) { |
| 241 if (it2.second->profilerAgent()->idleFinished()) return; |
| 242 } |
| 241 } | 243 } |
| 242 } | 244 } |
| 243 | 245 |
| 244 unsigned V8InspectorImpl::exceptionThrown( | 246 unsigned V8InspectorImpl::exceptionThrown( |
| 245 v8::Local<v8::Context> context, const StringView& message, | 247 v8::Local<v8::Context> context, const StringView& message, |
| 246 v8::Local<v8::Value> exception, const StringView& detailedMessage, | 248 v8::Local<v8::Value> exception, const StringView& detailedMessage, |
| 247 const StringView& url, unsigned lineNumber, unsigned columnNumber, | 249 const StringView& url, unsigned lineNumber, unsigned columnNumber, |
| 248 std::unique_ptr<V8StackTrace> stackTrace, int scriptId) { | 250 std::unique_ptr<V8StackTrace> stackTrace, int scriptId) { |
| 249 int groupId = contextGroupId(context); | 251 int groupId = contextGroupId(context); |
| 250 if (!groupId || m_muteExceptionsMap[groupId]) return 0; | 252 if (!groupId || m_muteExceptionsMap[groupId]) return 0; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 return m_regexContext.Get(m_isolate); | 307 return m_regexContext.Get(m_isolate); |
| 306 } | 308 } |
| 307 | 309 |
| 308 void V8InspectorImpl::discardInspectedContext(int contextGroupId, | 310 void V8InspectorImpl::discardInspectedContext(int contextGroupId, |
| 309 int contextId) { | 311 int contextId) { |
| 310 if (!getContext(contextGroupId, contextId)) return; | 312 if (!getContext(contextGroupId, contextId)) return; |
| 311 m_contexts[contextGroupId]->erase(contextId); | 313 m_contexts[contextGroupId]->erase(contextId); |
| 312 if (m_contexts[contextGroupId]->empty()) m_contexts.erase(contextGroupId); | 314 if (m_contexts[contextGroupId]->empty()) m_contexts.erase(contextGroupId); |
| 313 } | 315 } |
| 314 | 316 |
| 315 V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup( | 317 V8InspectorSessionImpl* V8InspectorImpl::sessionById(int contextGroupId, |
| 316 int contextGroupId) { | 318 int sessionId) { |
| 317 if (!contextGroupId) return nullptr; | 319 auto it = m_sessions.find(contextGroupId); |
| 318 SessionMap::iterator iter = m_sessions.find(contextGroupId); | 320 if (it == m_sessions.end()) return nullptr; |
| 319 return iter == m_sessions.end() ? nullptr : iter->second; | 321 auto it2 = it->second.find(sessionId); |
| 320 } | 322 return it2 == it->second.end() ? nullptr : it2->second; |
| 321 | |
| 322 V8InspectorSessionImpl* V8InspectorImpl::sessionById(int sessionId) { | |
| 323 auto it = m_sessionById.find(sessionId); | |
| 324 return it == m_sessionById.end() ? nullptr : it->second; | |
| 325 } | 323 } |
| 326 | 324 |
| 327 V8Console* V8InspectorImpl::console() { | 325 V8Console* V8InspectorImpl::console() { |
| 328 if (!m_console) m_console.reset(new V8Console(this)); | 326 if (!m_console) m_console.reset(new V8Console(this)); |
| 329 return m_console.get(); | 327 return m_console.get(); |
| 330 } | 328 } |
| 331 | 329 |
| 332 void V8InspectorImpl::forEachContext( | 330 void V8InspectorImpl::forEachContext( |
| 333 int contextGroupId, std::function<void(InspectedContext*)> callback) { | 331 int contextGroupId, std::function<void(InspectedContext*)> callback) { |
| 334 auto it = m_contexts.find(contextGroupId); | 332 auto it = m_contexts.find(contextGroupId); |
| 335 if (it == m_contexts.end()) return; | 333 if (it == m_contexts.end()) return; |
| 336 std::vector<int> ids; | 334 std::vector<int> ids; |
| 337 ids.reserve(it->second->size()); | 335 ids.reserve(it->second->size()); |
| 338 for (auto& contextIt : *(it->second)) ids.push_back(contextIt.first); | 336 for (auto& contextIt : *(it->second)) ids.push_back(contextIt.first); |
| 339 | 337 |
| 340 // Retrieve by ids each time since |callback| may destroy some contexts. | 338 // Retrieve by ids each time since |callback| may destroy some contexts. |
| 341 for (auto& contextId : ids) { | 339 for (auto& contextId : ids) { |
| 342 it = m_contexts.find(contextGroupId); | 340 it = m_contexts.find(contextGroupId); |
| 343 if (it == m_contexts.end()) continue; | 341 if (it == m_contexts.end()) continue; |
| 344 auto contextIt = it->second->find(contextId); | 342 auto contextIt = it->second->find(contextId); |
| 345 if (contextIt != it->second->end()) callback(contextIt->second.get()); | 343 if (contextIt != it->second->end()) callback(contextIt->second.get()); |
| 346 } | 344 } |
| 347 } | 345 } |
| 348 | 346 |
| 347 void V8InspectorImpl::forEachSession( |
| 348 int contextGroupId, std::function<void(V8InspectorSessionImpl*)> callback) { |
| 349 auto it = m_sessions.find(contextGroupId); |
| 350 if (it == m_sessions.end()) return; |
| 351 std::vector<int> ids; |
| 352 ids.reserve(it->second.size()); |
| 353 for (auto& sessionIt : it->second) ids.push_back(sessionIt.first); |
| 354 |
| 355 // Retrieve by ids each time since |callback| may destroy some contexts. |
| 356 for (auto& sessionId : ids) { |
| 357 it = m_sessions.find(contextGroupId); |
| 358 if (it == m_sessions.end()) continue; |
| 359 auto sessionIt = it->second.find(sessionId); |
| 360 if (sessionIt != it->second.end()) callback(sessionIt->second); |
| 361 } |
| 362 } |
| 363 |
| 349 } // namespace v8_inspector | 364 } // namespace v8_inspector |
| OLD | NEW |