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"; |
51 | 53 |
52 } | 54 } |
53 | 55 |
54 namespace WebCore { | 56 namespace WebCore { |
55 | 57 |
56 class AsyncCallStackTracker::ExecutionContextData FINAL : public ContextLifecycl
eObserver { | 58 class AsyncCallStackTracker::ExecutionContextData FINAL : public ContextLifecycl
eObserver { |
57 WTF_MAKE_FAST_ALLOCATED; | 59 WTF_MAKE_FAST_ALLOCATED; |
58 public: | 60 public: |
59 typedef std::pair<RegisteredEventListener, RefPtr<AsyncCallChain> > EventLis
tenerAsyncCallChain; | 61 typedef std::pair<RegisteredEventListener, RefPtr<AsyncCallChain> > EventLis
tenerAsyncCallChain; |
60 typedef Vector<EventListenerAsyncCallChain, 1> EventListenerAsyncCallChainVe
ctor; | 62 typedef Vector<EventListenerAsyncCallChain, 1> EventListenerAsyncCallChainVe
ctor; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 122 } |
121 | 123 |
122 public: | 124 public: |
123 AsyncCallStackTracker* m_tracker; | 125 AsyncCallStackTracker* m_tracker; |
124 HashSet<int> m_intervalTimerIds; | 126 HashSet<int> m_intervalTimerIds; |
125 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; | 127 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; |
126 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; | 128 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; |
127 HashMap<EventTarget*, EventListenerAsyncCallChainVectorHashMap> m_eventTarge
tCallChains; | 129 HashMap<EventTarget*, EventListenerAsyncCallChainVectorHashMap> m_eventTarge
tCallChains; |
128 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains; | 130 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains; |
129 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh
ains; | 131 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh
ains; |
| 132 HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_promiseTaskCallCha
ins; |
130 }; | 133 }; |
131 | 134 |
132 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) | 135 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) |
133 { | 136 { |
134 const AtomicString& interfaceName = eventTarget->interfaceName(); | 137 const AtomicString& interfaceName = eventTarget->interfaceName(); |
135 if (interfaceName == EventTargetNames::XMLHttpRequest) | 138 if (interfaceName == EventTargetNames::XMLHttpRequest) |
136 return static_cast<XMLHttpRequest*>(eventTarget); | 139 return static_cast<XMLHttpRequest*>(eventTarget); |
137 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) | 140 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) |
138 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; | 141 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; |
139 return 0; | 142 return 0; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 void AsyncCallStackTracker::willDeliverMutationRecords(ExecutionContext* context
, MutationObserver* observer) | 358 void AsyncCallStackTracker::willDeliverMutationRecords(ExecutionContext* context
, MutationObserver* observer) |
356 { | 359 { |
357 ASSERT(context); | 360 ASSERT(context); |
358 ASSERT(isEnabled()); | 361 ASSERT(isEnabled()); |
359 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 362 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
360 setCurrentAsyncCallChain(data->m_mutationObserverCallChains.take(observe
r)); | 363 setCurrentAsyncCallChain(data->m_mutationObserverCallChains.take(observe
r)); |
361 else | 364 else |
362 setCurrentAsyncCallChain(0); | 365 setCurrentAsyncCallChain(0); |
363 } | 366 } |
364 | 367 |
| 368 void AsyncCallStackTracker::didPostPromiseTask(ExecutionContext* context, Execut
ionContextTask* task, bool isResolved, const ScriptValue& callFrames) |
| 369 { |
| 370 ASSERT(context); |
| 371 ASSERT(isEnabled()); |
| 372 if (validateCallFrames(callFrames)) { |
| 373 ExecutionContextData* data = createContextDataIfNeeded(context); |
| 374 data->m_promiseTaskCallChains.set(task, createAsyncCallChain(isResolved
? promiseResolved : promiseRejected, callFrames)); |
| 375 } else if (m_currentAsyncCallChain) { |
| 376 // Propagate async call stack to the re-posted task to update a derived
Promise. |
| 377 ExecutionContextData* data = createContextDataIfNeeded(context); |
| 378 data->m_promiseTaskCallChains.set(task, m_currentAsyncCallChain); |
| 379 } |
| 380 } |
| 381 |
| 382 void AsyncCallStackTracker::willPerformPromiseTask(ExecutionContext* context, Ex
ecutionContextTask* task) |
| 383 { |
| 384 ASSERT(context); |
| 385 ASSERT(isEnabled()); |
| 386 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
| 387 setCurrentAsyncCallChain(data->m_promiseTaskCallChains.take(task)); |
| 388 else |
| 389 setCurrentAsyncCallChain(0); |
| 390 } |
| 391 |
365 void AsyncCallStackTracker::didFireAsyncCall() | 392 void AsyncCallStackTracker::didFireAsyncCall() |
366 { | 393 { |
367 clearCurrentAsyncCallChain(); | 394 clearCurrentAsyncCallChain(); |
368 } | 395 } |
369 | 396 |
370 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA
syncCallChain(const String& description, const ScriptValue& callFrames) | 397 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA
syncCallChain(const String& description, const ScriptValue& callFrames) |
371 { | 398 { |
372 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC
allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr
acker::AsyncCallChain()); | 399 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC
allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr
acker::AsyncCallChain()); |
373 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); | 400 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); |
374 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta
ck(description, callFrames))); | 401 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta
ck(description, callFrames))); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 { | 448 { |
422 m_currentAsyncCallChain.clear(); | 449 m_currentAsyncCallChain.clear(); |
423 m_nestedAsyncCallCount = 0; | 450 m_nestedAsyncCallCount = 0; |
424 ExecutionContextDataMap copy; | 451 ExecutionContextDataMap copy; |
425 m_executionContextDataMap.swap(copy); | 452 m_executionContextDataMap.swap(copy); |
426 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e
nd(); ++it) | 453 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e
nd(); ++it) |
427 delete it->value; | 454 delete it->value; |
428 } | 455 } |
429 | 456 |
430 } // namespace WebCore | 457 } // namespace WebCore |
OLD | NEW |