| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef AsyncCallStackTracker_h | 31 #ifndef AsyncCallStackTracker_h |
| 32 #define AsyncCallStackTracker_h | 32 #define AsyncCallStackTracker_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptValue.h" | 34 #include "bindings/core/v8/ScriptValue.h" |
| 35 #include "core/dom/ContextLifecycleObserver.h" | |
| 36 #include "wtf/Deque.h" | 35 #include "wtf/Deque.h" |
| 37 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
| 38 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
| 39 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
| 40 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 41 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 42 | 41 |
| 43 namespace blink { | 42 namespace blink { |
| 44 | 43 |
| 45 class Event; | 44 class Event; |
| 46 class EventListener; | 45 class EventListener; |
| 47 class EventTarget; | 46 class EventTarget; |
| 48 class ExecutionContext; | 47 class ExecutionContext; |
| 49 class ExecutionContextTask; | 48 class ExecutionContextTask; |
| 50 class MutationObserver; | 49 class MutationObserver; |
| 51 class XMLHttpRequest; | 50 class XMLHttpRequest; |
| 52 | 51 |
| 53 class AsyncCallStackTracker final : public NoBaseWillBeGarbageCollectedFinalized
<AsyncCallStackTracker> { | 52 class AsyncCallStackTracker final : public NoBaseWillBeGarbageCollected<AsyncCal
lStackTracker> { |
| 54 WTF_MAKE_NONCOPYABLE(AsyncCallStackTracker); | 53 WTF_MAKE_NONCOPYABLE(AsyncCallStackTracker); |
| 54 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(AsyncCallStackTracker); |
| 55 public: | 55 public: |
| 56 class AsyncCallStack final : public RefCountedWillBeGarbageCollectedFinalize
d<AsyncCallStack> { | 56 class AsyncCallStack final : public RefCountedWillBeGarbageCollectedFinalize
d<AsyncCallStack> { |
| 57 public: | 57 public: |
| 58 AsyncCallStack(const String&, const ScriptValue&); | 58 AsyncCallStack(const String&, const ScriptValue&); |
| 59 ~AsyncCallStack(); | 59 ~AsyncCallStack(); |
| 60 void trace(Visitor*) { } | 60 void trace(Visitor*) { } |
| 61 String description() const { return m_description; } | 61 String description() const { return m_description; } |
| 62 ScriptValue callFrames() const { return m_callFrames; } | 62 ScriptValue callFrames() const { return m_callFrames; } |
| 63 private: | 63 private: |
| 64 String m_description; | 64 String m_description; |
| 65 ScriptValue m_callFrames; | 65 ScriptValue m_callFrames; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 typedef WillBeHeapDeque<RefPtrWillBeMember<AsyncCallStack>, 4> AsyncCallStac
kVector; | 68 typedef WillBeHeapDeque<RefPtrWillBeMember<AsyncCallStack>, 4> AsyncCallStac
kVector; |
| 69 | 69 |
| 70 class AsyncCallChain final : public RefCountedWillBeGarbageCollected<AsyncCa
llChain> { | 70 class AsyncCallChain final : public RefCountedWillBeGarbageCollected<AsyncCa
llChain> { |
| 71 public: | 71 public: |
| 72 AsyncCallChain() { } | 72 AsyncCallChain() { } |
| 73 AsyncCallChain(const AsyncCallChain& t) : m_callStacks(t.m_callStacks) {
} | 73 AsyncCallChain(const AsyncCallChain& t) : m_callStacks(t.m_callStacks) {
} |
| 74 AsyncCallStackVector callStacks() const { return m_callStacks; } | 74 AsyncCallStackVector callStacks() const { return m_callStacks; } |
| 75 void trace(Visitor*); | 75 void trace(Visitor*); |
| 76 private: | 76 private: |
| 77 friend class AsyncCallStackTracker; | 77 friend class AsyncCallStackTracker; |
| 78 AsyncCallStackVector m_callStacks; | 78 AsyncCallStackVector m_callStacks; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 class ExecutionContextData final : public NoBaseWillBeGarbageCollectedFinali
zed<ExecutionContextData>, public ContextLifecycleObserver { | |
| 82 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; | |
| 83 public: | |
| 84 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* e
xecutionContext) | |
| 85 : ContextLifecycleObserver(executionContext) | |
| 86 , m_circularSequentialID(0) | |
| 87 , m_tracker(tracker) | |
| 88 { | |
| 89 } | |
| 90 | |
| 91 virtual void contextDestroyed() override; | |
| 92 | |
| 93 int circularSequentialID(); | |
| 94 | |
| 95 void trace(Visitor*); | |
| 96 | |
| 97 private: | |
| 98 int m_circularSequentialID; | |
| 99 | |
| 100 public: | |
| 101 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; | |
| 102 HashSet<int> m_intervalTimerIds; | |
| 103 WillBeHeapHashMap<int, RefPtrWillBeMember<AsyncCallChain> > m_timerCallC
hains; | |
| 104 WillBeHeapHashMap<int, RefPtrWillBeMember<AsyncCallChain> > m_animationF
rameCallChains; | |
| 105 WillBeHeapHashMap<RawPtrWillBeMember<Event>, RefPtrWillBeMember<AsyncCal
lChain> > m_eventCallChains; | |
| 106 WillBeHeapHashMap<RawPtrWillBeMember<EventTarget>, RefPtrWillBeMember<As
yncCallChain> > m_xhrCallChains; | |
| 107 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, RefPtrWillBeMemb
er<AsyncCallChain> > m_mutationObserverCallChains; | |
| 108 WillBeHeapHashMap<ExecutionContextTask*, RefPtrWillBeMember<AsyncCallCha
in> > m_executionContextTaskCallChains; | |
| 109 WillBeHeapHashMap<String, RefPtrWillBeMember<AsyncCallChain> > m_v8Async
TaskCallChains; | |
| 110 WillBeHeapHashMap<int, RefPtrWillBeMember<AsyncCallChain> > m_asyncOpera
tionCallChains; | |
| 111 }; | |
| 112 | |
| 113 AsyncCallStackTracker(); | 81 AsyncCallStackTracker(); |
| 114 | 82 |
| 115 bool isEnabled() const { return m_maxAsyncCallStackDepth; } | 83 bool isEnabled() const { return m_maxAsyncCallStackDepth; } |
| 116 void setAsyncCallStackDepth(int); | 84 void setAsyncCallStackDepth(int); |
| 117 const AsyncCallChain* currentAsyncCallChain() const; | 85 const AsyncCallChain* currentAsyncCallChain() const; |
| 118 | 86 |
| 119 void didInstallTimer(ExecutionContext*, int timerId, bool singleShot, const
ScriptValue& callFrames); | 87 void didInstallTimer(ExecutionContext*, int timerId, bool singleShot, const
ScriptValue& callFrames); |
| 120 void didRemoveTimer(ExecutionContext*, int timerId); | 88 void didRemoveTimer(ExecutionContext*, int timerId); |
| 121 void willFireTimer(ExecutionContext*, int timerId); | 89 void willFireTimer(ExecutionContext*, int timerId); |
| 122 | 90 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 145 | 113 |
| 146 int traceAsyncOperationStarting(ExecutionContext*, const String& operationNa
me, const ScriptValue& callFrames); | 114 int traceAsyncOperationStarting(ExecutionContext*, const String& operationNa
me, const ScriptValue& callFrames); |
| 147 void traceAsyncOperationCompleted(ExecutionContext*, int operationId); | 115 void traceAsyncOperationCompleted(ExecutionContext*, int operationId); |
| 148 void traceAsyncCallbackStarting(ExecutionContext*, int operationId); | 116 void traceAsyncCallbackStarting(ExecutionContext*, int operationId); |
| 149 | 117 |
| 150 void didFireAsyncCall(); | 118 void didFireAsyncCall(); |
| 151 void clear(); | 119 void clear(); |
| 152 | 120 |
| 153 void trace(Visitor*); | 121 void trace(Visitor*); |
| 154 | 122 |
| 123 class ExecutionContextData; |
| 124 |
| 155 private: | 125 private: |
| 156 void willHandleXHREvent(XMLHttpRequest*, Event*); | 126 void willHandleXHREvent(XMLHttpRequest*, Event*); |
| 157 | 127 |
| 158 PassRefPtrWillBeRawPtr<AsyncCallChain> createAsyncCallChain(const String& de
scription, const ScriptValue& callFrames); | 128 PassRefPtrWillBeRawPtr<AsyncCallChain> createAsyncCallChain(const String& de
scription, const ScriptValue& callFrames); |
| 159 void setCurrentAsyncCallChain(ExecutionContext*, PassRefPtrWillBeRawPtr<Asyn
cCallChain>); | 129 void setCurrentAsyncCallChain(ExecutionContext*, PassRefPtrWillBeRawPtr<Asyn
cCallChain>); |
| 160 void clearCurrentAsyncCallChain(); | 130 void clearCurrentAsyncCallChain(); |
| 161 static void ensureMaxAsyncCallChainDepth(AsyncCallChain*, unsigned); | 131 static void ensureMaxAsyncCallChainDepth(AsyncCallChain*, unsigned); |
| 162 bool validateCallFrames(const ScriptValue& callFrames); | 132 bool validateCallFrames(const ScriptValue& callFrames); |
| 163 | 133 |
| 164 ExecutionContextData* createContextDataIfNeeded(ExecutionContext*); | 134 ExecutionContextData* createContextDataIfNeeded(ExecutionContext*); |
| 165 | 135 |
| 166 unsigned m_maxAsyncCallStackDepth; | 136 unsigned m_maxAsyncCallStackDepth; |
| 167 RefPtrWillBeMember<AsyncCallChain> m_currentAsyncCallChain; | 137 RefPtrWillBeMember<AsyncCallChain> m_currentAsyncCallChain; |
| 168 unsigned m_nestedAsyncCallCount; | 138 unsigned m_nestedAsyncCallCount; |
| 169 typedef WillBeHeapHashMap<RawPtrWillBeMember<ExecutionContext>, OwnPtrWillBe
Member<ExecutionContextData> > ExecutionContextDataMap; | 139 typedef WillBeHeapHashMap<RawPtrWillBeMember<ExecutionContext>, OwnPtrWillBe
Member<ExecutionContextData> > ExecutionContextDataMap; |
| 170 ExecutionContextDataMap m_executionContextDataMap; | 140 ExecutionContextDataMap m_executionContextDataMap; |
| 171 }; | 141 }; |
| 172 | 142 |
| 173 } // namespace blink | 143 } // namespace blink |
| 174 | 144 |
| 175 #endif // !defined(AsyncCallStackTracker_h) | 145 #endif // !defined(AsyncCallStackTracker_h) |
| OLD | NEW |