Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #ifndef AsyncCallStackTracker_h | |
| 32 #define AsyncCallStackTracker_h | |
| 33 | |
| 34 #include "bindings/core/v8/ScriptValue.h" | |
| 35 #include "core/dom/ContextLifecycleObserver.h" | |
| 36 #include "wtf/Deque.h" | |
| 37 #include "wtf/HashMap.h" | |
| 38 #include "wtf/HashSet.h" | |
| 39 #include "wtf/Noncopyable.h" | |
| 40 #include "wtf/PassRefPtr.h" | |
| 41 #include "wtf/RefPtr.h" | |
| 42 | |
| 43 namespace blink { | |
| 44 | |
| 45 class Event; | |
| 46 class EventListener; | |
| 47 class EventTarget; | |
| 48 class ExecutionContext; | |
| 49 class MutationObserver; | |
| 50 | |
| 51 class AsyncCallStackTracker FINAL { | |
|
yurys
2014/11/14 07:38:31
Given that you tend to write DOM in JS, Sky will l
abarth-chromium
2014/11/14 08:00:57
It depends what you mean by DOM. We're not planni
| |
| 52 WTF_MAKE_NONCOPYABLE(AsyncCallStackTracker); | |
| 53 public: | |
| 54 class AsyncCallStack FINAL : public RefCounted<AsyncCallStack> { | |
| 55 public: | |
| 56 AsyncCallStack(const String&, const ScriptValue&); | |
| 57 ~AsyncCallStack(); | |
| 58 String description() const { return m_description; } | |
| 59 ScriptValue callFrames() const { return m_callFrames; } | |
| 60 private: | |
| 61 String m_description; | |
| 62 ScriptValue m_callFrames; | |
| 63 }; | |
| 64 | |
| 65 typedef Deque<RefPtr<AsyncCallStack>, 4> AsyncCallStackVector; | |
| 66 | |
| 67 class AsyncCallChain FINAL : public RefCounted<AsyncCallChain> { | |
| 68 public: | |
| 69 AsyncCallChain() { } | |
| 70 AsyncCallChain(const AsyncCallChain& t) : m_callStacks(t.m_callStacks) { } | |
| 71 AsyncCallStackVector callStacks() const { return m_callStacks; } | |
| 72 private: | |
| 73 friend class AsyncCallStackTracker; | |
| 74 AsyncCallStackVector m_callStacks; | |
| 75 }; | |
| 76 | |
| 77 class ExecutionContextData FINAL : public ContextLifecycleObserver { | |
| 78 WTF_MAKE_FAST_ALLOCATED; | |
| 79 public: | |
| 80 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* e xecutionContext) | |
| 81 : ContextLifecycleObserver(executionContext) | |
| 82 , m_circularSequentialID(0) | |
| 83 , m_tracker(tracker) | |
| 84 { | |
| 85 } | |
| 86 | |
| 87 virtual void contextDestroyed() override; | |
| 88 | |
| 89 int circularSequentialID(); | |
| 90 | |
| 91 private: | |
| 92 int m_circularSequentialID; | |
| 93 | |
| 94 public: | |
| 95 RawPtr<AsyncCallStackTracker> m_tracker; | |
| 96 HashSet<int> m_intervalTimerIds; | |
| 97 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; | |
| 98 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; | |
| 99 HashMap<RawPtr<Event>, RefPtr<AsyncCallChain> > m_eventCallChains; | |
| 100 HashMap<RawPtr<MutationObserver>, RefPtr<AsyncCallChain> > m_mutationObs erverCallChains; | |
| 101 //HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_executionCon textTaskCallChains; | |
| 102 HashMap<String, RefPtr<AsyncCallChain> > m_v8AsyncTaskCallChains; | |
| 103 HashMap<int, RefPtr<AsyncCallChain> > m_asyncOperationCallChains; | |
| 104 }; | |
| 105 | |
| 106 AsyncCallStackTracker(); | |
| 107 | |
| 108 bool isEnabled() const { return m_maxAsyncCallStackDepth; } | |
| 109 void setAsyncCallStackDepth(int); | |
| 110 const AsyncCallChain* currentAsyncCallChain() const; | |
| 111 | |
| 112 void didInstallTimer(ExecutionContext*, int timerId, bool singleShot, const ScriptValue& callFrames); | |
| 113 void didRemoveTimer(ExecutionContext*, int timerId); | |
| 114 void willFireTimer(ExecutionContext*, int timerId); | |
| 115 | |
| 116 void didRequestAnimationFrame(ExecutionContext*, int callbackId, const Scrip tValue& callFrames); | |
| 117 void didCancelAnimationFrame(ExecutionContext*, int callbackId); | |
| 118 void willFireAnimationFrame(ExecutionContext*, int callbackId); | |
| 119 | |
| 120 void didEnqueueEvent(EventTarget*, Event*, const ScriptValue& callFrames); | |
| 121 void didRemoveEvent(EventTarget*, Event*); | |
| 122 void willHandleEvent(EventTarget*, Event*, EventListener*, bool useCapture); | |
| 123 | |
| 124 void didEnqueueMutationRecord(ExecutionContext*, MutationObserver*, const Sc riptValue& callFrames); | |
| 125 bool hasEnqueuedMutationRecord(ExecutionContext*, MutationObserver*); | |
| 126 void didClearAllMutationRecords(ExecutionContext*, MutationObserver*); | |
| 127 void willDeliverMutationRecords(ExecutionContext*, MutationObserver*); | |
| 128 | |
| 129 // void didPostExecutionContextTask(ExecutionContext*, ExecutionContextTask* , const ScriptValue& callFrames); | |
| 130 // void didKillAllExecutionContextTasks(ExecutionContext*); | |
| 131 // void willPerformExecutionContextTask(ExecutionContext*, ExecutionContextT ask*); | |
| 132 | |
| 133 void didEnqueueV8AsyncTask(ExecutionContext*, const String& eventName, int i d, const ScriptValue& callFrames); | |
| 134 void willHandleV8AsyncTask(ExecutionContext*, const String& eventName, int i d); | |
| 135 | |
| 136 int traceAsyncOperationStarting(ExecutionContext*, const String& operationNa me, const ScriptValue& callFrames); | |
| 137 void traceAsyncOperationCompleted(ExecutionContext*, int operationId); | |
| 138 void traceAsyncCallbackStarting(ExecutionContext*, int operationId); | |
| 139 | |
| 140 void didFireAsyncCall(); | |
| 141 void clear(); | |
| 142 | |
| 143 private: | |
| 144 PassRefPtr<AsyncCallChain> createAsyncCallChain(const String& description, c onst ScriptValue& callFrames); | |
| 145 void setCurrentAsyncCallChain(ExecutionContext*, PassRefPtr<AsyncCallChain>) ; | |
| 146 void clearCurrentAsyncCallChain(); | |
| 147 static void ensureMaxAsyncCallChainDepth(AsyncCallChain*, unsigned); | |
| 148 bool validateCallFrames(const ScriptValue& callFrames); | |
| 149 | |
| 150 ExecutionContextData* createContextDataIfNeeded(ExecutionContext*); | |
| 151 | |
| 152 unsigned m_maxAsyncCallStackDepth; | |
| 153 RefPtr<AsyncCallChain> m_currentAsyncCallChain; | |
| 154 unsigned m_nestedAsyncCallCount; | |
| 155 typedef HashMap<RawPtr<ExecutionContext>, OwnPtr<ExecutionContextData> > Exe cutionContextDataMap; | |
| 156 ExecutionContextDataMap m_executionContextDataMap; | |
| 157 }; | |
| 158 | |
| 159 } // namespace blink | |
| 160 | |
| 161 #endif // !defined(AsyncCallStackTracker_h) | |
| OLD | NEW |