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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "src/inspector/v8-inspector-impl.h" | 31 #include "src/inspector/v8-inspector-impl.h" |
32 | 32 |
| 33 #include <vector> |
| 34 |
33 #include "src/inspector/inspected-context.h" | 35 #include "src/inspector/inspected-context.h" |
34 #include "src/inspector/string-util.h" | 36 #include "src/inspector/string-util.h" |
35 #include "src/inspector/v8-console-agent-impl.h" | 37 #include "src/inspector/v8-console-agent-impl.h" |
36 #include "src/inspector/v8-console-message.h" | 38 #include "src/inspector/v8-console-message.h" |
37 #include "src/inspector/v8-console.h" | 39 #include "src/inspector/v8-console.h" |
38 #include "src/inspector/v8-debugger-agent-impl.h" | 40 #include "src/inspector/v8-debugger-agent-impl.h" |
39 #include "src/inspector/v8-debugger.h" | 41 #include "src/inspector/v8-debugger.h" |
40 #include "src/inspector/v8-inspector-session-impl.h" | 42 #include "src/inspector/v8-inspector-session-impl.h" |
41 #include "src/inspector/v8-profiler-agent-impl.h" | 43 #include "src/inspector/v8-profiler-agent-impl.h" |
42 #include "src/inspector/v8-runtime-agent-impl.h" | 44 #include "src/inspector/v8-runtime-agent-impl.h" |
(...skipping 24 matching lines...) Expand all Loading... |
67 int V8InspectorImpl::contextGroupId(v8::Local<v8::Context> context) { | 69 int V8InspectorImpl::contextGroupId(v8::Local<v8::Context> context) { |
68 return contextGroupId(InspectedContext::contextId(context)); | 70 return contextGroupId(InspectedContext::contextId(context)); |
69 } | 71 } |
70 | 72 |
71 int V8InspectorImpl::contextGroupId(int contextId) { | 73 int V8InspectorImpl::contextGroupId(int contextId) { |
72 protocol::HashMap<int, int>::iterator it = | 74 protocol::HashMap<int, int>::iterator it = |
73 m_contextIdToGroupIdMap.find(contextId); | 75 m_contextIdToGroupIdMap.find(contextId); |
74 return it != m_contextIdToGroupIdMap.end() ? it->second : 0; | 76 return it != m_contextIdToGroupIdMap.end() ? it->second : 0; |
75 } | 77 } |
76 | 78 |
77 V8DebuggerAgentImpl* V8InspectorImpl::enabledDebuggerAgentForGroup( | |
78 int contextGroupId) { | |
79 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); | |
80 V8DebuggerAgentImpl* agent = session ? session->debuggerAgent() : nullptr; | |
81 return agent && agent->enabled() ? agent : nullptr; | |
82 } | |
83 | |
84 V8RuntimeAgentImpl* V8InspectorImpl::enabledRuntimeAgentForGroup( | |
85 int contextGroupId) { | |
86 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); | |
87 V8RuntimeAgentImpl* agent = session ? session->runtimeAgent() : nullptr; | |
88 return agent && agent->enabled() ? agent : nullptr; | |
89 } | |
90 | |
91 V8ProfilerAgentImpl* V8InspectorImpl::enabledProfilerAgentForGroup( | |
92 int contextGroupId) { | |
93 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); | |
94 V8ProfilerAgentImpl* agent = session ? session->profilerAgent() : nullptr; | |
95 return agent && agent->enabled() ? agent : nullptr; | |
96 } | |
97 | |
98 v8::MaybeLocal<v8::Value> V8InspectorImpl::compileAndRunInternalScript( | 79 v8::MaybeLocal<v8::Value> V8InspectorImpl::compileAndRunInternalScript( |
99 v8::Local<v8::Context> context, v8::Local<v8::String> source) { | 80 v8::Local<v8::Context> context, v8::Local<v8::String> source) { |
100 v8::Local<v8::UnboundScript> unboundScript; | 81 v8::Local<v8::UnboundScript> unboundScript; |
101 if (!v8::debug::CompileInspectorScript(m_isolate, source) | 82 if (!v8::debug::CompileInspectorScript(m_isolate, source) |
102 .ToLocal(&unboundScript)) | 83 .ToLocal(&unboundScript)) |
103 return v8::MaybeLocal<v8::Value>(); | 84 return v8::MaybeLocal<v8::Value>(); |
104 v8::MicrotasksScope microtasksScope(m_isolate, | 85 v8::MicrotasksScope microtasksScope(m_isolate, |
105 v8::MicrotasksScope::kDoNotRunMicrotasks); | 86 v8::MicrotasksScope::kDoNotRunMicrotasks); |
106 v8::Context::Scope contextScope(context); | 87 v8::Context::Scope contextScope(context); |
107 return unboundScript->BindToCurrentContext()->Run(context); | 88 return unboundScript->BindToCurrentContext()->Run(context); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 145 |
165 std::unique_ptr<V8StackTrace> V8InspectorImpl::createStackTrace( | 146 std::unique_ptr<V8StackTrace> V8InspectorImpl::createStackTrace( |
166 v8::Local<v8::StackTrace> stackTrace) { | 147 v8::Local<v8::StackTrace> stackTrace) { |
167 return m_debugger->createStackTrace(stackTrace); | 148 return m_debugger->createStackTrace(stackTrace); |
168 } | 149 } |
169 | 150 |
170 std::unique_ptr<V8InspectorSession> V8InspectorImpl::connect( | 151 std::unique_ptr<V8InspectorSession> V8InspectorImpl::connect( |
171 int contextGroupId, V8Inspector::Channel* channel, | 152 int contextGroupId, V8Inspector::Channel* channel, |
172 const StringView& state) { | 153 const StringView& state) { |
173 DCHECK(m_sessions.find(contextGroupId) == m_sessions.cend()); | 154 DCHECK(m_sessions.find(contextGroupId) == m_sessions.cend()); |
| 155 int sessionId = ++m_lastSessionId; |
174 std::unique_ptr<V8InspectorSessionImpl> session = | 156 std::unique_ptr<V8InspectorSessionImpl> session = |
175 V8InspectorSessionImpl::create(this, contextGroupId, channel, state); | 157 V8InspectorSessionImpl::create(this, contextGroupId, sessionId, channel, |
| 158 state); |
176 m_sessions[contextGroupId] = session.get(); | 159 m_sessions[contextGroupId] = session.get(); |
| 160 m_sessionById[sessionId] = session.get(); |
177 return std::move(session); | 161 return std::move(session); |
178 } | 162 } |
179 | 163 |
180 void V8InspectorImpl::disconnect(V8InspectorSessionImpl* session) { | 164 void V8InspectorImpl::disconnect(V8InspectorSessionImpl* session) { |
181 DCHECK(m_sessions.find(session->contextGroupId()) != m_sessions.end()); | 165 DCHECK(m_sessions.find(session->contextGroupId()) != m_sessions.end()); |
182 m_sessions.erase(session->contextGroupId()); | 166 m_sessions.erase(session->contextGroupId()); |
| 167 m_sessionById.erase(session->sessionId()); |
183 } | 168 } |
184 | 169 |
185 InspectedContext* V8InspectorImpl::getContext(int groupId, | 170 InspectedContext* V8InspectorImpl::getContext(int groupId, |
186 int contextId) const { | 171 int contextId) const { |
187 if (!groupId || !contextId) return nullptr; | 172 if (!groupId || !contextId) return nullptr; |
188 | 173 |
189 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId); | 174 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId); |
190 if (contextGroupIt == m_contexts.end()) return nullptr; | 175 if (contextGroupIt == m_contexts.end()) return nullptr; |
191 | 176 |
192 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId); | 177 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 return m_regexContext.Get(m_isolate); | 305 return m_regexContext.Get(m_isolate); |
321 } | 306 } |
322 | 307 |
323 void V8InspectorImpl::discardInspectedContext(int contextGroupId, | 308 void V8InspectorImpl::discardInspectedContext(int contextGroupId, |
324 int contextId) { | 309 int contextId) { |
325 if (!getContext(contextGroupId, contextId)) return; | 310 if (!getContext(contextGroupId, contextId)) return; |
326 m_contexts[contextGroupId]->erase(contextId); | 311 m_contexts[contextGroupId]->erase(contextId); |
327 if (m_contexts[contextGroupId]->empty()) m_contexts.erase(contextGroupId); | 312 if (m_contexts[contextGroupId]->empty()) m_contexts.erase(contextGroupId); |
328 } | 313 } |
329 | 314 |
330 const V8InspectorImpl::ContextByIdMap* V8InspectorImpl::contextGroup( | |
331 int contextGroupId) { | |
332 ContextsByGroupMap::iterator iter = m_contexts.find(contextGroupId); | |
333 return iter == m_contexts.end() ? nullptr : iter->second.get(); | |
334 } | |
335 | |
336 V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup( | 315 V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup( |
337 int contextGroupId) { | 316 int contextGroupId) { |
338 if (!contextGroupId) return nullptr; | 317 if (!contextGroupId) return nullptr; |
339 SessionMap::iterator iter = m_sessions.find(contextGroupId); | 318 SessionMap::iterator iter = m_sessions.find(contextGroupId); |
340 return iter == m_sessions.end() ? nullptr : iter->second; | 319 return iter == m_sessions.end() ? nullptr : iter->second; |
341 } | 320 } |
342 | 321 |
| 322 V8InspectorSessionImpl* V8InspectorImpl::sessionById(int sessionId) { |
| 323 auto it = m_sessionById.find(sessionId); |
| 324 return it == m_sessionById.end() ? nullptr : it->second; |
| 325 } |
| 326 |
343 V8Console* V8InspectorImpl::console() { | 327 V8Console* V8InspectorImpl::console() { |
344 if (!m_console) m_console.reset(new V8Console(this)); | 328 if (!m_console) m_console.reset(new V8Console(this)); |
345 return m_console.get(); | 329 return m_console.get(); |
346 } | 330 } |
347 | 331 |
| 332 void V8InspectorImpl::forEachContext( |
| 333 int contextGroupId, std::function<void(InspectedContext*)> callback) { |
| 334 auto it = m_contexts.find(contextGroupId); |
| 335 if (it == m_contexts.end()) return; |
| 336 std::vector<int> ids; |
| 337 ids.reserve(it->second->size()); |
| 338 for (auto& contextIt : *(it->second)) ids.push_back(contextIt.first); |
| 339 |
| 340 // Retrieve by ids each time since |callback| may destroy some contexts. |
| 341 for (auto& contextId : ids) { |
| 342 it = m_contexts.find(contextGroupId); |
| 343 if (it == m_contexts.end()) continue; |
| 344 auto contextIt = it->second->find(contextId); |
| 345 if (contextIt != it->second->end()) callback(contextIt->second.get()); |
| 346 } |
| 347 } |
| 348 |
348 } // namespace v8_inspector | 349 } // namespace v8_inspector |
OLD | NEW |