OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 5 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
6 | 6 |
7 #include "platform/inspector_protocol/Parser.h" | 7 #include "platform/inspector_protocol/Parser.h" |
8 #include "platform/v8_inspector/InjectedScript.h" | 8 #include "platform/v8_inspector/InjectedScript.h" |
9 #include "platform/v8_inspector/InspectedContext.h" | 9 #include "platform/v8_inspector/InspectedContext.h" |
10 #include "platform/v8_inspector/RemoteObjectId.h" | 10 #include "platform/v8_inspector/RemoteObjectId.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 discardInjectedScripts(); | 104 discardInjectedScripts(); |
105 } | 105 } |
106 | 106 |
107 void V8InspectorSessionImpl::discardInjectedScripts() | 107 void V8InspectorSessionImpl::discardInjectedScripts() |
108 { | 108 { |
109 m_inspectedObjects.clear(); | 109 m_inspectedObjects.clear(); |
110 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); | 110 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); |
111 if (!contexts) | 111 if (!contexts) |
112 return; | 112 return; |
113 | 113 |
114 protocol::Vector<int> keys; | 114 std::vector<int> keys; |
115 keys.reserve(contexts->size()); | |
115 for (auto& idContext : *contexts) | 116 for (auto& idContext : *contexts) |
116 keys.append(idContext.first); | 117 keys.push_back(idContext.first); |
117 for (auto& key : keys) { | 118 for (auto& key : keys) { |
118 contexts = m_debugger->contextGroup(m_contextGroupId); | 119 contexts = m_debugger->contextGroup(m_contextGroupId); |
119 if (contexts && contexts->contains(key)) | 120 if (contexts) { |
120 contexts->get(key)->discardInjectedScript(); // This may destroy som e contexts. | 121 auto context_iter = contexts->find(key); |
dgozman
2016/06/24 17:01:13
Blink avoids abbreviations as much as possible, bu
eostroukhov-old
2016/06/24 22:24:26
Done.
| |
122 if (context_iter != contexts->end()) { | |
dgozman
2016/06/24 17:01:13
style: extra {}
eostroukhov-old
2016/06/24 22:24:26
Done.
| |
123 context_iter->second->discardInjectedScript(); // This may destr oy some contexts. | |
124 } | |
125 } | |
121 } | 126 } |
122 } | 127 } |
123 | 128 |
124 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr ing, int contextId) | 129 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr ing, int contextId) |
125 { | 130 { |
126 if (!contextId) { | 131 if (!contextId) { |
127 *errorString = "Cannot find context with specified id"; | 132 *errorString = "Cannot find context with specified id"; |
128 return nullptr; | 133 return nullptr; |
129 } | 134 } |
130 | 135 |
131 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); | 136 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); |
132 if (!contexts || !contexts->contains(contextId)) { | 137 auto contexts_iter = contexts ? contexts->find(contextId) : contexts->end(); |
138 if (contexts_iter == contexts->end()) { | |
133 *errorString = "Cannot find context with specified id"; | 139 *errorString = "Cannot find context with specified id"; |
134 return nullptr; | 140 return nullptr; |
135 } | 141 } |
136 | 142 |
137 InspectedContext* context = contexts->get(contextId); | 143 const std::unique_ptr<InspectedContext>& context = contexts_iter->second; |
138 if (!context->getInjectedScript()) { | 144 if (!context->getInjectedScript()) { |
139 context->createInjectedScript(); | 145 context->createInjectedScript(); |
140 if (!context->getInjectedScript()) { | 146 if (!context->getInjectedScript()) { |
141 *errorString = "Cannot access specified execution context"; | 147 *errorString = "Cannot access specified execution context"; |
142 return nullptr; | 148 return nullptr; |
143 } | 149 } |
144 if (m_customObjectFormatterEnabled) | 150 if (m_customObjectFormatterEnabled) |
145 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); | 151 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); |
146 } | 152 } |
147 return context->getInjectedScript(); | 153 return context->getInjectedScript(); |
148 } | 154 } |
149 | 155 |
150 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr ing, RemoteObjectIdBase* objectId) | 156 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr ing, RemoteObjectIdBase* objectId) |
151 { | 157 { |
152 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n ullptr; | 158 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n ullptr; |
153 } | 159 } |
154 | 160 |
155 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) | 161 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) |
156 { | 162 { |
157 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); | 163 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); |
158 if (!contexts) | 164 if (!contexts) |
159 return; | 165 return; |
160 | 166 |
161 protocol::Vector<int> keys; | 167 std::vector<int> keys; |
162 for (auto& idContext : *contexts) | 168 for (auto& idContext : *contexts) |
163 keys.append(idContext.first); | 169 keys.push_back(idContext.first); |
164 for (auto& key : keys) { | 170 for (auto& key : keys) { |
165 contexts = m_debugger->contextGroup(m_contextGroupId); | 171 contexts = m_debugger->contextGroup(m_contextGroupId); |
166 if (contexts && contexts->contains(key)) { | 172 if (contexts) { |
alph
2016/06/24 17:37:27
nit: here and everywhere:
if (!contexts) continue;
eostroukhov-old
2016/06/24 22:24:26
Done.
| |
167 InjectedScript* injectedScript = contexts->get(key)->getInjectedScri pt(); | 173 auto contexts_iter = contexts->find(key); |
168 if (injectedScript) | 174 if (contexts_iter != contexts->end()) { |
169 injectedScript->releaseObjectGroup(objectGroup); // This may des troy some contexts. | 175 InjectedScript* injectedScript = contexts_iter->second->getInjec tedScript(); |
176 if (injectedScript) | |
177 injectedScript->releaseObjectGroup(objectGroup); // This may destroy some contexts. | |
178 } | |
170 } | 179 } |
171 } | 180 } |
172 } | 181 } |
173 | 182 |
174 v8::Local<v8::Value> V8InspectorSessionImpl::findObject(ErrorString* errorString , const String16& objectId, v8::Local<v8::Context>* context, String16* groupName ) | 183 v8::Local<v8::Value> V8InspectorSessionImpl::findObject(ErrorString* errorString , const String16& objectId, v8::Local<v8::Context>* context, String16* groupName ) |
175 { | 184 { |
176 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString , objectId); | 185 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString , objectId); |
177 if (!remoteId) | 186 if (!remoteId) |
178 return v8::Local<v8::Value>(); | 187 return v8::Local<v8::Value>(); |
179 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge t()); | 188 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge t()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 injectedScript->setCustomObjectFormatterEnabled(enabled); | 229 injectedScript->setCustomObjectFormatterEnabled(enabled); |
221 } | 230 } |
222 } | 231 } |
223 | 232 |
224 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) | 233 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) |
225 { | 234 { |
226 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); | 235 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); |
227 if (!contexts) | 236 if (!contexts) |
228 return; | 237 return; |
229 for (auto& idContext : *contexts) | 238 for (auto& idContext : *contexts) |
230 agent->reportExecutionContextCreated(idContext.second); | 239 agent->reportExecutionContextCreated(idContext.second.get()); |
231 } | 240 } |
232 | 241 |
233 void V8InspectorSessionImpl::changeInstrumentationCounter(int delta) | 242 void V8InspectorSessionImpl::changeInstrumentationCounter(int delta) |
234 { | 243 { |
235 DCHECK_GE(m_instrumentationCounter + delta, 0); | 244 DCHECK_GE(m_instrumentationCounter + delta, 0); |
236 if (!m_instrumentationCounter) | 245 if (!m_instrumentationCounter) |
237 m_client->startInstrumenting(); | 246 m_client->startInstrumenting(); |
238 m_instrumentationCounter += delta; | 247 m_instrumentationCounter += delta; |
239 if (!m_instrumentationCounter) | 248 if (!m_instrumentationCounter) |
240 m_client->stopInstrumenting(); | 249 m_client->stopInstrumenting(); |
241 } | 250 } |
242 | 251 |
243 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) | 252 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) |
244 { | 253 { |
245 m_dispatcher.dispatch(message); | 254 m_dispatcher.dispatch(message); |
246 } | 255 } |
247 | 256 |
248 String16 V8InspectorSessionImpl::stateJSON() | 257 String16 V8InspectorSessionImpl::stateJSON() |
249 { | 258 { |
250 return m_state->toJSONString(); | 259 return m_state->toJSONString(); |
251 } | 260 } |
252 | 261 |
253 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi on::Inspectable> inspectable) | 262 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi on::Inspectable> inspectable) |
254 { | 263 { |
255 m_inspectedObjects.prepend(std::move(inspectable)); | 264 m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable) ); |
256 while (m_inspectedObjects.size() > kInspectedObjectBufferSize) | 265 if (m_inspectedObjects.size() > kInspectedObjectBufferSize) |
257 m_inspectedObjects.removeLast(); | 266 m_inspectedObjects.resize(kInspectedObjectBufferSize); |
258 } | 267 } |
259 | 268 |
260 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num) | 269 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num) |
261 { | 270 { |
262 if (num >= m_inspectedObjects.size()) | 271 if (num >= m_inspectedObjects.size()) |
263 return nullptr; | 272 return nullptr; |
264 return m_inspectedObjects[num]; | 273 return m_inspectedObjects[num].get(); |
265 } | 274 } |
266 | 275 |
267 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR eason, std::unique_ptr<protocol::DictionaryValue> data) | 276 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR eason, std::unique_ptr<protocol::DictionaryValue> data) |
268 { | 277 { |
269 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, std::move(data)); | 278 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, std::move(data)); |
270 } | 279 } |
271 | 280 |
272 void V8InspectorSessionImpl::cancelPauseOnNextStatement() | 281 void V8InspectorSessionImpl::cancelPauseOnNextStatement() |
273 { | 282 { |
274 m_debuggerAgent->cancelPauseOnNextStatement(); | 283 m_debuggerAgent->cancelPauseOnNextStatement(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 { | 330 { |
322 m_debuggerAgent->asyncTaskFinished(task); | 331 m_debuggerAgent->asyncTaskFinished(task); |
323 } | 332 } |
324 | 333 |
325 void V8InspectorSessionImpl::allAsyncTasksCanceled() | 334 void V8InspectorSessionImpl::allAsyncTasksCanceled() |
326 { | 335 { |
327 m_debuggerAgent->allAsyncTasksCanceled(); | 336 m_debuggerAgent->allAsyncTasksCanceled(); |
328 } | 337 } |
329 | 338 |
330 } // namespace blink | 339 } // namespace blink |
OLD | NEW |