Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: src/inspector/v8-inspector-impl.cc

Issue 2558913004: [inspector] Store interger in context embedder data instead of a string. (Closed)
Patch Set: review comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/v8-inspector-impl.h ('k') | src/inspector/v8-inspector-session-impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 V8InspectorClient* client) { 47 V8InspectorClient* client) {
48 return std::unique_ptr<V8Inspector>(new V8InspectorImpl(isolate, client)); 48 return std::unique_ptr<V8Inspector>(new V8InspectorImpl(isolate, client));
49 } 49 }
50 50
51 V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate, 51 V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate,
52 V8InspectorClient* client) 52 V8InspectorClient* client)
53 : m_isolate(isolate), 53 : m_isolate(isolate),
54 m_client(client), 54 m_client(client),
55 m_debugger(new V8Debugger(isolate, this)), 55 m_debugger(new V8Debugger(isolate, this)),
56 m_capturingStackTracesCount(0), 56 m_capturingStackTracesCount(0),
57 m_lastExceptionId(0) {} 57 m_lastExceptionId(0),
58 m_lastContextId(0) {}
58 59
59 V8InspectorImpl::~V8InspectorImpl() {} 60 V8InspectorImpl::~V8InspectorImpl() {}
60 61
62 int V8InspectorImpl::contextGroupId(v8::Local<v8::Context> context) {
63 return contextGroupId(InspectedContext::contextId(context));
64 }
65
66 int V8InspectorImpl::contextGroupId(int contextId) {
67 protocol::HashMap<int, int>::iterator it =
68 m_contextIdToGroupIdMap.find(contextId);
69 return it != m_contextIdToGroupIdMap.end() ? it->second : 0;
70 }
71
61 V8DebuggerAgentImpl* V8InspectorImpl::enabledDebuggerAgentForGroup( 72 V8DebuggerAgentImpl* V8InspectorImpl::enabledDebuggerAgentForGroup(
62 int contextGroupId) { 73 int contextGroupId) {
63 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); 74 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId);
64 V8DebuggerAgentImpl* agent = session ? session->debuggerAgent() : nullptr; 75 V8DebuggerAgentImpl* agent = session ? session->debuggerAgent() : nullptr;
65 return agent && agent->enabled() ? agent : nullptr; 76 return agent && agent->enabled() ? agent : nullptr;
66 } 77 }
67 78
68 V8RuntimeAgentImpl* V8InspectorImpl::enabledRuntimeAgentForGroup( 79 V8RuntimeAgentImpl* V8InspectorImpl::enabledRuntimeAgentForGroup(
69 int contextGroupId) { 80 int contextGroupId) {
70 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); 81 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId);
71 V8RuntimeAgentImpl* agent = session ? session->runtimeAgent() : nullptr; 82 V8RuntimeAgentImpl* agent = session ? session->runtimeAgent() : nullptr;
72 return agent && agent->enabled() ? agent : nullptr; 83 return agent && agent->enabled() ? agent : nullptr;
73 } 84 }
74 85
75 V8ProfilerAgentImpl* V8InspectorImpl::enabledProfilerAgentForGroup( 86 V8ProfilerAgentImpl* V8InspectorImpl::enabledProfilerAgentForGroup(
76 int contextGroupId) { 87 int contextGroupId) {
77 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); 88 V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId);
78 V8ProfilerAgentImpl* agent = session ? session->profilerAgent() : nullptr; 89 V8ProfilerAgentImpl* agent = session ? session->profilerAgent() : nullptr;
79 return agent && agent->enabled() ? agent : nullptr; 90 return agent && agent->enabled() ? agent : nullptr;
80 } 91 }
81 92
82 v8::MaybeLocal<v8::Value> V8InspectorImpl::runCompiledScript( 93 v8::MaybeLocal<v8::Value> V8InspectorImpl::runCompiledScript(
83 v8::Local<v8::Context> context, v8::Local<v8::Script> script) { 94 v8::Local<v8::Context> context, v8::Local<v8::Script> script) {
84 v8::MicrotasksScope microtasksScope(m_isolate, 95 v8::MicrotasksScope microtasksScope(m_isolate,
85 v8::MicrotasksScope::kRunMicrotasks); 96 v8::MicrotasksScope::kRunMicrotasks);
86 int groupId = V8Debugger::getGroupId(context); 97 int groupId = contextGroupId(context);
87 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId)) 98 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
88 agent->willExecuteScript(script->GetUnboundScript()->GetId()); 99 agent->willExecuteScript(script->GetUnboundScript()->GetId());
89 v8::MaybeLocal<v8::Value> result = script->Run(context); 100 v8::MaybeLocal<v8::Value> result = script->Run(context);
90 // Get agent from the map again, since it could have detached during script 101 // Get agent from the map again, since it could have detached during script
91 // execution. 102 // execution.
92 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId)) 103 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
93 agent->didExecuteScript(); 104 agent->didExecuteScript();
94 return result; 105 return result;
95 } 106 }
96 107
97 v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction( 108 v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(
98 v8::Local<v8::Function> function, v8::Local<v8::Context> context, 109 v8::Local<v8::Function> function, v8::Local<v8::Context> context,
99 v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) { 110 v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) {
100 return callFunction(function, context, receiver, argc, info, 111 return callFunction(function, context, receiver, argc, info,
101 v8::MicrotasksScope::kRunMicrotasks); 112 v8::MicrotasksScope::kRunMicrotasks);
102 } 113 }
103 114
104 v8::MaybeLocal<v8::Value> V8InspectorImpl::callInternalFunction( 115 v8::MaybeLocal<v8::Value> V8InspectorImpl::callInternalFunction(
105 v8::Local<v8::Function> function, v8::Local<v8::Context> context, 116 v8::Local<v8::Function> function, v8::Local<v8::Context> context,
106 v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) { 117 v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) {
107 return callFunction(function, context, receiver, argc, info, 118 return callFunction(function, context, receiver, argc, info,
108 v8::MicrotasksScope::kDoNotRunMicrotasks); 119 v8::MicrotasksScope::kDoNotRunMicrotasks);
109 } 120 }
110 121
111 v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction( 122 v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(
112 v8::Local<v8::Function> function, v8::Local<v8::Context> context, 123 v8::Local<v8::Function> function, v8::Local<v8::Context> context,
113 v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[], 124 v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[],
114 v8::MicrotasksScope::Type runMicrotasks) { 125 v8::MicrotasksScope::Type runMicrotasks) {
115 v8::MicrotasksScope microtasksScope(m_isolate, runMicrotasks); 126 v8::MicrotasksScope microtasksScope(m_isolate, runMicrotasks);
116 int groupId = V8Debugger::getGroupId(context); 127 int groupId = contextGroupId(context);
117 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId)) 128 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
118 agent->willExecuteScript(function->ScriptId()); 129 agent->willExecuteScript(function->ScriptId());
119 v8::MaybeLocal<v8::Value> result = 130 v8::MaybeLocal<v8::Value> result =
120 function->Call(context, receiver, argc, info); 131 function->Call(context, receiver, argc, info);
121 // Get agent from the map again, since it could have detached during script 132 // Get agent from the map again, since it could have detached during script
122 // execution. 133 // execution.
123 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId)) 134 if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
124 agent->didExecuteScript(); 135 agent->didExecuteScript();
125 return result; 136 return result;
126 } 137 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId); 230 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId);
220 if (contextGroupIt == m_contexts.end()) return nullptr; 231 if (contextGroupIt == m_contexts.end()) return nullptr;
221 232
222 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId); 233 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId);
223 if (contextIt == contextGroupIt->second->end()) return nullptr; 234 if (contextIt == contextGroupIt->second->end()) return nullptr;
224 235
225 return contextIt->second.get(); 236 return contextIt->second.get();
226 } 237 }
227 238
228 void V8InspectorImpl::contextCreated(const V8ContextInfo& info) { 239 void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
229 int contextId = m_debugger->markContext(info); 240 int contextId = ++m_lastContextId;
241 InspectedContext* context = new InspectedContext(this, info, contextId);
242 m_contextIdToGroupIdMap[contextId] = info.contextGroupId;
230 243
231 ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId); 244 ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId);
232 if (contextIt == m_contexts.end()) 245 if (contextIt == m_contexts.end())
233 contextIt = m_contexts 246 contextIt = m_contexts
234 .insert(std::make_pair( 247 .insert(std::make_pair(
235 info.contextGroupId, 248 info.contextGroupId,
236 std::unique_ptr<ContextByIdMap>(new ContextByIdMap()))) 249 std::unique_ptr<ContextByIdMap>(new ContextByIdMap())))
237 .first; 250 .first;
238
239 const auto& contextById = contextIt->second; 251 const auto& contextById = contextIt->second;
240 252
241 DCHECK(contextById->find(contextId) == contextById->cend()); 253 DCHECK(contextById->find(contextId) == contextById->cend());
242 InspectedContext* context = new InspectedContext(this, info, contextId);
243 (*contextById)[contextId].reset(context); 254 (*contextById)[contextId].reset(context);
244 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId); 255 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId);
245 if (sessionIt != m_sessions.end()) 256 if (sessionIt != m_sessions.end())
246 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context); 257 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context);
247 } 258 }
248 259
249 void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) { 260 void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) {
250 int contextId = V8Debugger::contextId(context); 261 int contextId = InspectedContext::contextId(context);
251 int contextGroupId = V8Debugger::getGroupId(context); 262 int groupId = contextGroupId(context);
263 m_contextIdToGroupIdMap.erase(contextId);
252 264
253 ConsoleStorageMap::iterator storageIt = 265 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(groupId);
254 m_consoleStorageMap.find(contextGroupId);
255 if (storageIt != m_consoleStorageMap.end()) 266 if (storageIt != m_consoleStorageMap.end())
256 storageIt->second->contextDestroyed(contextId); 267 storageIt->second->contextDestroyed(contextId);
257 268
258 InspectedContext* inspectedContext = getContext(contextGroupId, contextId); 269 InspectedContext* inspectedContext = getContext(groupId, contextId);
259 if (!inspectedContext) return; 270 if (!inspectedContext) return;
260 271
261 SessionMap::iterator iter = m_sessions.find(contextGroupId); 272 SessionMap::iterator iter = m_sessions.find(groupId);
262 if (iter != m_sessions.end()) 273 if (iter != m_sessions.end())
263 iter->second->runtimeAgent()->reportExecutionContextDestroyed( 274 iter->second->runtimeAgent()->reportExecutionContextDestroyed(
264 inspectedContext); 275 inspectedContext);
265 discardInspectedContext(contextGroupId, contextId); 276 discardInspectedContext(groupId, contextId);
266 } 277 }
267 278
268 void V8InspectorImpl::resetContextGroup(int contextGroupId) { 279 void V8InspectorImpl::resetContextGroup(int contextGroupId) {
269 m_consoleStorageMap.erase(contextGroupId); 280 m_consoleStorageMap.erase(contextGroupId);
270 m_muteExceptionsMap.erase(contextGroupId); 281 m_muteExceptionsMap.erase(contextGroupId);
271 SessionMap::iterator session = m_sessions.find(contextGroupId); 282 SessionMap::iterator session = m_sessions.find(contextGroupId);
272 if (session != m_sessions.end()) session->second->reset(); 283 if (session != m_sessions.end()) session->second->reset();
273 m_contexts.erase(contextGroupId); 284 m_contexts.erase(contextGroupId);
274 m_debugger->wasmTranslation()->Clear(); 285 m_debugger->wasmTranslation()->Clear();
275 } 286 }
276 287
277 void V8InspectorImpl::willExecuteScript(v8::Local<v8::Context> context, 288 void V8InspectorImpl::willExecuteScript(v8::Local<v8::Context> context,
278 int scriptId) { 289 int scriptId) {
279 if (V8DebuggerAgentImpl* agent = 290 if (V8DebuggerAgentImpl* agent =
280 enabledDebuggerAgentForGroup(V8Debugger::getGroupId(context))) 291 enabledDebuggerAgentForGroup(contextGroupId(context))) {
281 agent->willExecuteScript(scriptId); 292 agent->willExecuteScript(scriptId);
293 }
282 } 294 }
283 295
284 void V8InspectorImpl::didExecuteScript(v8::Local<v8::Context> context) { 296 void V8InspectorImpl::didExecuteScript(v8::Local<v8::Context> context) {
285 if (V8DebuggerAgentImpl* agent = 297 if (V8DebuggerAgentImpl* agent =
286 enabledDebuggerAgentForGroup(V8Debugger::getGroupId(context))) 298 enabledDebuggerAgentForGroup(contextGroupId(context))) {
287 agent->didExecuteScript(); 299 agent->didExecuteScript();
300 }
288 } 301 }
289 302
290 void V8InspectorImpl::idleStarted() { 303 void V8InspectorImpl::idleStarted() {
291 for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) { 304 for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) {
292 if (it->second->profilerAgent()->idleStarted()) return; 305 if (it->second->profilerAgent()->idleStarted()) return;
293 } 306 }
294 } 307 }
295 308
296 void V8InspectorImpl::idleFinished() { 309 void V8InspectorImpl::idleFinished() {
297 for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) { 310 for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) {
298 if (it->second->profilerAgent()->idleFinished()) return; 311 if (it->second->profilerAgent()->idleFinished()) return;
299 } 312 }
300 } 313 }
301 314
302 unsigned V8InspectorImpl::exceptionThrown( 315 unsigned V8InspectorImpl::exceptionThrown(
303 v8::Local<v8::Context> context, const StringView& message, 316 v8::Local<v8::Context> context, const StringView& message,
304 v8::Local<v8::Value> exception, const StringView& detailedMessage, 317 v8::Local<v8::Value> exception, const StringView& detailedMessage,
305 const StringView& url, unsigned lineNumber, unsigned columnNumber, 318 const StringView& url, unsigned lineNumber, unsigned columnNumber,
306 std::unique_ptr<V8StackTrace> stackTrace, int scriptId) { 319 std::unique_ptr<V8StackTrace> stackTrace, int scriptId) {
307 int contextGroupId = V8Debugger::getGroupId(context); 320 int groupId = contextGroupId(context);
308 if (!contextGroupId || m_muteExceptionsMap[contextGroupId]) return 0; 321 if (!groupId || m_muteExceptionsMap[groupId]) return 0;
309 std::unique_ptr<V8StackTraceImpl> stackTraceImpl( 322 std::unique_ptr<V8StackTraceImpl> stackTraceImpl(
310 static_cast<V8StackTraceImpl*>(stackTrace.release())); 323 static_cast<V8StackTraceImpl*>(stackTrace.release()));
311 unsigned exceptionId = nextExceptionId(); 324 unsigned exceptionId = nextExceptionId();
312 std::unique_ptr<V8ConsoleMessage> consoleMessage = 325 std::unique_ptr<V8ConsoleMessage> consoleMessage =
313 V8ConsoleMessage::createForException( 326 V8ConsoleMessage::createForException(
314 m_client->currentTimeMS(), toString16(detailedMessage), 327 m_client->currentTimeMS(), toString16(detailedMessage),
315 toString16(url), lineNumber, columnNumber, std::move(stackTraceImpl), 328 toString16(url), lineNumber, columnNumber, std::move(stackTraceImpl),
316 scriptId, m_isolate, toString16(message), 329 scriptId, m_isolate, toString16(message),
317 V8Debugger::contextId(context), exception, exceptionId); 330 InspectedContext::contextId(context), exception, exceptionId);
318 ensureConsoleMessageStorage(contextGroupId) 331 ensureConsoleMessageStorage(groupId)->addMessage(std::move(consoleMessage));
319 ->addMessage(std::move(consoleMessage));
320 return exceptionId; 332 return exceptionId;
321 } 333 }
322 334
323 void V8InspectorImpl::exceptionRevoked(v8::Local<v8::Context> context, 335 void V8InspectorImpl::exceptionRevoked(v8::Local<v8::Context> context,
324 unsigned exceptionId, 336 unsigned exceptionId,
325 const StringView& message) { 337 const StringView& message) {
326 int contextGroupId = V8Debugger::getGroupId(context); 338 int groupId = contextGroupId(context);
327 if (!contextGroupId) return; 339 if (!groupId) return;
328 340
329 std::unique_ptr<V8ConsoleMessage> consoleMessage = 341 std::unique_ptr<V8ConsoleMessage> consoleMessage =
330 V8ConsoleMessage::createForRevokedException( 342 V8ConsoleMessage::createForRevokedException(
331 m_client->currentTimeMS(), toString16(message), exceptionId); 343 m_client->currentTimeMS(), toString16(message), exceptionId);
332 ensureConsoleMessageStorage(contextGroupId) 344 ensureConsoleMessageStorage(groupId)->addMessage(std::move(consoleMessage));
333 ->addMessage(std::move(consoleMessage));
334 } 345 }
335 346
336 std::unique_ptr<V8StackTrace> V8InspectorImpl::captureStackTrace( 347 std::unique_ptr<V8StackTrace> V8InspectorImpl::captureStackTrace(
337 bool fullStack) { 348 bool fullStack) {
338 return m_debugger->captureStackTrace(fullStack); 349 return m_debugger->captureStackTrace(fullStack);
339 } 350 }
340 351
341 void V8InspectorImpl::asyncTaskScheduled(const StringView& taskName, void* task, 352 void V8InspectorImpl::asyncTaskScheduled(const StringView& taskName, void* task,
342 bool recurring) { 353 bool recurring) {
343 m_debugger->asyncTaskScheduled(taskName, task, recurring); 354 m_debugger->asyncTaskScheduled(taskName, task, recurring);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 390 }
380 391
381 V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup( 392 V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup(
382 int contextGroupId) { 393 int contextGroupId) {
383 if (!contextGroupId) return nullptr; 394 if (!contextGroupId) return nullptr;
384 SessionMap::iterator iter = m_sessions.find(contextGroupId); 395 SessionMap::iterator iter = m_sessions.find(contextGroupId);
385 return iter == m_sessions.end() ? nullptr : iter->second; 396 return iter == m_sessions.end() ? nullptr : iter->second;
386 } 397 }
387 398
388 } // namespace v8_inspector 399 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-inspector-impl.h ('k') | src/inspector/v8-inspector-session-impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698