| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 #include "wtf/text/AtomicStringHash.h" | 41 #include "wtf/text/AtomicStringHash.h" |
| 42 #include "wtf/text/StringBuilder.h" | 42 #include "wtf/text/StringBuilder.h" |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 static const char setTimeoutName[] = "setTimeout"; | 46 static const char setTimeoutName[] = "setTimeout"; |
| 47 static const char setIntervalName[] = "setInterval"; | 47 static const char setIntervalName[] = "setInterval"; |
| 48 static const char requestAnimationFrameName[] = "requestAnimationFrame"; | 48 static const char requestAnimationFrameName[] = "requestAnimationFrame"; |
| 49 static const char xhrSendName[] = "XMLHttpRequest.send"; | 49 static const char xhrSendName[] = "XMLHttpRequest.send"; |
| 50 static const char enqueueMutationRecordName[] = "Mutation"; | 50 static const char enqueueMutationRecordName[] = "Mutation"; |
| 51 static const char promiseResolved[] = "Promise.resolve"; | |
| 52 static const char promiseRejected[] = "Promise.reject"; | |
| 53 | 51 |
| 54 } | 52 } |
| 55 | 53 |
| 56 namespace WebCore { | 54 namespace WebCore { |
| 57 | 55 |
| 58 class AsyncCallStackTracker::ExecutionContextData FINAL : public ContextLifecycl
eObserver { | 56 class AsyncCallStackTracker::ExecutionContextData FINAL : public ContextLifecycl
eObserver { |
| 59 WTF_MAKE_FAST_ALLOCATED; | 57 WTF_MAKE_FAST_ALLOCATED; |
| 60 public: | 58 public: |
| 61 typedef std::pair<RegisteredEventListener, RefPtr<AsyncCallChain> > EventLis
tenerAsyncCallChain; | 59 typedef std::pair<RegisteredEventListener, RefPtr<AsyncCallChain> > EventLis
tenerAsyncCallChain; |
| 62 typedef Vector<EventListenerAsyncCallChain, 1> EventListenerAsyncCallChainVe
ctor; | 60 typedef Vector<EventListenerAsyncCallChain, 1> EventListenerAsyncCallChainVe
ctor; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 124 } |
| 127 | 125 |
| 128 public: | 126 public: |
| 129 AsyncCallStackTracker* m_tracker; | 127 AsyncCallStackTracker* m_tracker; |
| 130 HashSet<int> m_intervalTimerIds; | 128 HashSet<int> m_intervalTimerIds; |
| 131 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; | 129 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; |
| 132 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; | 130 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; |
| 133 HashMap<EventTarget*, EventListenerAsyncCallChainVectorHashMap> m_eventTarge
tCallChains; | 131 HashMap<EventTarget*, EventListenerAsyncCallChainVectorHashMap> m_eventTarge
tCallChains; |
| 134 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains; | 132 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains; |
| 135 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh
ains; | 133 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh
ains; |
| 136 HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_promiseTaskCallCha
ins; | |
| 137 }; | 134 }; |
| 138 | 135 |
| 139 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) | 136 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) |
| 140 { | 137 { |
| 141 const AtomicString& interfaceName = eventTarget->interfaceName(); | 138 const AtomicString& interfaceName = eventTarget->interfaceName(); |
| 142 if (interfaceName == EventTargetNames::XMLHttpRequest) | 139 if (interfaceName == EventTargetNames::XMLHttpRequest) |
| 143 return static_cast<XMLHttpRequest*>(eventTarget); | 140 return static_cast<XMLHttpRequest*>(eventTarget); |
| 144 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) | 141 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) |
| 145 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; | 142 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; |
| 146 return 0; | 143 return 0; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 void AsyncCallStackTracker::willDeliverMutationRecords(ExecutionContext* context
, MutationObserver* observer) | 359 void AsyncCallStackTracker::willDeliverMutationRecords(ExecutionContext* context
, MutationObserver* observer) |
| 363 { | 360 { |
| 364 ASSERT(context); | 361 ASSERT(context); |
| 365 ASSERT(isEnabled()); | 362 ASSERT(isEnabled()); |
| 366 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 363 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
| 367 setCurrentAsyncCallChain(data->m_mutationObserverCallChains.take(observe
r)); | 364 setCurrentAsyncCallChain(data->m_mutationObserverCallChains.take(observe
r)); |
| 368 else | 365 else |
| 369 setCurrentAsyncCallChain(nullptr); | 366 setCurrentAsyncCallChain(nullptr); |
| 370 } | 367 } |
| 371 | 368 |
| 372 void AsyncCallStackTracker::didPostPromiseTask(ExecutionContext* context, Execut
ionContextTask* task, bool isResolved, const ScriptValue& callFrames) | |
| 373 { | |
| 374 ASSERT(context); | |
| 375 ASSERT(isEnabled()); | |
| 376 if (validateCallFrames(callFrames)) { | |
| 377 ExecutionContextData* data = createContextDataIfNeeded(context); | |
| 378 data->m_promiseTaskCallChains.set(task, createAsyncCallChain(isResolved
? promiseResolved : promiseRejected, callFrames)); | |
| 379 } else if (m_currentAsyncCallChain) { | |
| 380 // Propagate async call stack to the re-posted task to update a derived
Promise. | |
| 381 ExecutionContextData* data = createContextDataIfNeeded(context); | |
| 382 data->m_promiseTaskCallChains.set(task, m_currentAsyncCallChain); | |
| 383 } | |
| 384 } | |
| 385 | |
| 386 void AsyncCallStackTracker::willPerformPromiseTask(ExecutionContext* context, Ex
ecutionContextTask* task) | |
| 387 { | |
| 388 ASSERT(context); | |
| 389 ASSERT(isEnabled()); | |
| 390 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | |
| 391 setCurrentAsyncCallChain(data->m_promiseTaskCallChains.take(task)); | |
| 392 else | |
| 393 setCurrentAsyncCallChain(nullptr); | |
| 394 } | |
| 395 | |
| 396 void AsyncCallStackTracker::didFireAsyncCall() | 369 void AsyncCallStackTracker::didFireAsyncCall() |
| 397 { | 370 { |
| 398 clearCurrentAsyncCallChain(); | 371 clearCurrentAsyncCallChain(); |
| 399 } | 372 } |
| 400 | 373 |
| 401 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA
syncCallChain(const String& description, const ScriptValue& callFrames) | 374 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA
syncCallChain(const String& description, const ScriptValue& callFrames) |
| 402 { | 375 { |
| 403 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC
allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr
acker::AsyncCallChain()); | 376 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC
allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr
acker::AsyncCallChain()); |
| 404 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); | 377 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); |
| 405 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta
ck(description, callFrames))); | 378 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta
ck(description, callFrames))); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 { | 425 { |
| 453 m_currentAsyncCallChain.clear(); | 426 m_currentAsyncCallChain.clear(); |
| 454 m_nestedAsyncCallCount = 0; | 427 m_nestedAsyncCallCount = 0; |
| 455 ExecutionContextDataMap copy; | 428 ExecutionContextDataMap copy; |
| 456 m_executionContextDataMap.swap(copy); | 429 m_executionContextDataMap.swap(copy); |
| 457 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e
nd(); ++it) | 430 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e
nd(); ++it) |
| 458 delete it->value; | 431 delete it->value; |
| 459 } | 432 } |
| 460 | 433 |
| 461 } // namespace WebCore | 434 } // namespace WebCore |
| OLD | NEW |