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

Side by Side Diff: Source/core/inspector/AsyncCallStackTracker.cpp

Issue 374903002: DevTools: Async call stacks for Promises and Object.observe. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 5 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 22 matching lines...) Expand all
33 33
34 #include "bindings/core/v8/V8Binding.h" 34 #include "bindings/core/v8/V8Binding.h"
35 #include "bindings/core/v8/V8RecursionScope.h" 35 #include "bindings/core/v8/V8RecursionScope.h"
36 #include "core/dom/ContextLifecycleObserver.h" 36 #include "core/dom/ContextLifecycleObserver.h"
37 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "core/dom/ExecutionContextTask.h" 38 #include "core/dom/ExecutionContextTask.h"
39 #include "core/events/Event.h" 39 #include "core/events/Event.h"
40 #include "core/events/EventTarget.h" 40 #include "core/events/EventTarget.h"
41 #include "core/xml/XMLHttpRequest.h" 41 #include "core/xml/XMLHttpRequest.h"
42 #include "core/xml/XMLHttpRequestUpload.h" 42 #include "core/xml/XMLHttpRequestUpload.h"
43 #include "wtf/text/AtomicStringHash.h"
44 #include "wtf/text/StringBuilder.h" 43 #include "wtf/text/StringBuilder.h"
44 #include "wtf/text/StringHash.h"
45 #include <v8.h> 45 #include <v8.h>
46 46
47 namespace { 47 namespace {
48 48
49 static const char setTimeoutName[] = "setTimeout"; 49 static const char setTimeoutName[] = "setTimeout";
50 static const char setIntervalName[] = "setInterval"; 50 static const char setIntervalName[] = "setInterval";
51 static const char requestAnimationFrameName[] = "requestAnimationFrame"; 51 static const char requestAnimationFrameName[] = "requestAnimationFrame";
52 static const char xhrSendName[] = "XMLHttpRequest.send"; 52 static const char xhrSendName[] = "XMLHttpRequest.send";
53 static const char enqueueMutationRecordName[] = "Mutation"; 53 static const char enqueueMutationRecordName[] = "Mutation";
54 54
(...skipping 21 matching lines...) Expand all
76 76
77 public: 77 public:
78 AsyncCallStackTracker* m_tracker; 78 AsyncCallStackTracker* m_tracker;
79 HashSet<int> m_intervalTimerIds; 79 HashSet<int> m_intervalTimerIds;
80 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; 80 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains;
81 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; 81 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains;
82 HashMap<Event*, RefPtr<AsyncCallChain> > m_eventCallChains; 82 HashMap<Event*, RefPtr<AsyncCallChain> > m_eventCallChains;
83 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains; 83 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains;
84 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh ains; 84 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh ains;
85 HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_executionContextTa skCallChains; 85 HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_executionContextTa skCallChains;
86 HashMap<String, RefPtr<AsyncCallChain> > m_v8AsyncTaskCallChains;
86 }; 87 };
87 88
88 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) 89 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget)
89 { 90 {
90 const AtomicString& interfaceName = eventTarget->interfaceName(); 91 const AtomicString& interfaceName = eventTarget->interfaceName();
91 if (interfaceName == EventTargetNames::XMLHttpRequest) 92 if (interfaceName == EventTargetNames::XMLHttpRequest)
92 return static_cast<XMLHttpRequest*>(eventTarget); 93 return static_cast<XMLHttpRequest*>(eventTarget);
93 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) 94 if (interfaceName == EventTargetNames::XMLHttpRequestUpload)
94 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest() ; 95 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest() ;
95 return 0; 96 return 0;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 void AsyncCallStackTracker::willPerformExecutionContextTask(ExecutionContext* co ntext, ExecutionContextTask* task) 320 void AsyncCallStackTracker::willPerformExecutionContextTask(ExecutionContext* co ntext, ExecutionContextTask* task)
320 { 321 {
321 ASSERT(context); 322 ASSERT(context);
322 ASSERT(isEnabled()); 323 ASSERT(isEnabled());
323 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) 324 if (ExecutionContextData* data = m_executionContextDataMap.get(context))
324 setCurrentAsyncCallChain(context, data->m_executionContextTaskCallChains .take(task)); 325 setCurrentAsyncCallChain(context, data->m_executionContextTaskCallChains .take(task));
325 else 326 else
326 setCurrentAsyncCallChain(context, nullptr); 327 setCurrentAsyncCallChain(context, nullptr);
327 } 328 }
328 329
330 static String makeV8AsyncTaskUniqueId(const String& eventName, int id)
331 {
332 StringBuilder builder;
333 builder.append(eventName);
334 builder.appendNumber(id);
335 return builder.toString();
336 }
337
338 void AsyncCallStackTracker::didEnqueueV8AsyncTask(ExecutionContext* context, con st String& eventName, int id, const ScriptValue& callFrames)
339 {
340 ASSERT(context);
341 ASSERT(isEnabled());
342 if (!validateCallFrames(callFrames))
343 return;
344 ExecutionContextData* data = createContextDataIfNeeded(context);
345 data->m_v8AsyncTaskCallChains.set(makeV8AsyncTaskUniqueId(eventName, id), cr eateAsyncCallChain(eventName, callFrames));
346 }
347
348 void AsyncCallStackTracker::willHandleV8AsyncTask(ExecutionContext* context, con st String& eventName, int id)
349 {
350 ASSERT(context);
351 ASSERT(isEnabled());
352 if (ExecutionContextData* data = m_executionContextDataMap.get(context))
353 setCurrentAsyncCallChain(context, data->m_v8AsyncTaskCallChains.take(mak eV8AsyncTaskUniqueId(eventName, id)));
354 else
355 setCurrentAsyncCallChain(context, nullptr);
356 }
357
329 void AsyncCallStackTracker::didFireAsyncCall() 358 void AsyncCallStackTracker::didFireAsyncCall()
330 { 359 {
331 clearCurrentAsyncCallChain(); 360 clearCurrentAsyncCallChain();
332 } 361 }
333 362
334 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA syncCallChain(const String& description, const ScriptValue& callFrames) 363 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA syncCallChain(const String& description, const ScriptValue& callFrames)
335 { 364 {
365 if (callFrames.isEmpty()) {
366 ASSERT(m_currentAsyncCallChain);
367 return m_currentAsyncCallChain; // Propogate async call stack chain.
368 }
336 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr acker::AsyncCallChain()); 369 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr acker::AsyncCallChain());
337 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); 370 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1);
338 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta ck(description, callFrames))); 371 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta ck(description, callFrames)));
339 return chain.release(); 372 return chain.release();
340 } 373 }
341 374
342 void AsyncCallStackTracker::setCurrentAsyncCallChain(ExecutionContext* context, PassRefPtr<AsyncCallChain> chain) 375 void AsyncCallStackTracker::setCurrentAsyncCallChain(ExecutionContext* context, PassRefPtr<AsyncCallChain> chain)
343 { 376 {
344 if (V8RecursionScope::recursionLevel(toIsolate(context))) { 377 if (V8RecursionScope::recursionLevel(toIsolate(context))) {
345 if (m_currentAsyncCallChain) 378 if (m_currentAsyncCallChain)
(...skipping 15 matching lines...) Expand all
361 } 394 }
362 395
363 void AsyncCallStackTracker::ensureMaxAsyncCallChainDepth(AsyncCallChain* chain, unsigned maxDepth) 396 void AsyncCallStackTracker::ensureMaxAsyncCallChainDepth(AsyncCallChain* chain, unsigned maxDepth)
364 { 397 {
365 while (chain->m_callStacks.size() > maxDepth) 398 while (chain->m_callStacks.size() > maxDepth)
366 chain->m_callStacks.removeLast(); 399 chain->m_callStacks.removeLast();
367 } 400 }
368 401
369 bool AsyncCallStackTracker::validateCallFrames(const ScriptValue& callFrames) 402 bool AsyncCallStackTracker::validateCallFrames(const ScriptValue& callFrames)
370 { 403 {
371 return !callFrames.isEmpty(); 404 return !callFrames.isEmpty() || m_currentAsyncCallChain;
372 } 405 }
373 406
374 AsyncCallStackTracker::ExecutionContextData* AsyncCallStackTracker::createContex tDataIfNeeded(ExecutionContext* context) 407 AsyncCallStackTracker::ExecutionContextData* AsyncCallStackTracker::createContex tDataIfNeeded(ExecutionContext* context)
375 { 408 {
376 ExecutionContextData* data = m_executionContextDataMap.get(context); 409 ExecutionContextData* data = m_executionContextDataMap.get(context);
377 if (!data) { 410 if (!data) {
378 data = new AsyncCallStackTracker::ExecutionContextData(this, context); 411 data = new AsyncCallStackTracker::ExecutionContextData(this, context);
379 m_executionContextDataMap.set(context, data); 412 m_executionContextDataMap.set(context, data);
380 } 413 }
381 return data; 414 return data;
382 } 415 }
383 416
384 void AsyncCallStackTracker::clear() 417 void AsyncCallStackTracker::clear()
385 { 418 {
386 m_currentAsyncCallChain.clear(); 419 m_currentAsyncCallChain.clear();
387 m_nestedAsyncCallCount = 0; 420 m_nestedAsyncCallCount = 0;
388 ExecutionContextDataMap copy; 421 ExecutionContextDataMap copy;
389 m_executionContextDataMap.swap(copy); 422 m_executionContextDataMap.swap(copy);
390 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e nd(); ++it) 423 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e nd(); ++it)
391 delete it->value; 424 delete it->value;
392 } 425 }
393 426
394 } // namespace WebCore 427 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/inspector/AsyncCallStackTracker.h ('k') | Source/core/inspector/InspectorDebuggerAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698