OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/inspector/PromiseTracker.h" | 6 #include "core/inspector/PromiseTracker.h" |
7 | 7 |
8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
9 #include "bindings/core/v8/ScriptCallStackFactory.h" | 9 #include "bindings/core/v8/ScriptCallStackFactory.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
11 #include "wtf/PassOwnPtr.h" | 11 #include "wtf/PassOwnPtr.h" |
12 #include "wtf/WeakPtr.h" | 12 #include "wtf/WeakPtr.h" |
13 | 13 |
14 using blink::TypeBuilder::Array; | 14 using blink::TypeBuilder::Array; |
15 using blink::TypeBuilder::Console::CallFrame; | 15 using blink::TypeBuilder::Console::CallFrame; |
16 using blink::TypeBuilder::Debugger::PromiseDetails; | 16 using blink::TypeBuilder::Debugger::PromiseDetails; |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 class PromiseTracker::PromiseData FINAL : public RefCountedWillBeGarbageCollecte dFinalized<PromiseData> { | 20 class PromiseTracker::PromiseData FINAL : public RefCountedWillBeGarbageCollecte dFinalized<PromiseData> { |
21 public: | 21 public: |
22 static PassRefPtrWillBeRawPtr<PromiseData> create(v8::Isolate* isolate, int promiseHash, int promiseId, v8::Handle<v8::Object> promise) | 22 static PassRefPtrWillBeRawPtr<PromiseData> create(v8::Isolate* isolate, int promiseHash, int promiseId, v8::Handle<v8::Object> promise) |
23 { | 23 { |
24 return adoptRefWillBeNoop(new PromiseData(isolate, promiseHash, promiseI d, promise)); | 24 return adoptRefWillBeNoop(new PromiseData(isolate, promiseHash, promiseI d, promise)); |
25 } | 25 } |
26 | 26 |
27 int promiseHash() const { return m_promiseHash; } | 27 int promiseHash() const { return m_promiseHash; } |
28 ScopedPersistent<v8::Object>& promise() { return m_promise; } | 28 ScopedPersistent<v8::Object>& promise() { return m_promise; } |
29 | 29 |
30 #if !ENABLE(OILPAN) | |
31 WeakPtr<PromiseData> createWeakPtr() | |
32 { | |
33 return m_weakPtrFactory.createWeakPtr(); | |
34 } | |
35 #endif | |
36 | |
30 void trace(Visitor* visitor) | 37 void trace(Visitor* visitor) |
31 { | 38 { |
32 visitor->trace(m_callStack); | 39 visitor->trace(m_callStack); |
33 } | 40 } |
34 | 41 |
35 WeakPtrWillBeRawPtr<PromiseData> createWeakPtr() | |
36 { | |
37 #if ENABLE(OILPAN) | |
38 return this; | |
39 #else | |
40 return m_weakPtrFactory.createWeakPtr(); | |
41 #endif | |
42 } | |
43 | |
44 private: | 42 private: |
45 friend class PromiseTracker; | 43 friend class PromiseTracker; |
46 | 44 |
47 PromiseData(v8::Isolate* isolate, int promiseHash, int promiseId, v8::Handle <v8::Object> promise) | 45 PromiseData(v8::Isolate* isolate, int promiseHash, int promiseId, v8::Handle <v8::Object> promise) |
48 : m_promiseHash(promiseHash) | 46 : m_promiseHash(promiseHash) |
49 , m_promiseId(promiseId) | 47 , m_promiseId(promiseId) |
50 , m_promise(isolate, promise) | 48 , m_promise(isolate, promise) |
51 , m_parentPromiseId(0) | 49 , m_parentPromiseId(0) |
52 , m_status(0) | 50 , m_status(0) |
53 #if !ENABLE(OILPAN) | 51 #if !ENABLE(OILPAN) |
(...skipping 20 matching lines...) Loading... | |
74 if (vector->at(index)->promise() == promise) | 72 if (vector->at(index)->promise() == promise) |
75 return index; | 73 return index; |
76 } | 74 } |
77 return -1; | 75 return -1; |
78 } | 76 } |
79 | 77 |
80 namespace { | 78 namespace { |
81 | 79 |
82 class PromiseDataWrapper FINAL : public NoBaseWillBeGarbageCollected<PromiseData Wrapper> { | 80 class PromiseDataWrapper FINAL : public NoBaseWillBeGarbageCollected<PromiseData Wrapper> { |
83 public: | 81 public: |
84 static PassOwnPtrWillBeRawPtr<PromiseDataWrapper> create(PromiseTracker::Pro miseData* data, PromiseTracker::PromiseDataMap* map) | 82 static PassOwnPtrWillBeRawPtr<PromiseDataWrapper> create(PromiseTracker::Pro miseData* data, PromiseTracker* tracker) |
85 { | 83 { |
86 return adoptPtrWillBeNoop(new PromiseDataWrapper(data->createWeakPtr(), map)); | 84 #if ENABLE(OILPAN) |
85 return new PromiseDataWrapper(data, tracker); | |
86 #else | |
87 return adoptPtr(new PromiseDataWrapper(data->createWeakPtr(), tracker)); | |
88 #endif | |
87 } | 89 } |
88 | 90 |
91 #if ENABLE(OILPAN) | |
92 static void didRemovePromise(const v8::WeakCallbackData<v8::Object, Persiste nt<PromiseDataWrapper> >& data) | |
93 #else | |
89 static void didRemovePromise(const v8::WeakCallbackData<v8::Object, PromiseD ataWrapper>& data) | 94 static void didRemovePromise(const v8::WeakCallbackData<v8::Object, PromiseD ataWrapper>& data) |
95 #endif | |
90 { | 96 { |
91 OwnPtrWillBeRawPtr<PromiseDataWrapper> wrapper = adoptPtrWillBeNoop(data .GetParameter()); | 97 #if ENABLE(OILPAN) |
98 OwnPtr<Persistent<PromiseDataWrapper> > persistentWrapper = adoptPtr(dat a.GetParameter()); | |
99 RawPtr<PromiseDataWrapper> wrapper = *persistentWrapper; | |
100 #else | |
101 OwnPtr<PromiseDataWrapper> wrapper = adoptPtr(data.GetParameter()); | |
102 #endif | |
92 WeakPtrWillBeRawPtr<PromiseTracker::PromiseData> promiseData = wrapper-> m_data; | 103 WeakPtrWillBeRawPtr<PromiseTracker::PromiseData> promiseData = wrapper-> m_data; |
93 if (!promiseData) | 104 if (!promiseData || !wrapper->m_tracker) |
94 return; | 105 return; |
95 PromiseTracker::PromiseDataMap* map = wrapper->m_promiseDataMap; | 106 PromiseTracker::PromiseDataMap& map = wrapper->m_tracker->promiseDataMap (); |
96 int promiseHash = promiseData->promiseHash(); | 107 int promiseHash = promiseData->promiseHash(); |
97 PromiseTracker::PromiseDataVector* vector = &map->find(promiseHash)->val ue; | 108 PromiseTracker::PromiseDataVector* vector = &map.find(promiseHash)->valu e; |
98 int index = indexOf(vector, promiseData->promise()); | 109 int index = indexOf(vector, promiseData->promise()); |
99 ASSERT(index >= 0); | 110 ASSERT(index >= 0); |
100 vector->remove(index); | 111 vector->remove(index); |
101 if (vector->size() == 0) | 112 if (!vector->size()) |
aandrey
2014/09/10 14:42:18
if (vector->isEmpty())
sof
2014/09/11 05:20:53
Done.
| |
102 map->remove(promiseHash); | 113 map.remove(promiseHash); |
103 } | 114 } |
104 | 115 |
105 void trace(Visitor* visitor) | 116 void trace(Visitor* visitor) |
106 { | 117 { |
107 #if ENABLE(OILPAN) | 118 #if ENABLE(OILPAN) |
108 visitor->trace(m_data); | 119 visitor->trace(m_data); |
109 visitor->trace(m_promiseDataMap); | 120 visitor->trace(m_tracker); |
110 #endif | 121 #endif |
111 } | 122 } |
112 | 123 |
113 private: | 124 private: |
114 PromiseDataWrapper(WeakPtrWillBeRawPtr<PromiseTracker::PromiseData> data, Pr omiseTracker::PromiseDataMap* map) | 125 PromiseDataWrapper(WeakPtrWillBeRawPtr<PromiseTracker::PromiseData> data, P romiseTracker* tracker) |
aandrey
2014/09/10 14:42:18
nit: extra space before PromiseTracker*
sof
2014/09/11 05:20:53
Well spotted :)
| |
115 : m_data(data) | 126 : m_data(data) |
116 , m_promiseDataMap(map) | 127 , m_tracker(tracker) |
117 { | 128 { |
118 } | 129 } |
119 | 130 |
120 WeakPtrWillBeMember<PromiseTracker::PromiseData> m_data; | 131 WeakPtrWillBeWeakMember<PromiseTracker::PromiseData> m_data; |
121 RawPtrWillBeMember<PromiseTracker::PromiseDataMap> m_promiseDataMap; | 132 RawPtrWillBeWeakMember<PromiseTracker> m_tracker; |
122 }; | 133 }; |
123 | 134 |
124 } | 135 } |
125 | 136 |
126 PromiseTracker::PromiseTracker() | 137 PromiseTracker::PromiseTracker() |
127 : m_isEnabled(false) | 138 : m_circularSequentialId(0) |
128 , m_circularSequentialId(0) | 139 , m_isEnabled(false) |
129 { | 140 { |
130 } | 141 } |
131 | 142 |
132 PromiseTracker::~PromiseTracker() | 143 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(PromiseTracker); |
133 { | |
134 } | |
135 | 144 |
136 void PromiseTracker::trace(Visitor* visitor) | 145 void PromiseTracker::trace(Visitor* visitor) |
137 { | 146 { |
138 #if ENABLE(OILPAN) | 147 #if ENABLE(OILPAN) |
139 visitor->trace(m_promiseDataMap); | 148 visitor->trace(m_promiseDataMap); |
140 #endif | 149 #endif |
141 } | 150 } |
142 | 151 |
143 void PromiseTracker::setEnabled(bool enabled) | 152 void PromiseTracker::setEnabled(bool enabled) |
144 { | 153 { |
(...skipping 18 matching lines...) Loading... | |
163 PassRefPtrWillBeRawPtr<PromiseTracker::PromiseData> PromiseTracker::createPromis eDataIfNeeded(v8::Isolate* isolate, v8::Handle<v8::Object> promise) | 172 PassRefPtrWillBeRawPtr<PromiseTracker::PromiseData> PromiseTracker::createPromis eDataIfNeeded(v8::Isolate* isolate, v8::Handle<v8::Object> promise) |
164 { | 173 { |
165 int promiseHash = promise->GetIdentityHash(); | 174 int promiseHash = promise->GetIdentityHash(); |
166 RawPtr<PromiseDataVector> vector = nullptr; | 175 RawPtr<PromiseDataVector> vector = nullptr; |
167 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); | 176 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); |
168 if (it != m_promiseDataMap.end()) | 177 if (it != m_promiseDataMap.end()) |
169 vector = &it->value; | 178 vector = &it->value; |
170 else | 179 else |
171 vector = &m_promiseDataMap.add(promiseHash, PromiseDataVector()).storedV alue->value; | 180 vector = &m_promiseDataMap.add(promiseHash, PromiseDataVector()).storedV alue->value; |
172 | 181 |
173 RefPtrWillBeRawPtr<PromiseData> data = nullptr; | |
174 int index = indexOf(vector, ScopedPersistent<v8::Object>(isolate, promise)); | 182 int index = indexOf(vector, ScopedPersistent<v8::Object>(isolate, promise)); |
175 if (index == -1) { | 183 if (index != -1) |
176 data = PromiseData::create(isolate, promiseHash, circularSequentialId(), promise); | 184 return vector->at(index); |
177 OwnPtrWillBeRawPtr<PromiseDataWrapper> wrapper = PromiseDataWrapper::cre ate(data.get(), &m_promiseDataMap); | 185 |
178 data->m_promise.setWeak(wrapper.leakPtr(), &PromiseDataWrapper::didRemov ePromise); | 186 RefPtrWillBeRawPtr<PromiseData> data = PromiseData::create(isolate, promiseH ash, circularSequentialId(), promise); |
179 vector->append(data); | 187 OwnPtrWillBeRawPtr<PromiseDataWrapper> dataWrapper = PromiseDataWrapper::cre ate(data.get(), this); |
180 } else { | 188 #if ENABLE(OILPAN) |
181 data = vector->at(index); | 189 OwnPtr<Persistent<PromiseDataWrapper> > wrapper = adoptPtr(new Persistent<Pr omiseDataWrapper>(dataWrapper.leakPtr())); |
182 } | 190 #else |
191 OwnPtr<PromiseDataWrapper> wrapper = dataWrapper.release(); | |
192 #endif | |
193 data->m_promise.setWeak(wrapper.leakPtr(), &PromiseDataWrapper::didRemovePro mise); | |
194 vector->append(data); | |
183 | 195 |
184 return data.release(); | 196 return data.release(); |
185 } | 197 } |
186 | 198 |
187 void PromiseTracker::didReceiveV8PromiseEvent(ScriptState* scriptState, v8::Hand le<v8::Object> promise, v8::Handle<v8::Value> parentPromise, int status) | 199 void PromiseTracker::didReceiveV8PromiseEvent(ScriptState* scriptState, v8::Hand le<v8::Object> promise, v8::Handle<v8::Value> parentPromise, int status) |
188 { | 200 { |
189 ASSERT(isEnabled()); | 201 ASSERT(isEnabled()); |
190 | 202 |
191 v8::Isolate* isolate = scriptState->isolate(); | 203 v8::Isolate* isolate = scriptState->isolate(); |
192 RefPtrWillBeRawPtr<PromiseData> data = createPromiseDataIfNeeded(isolate, pr omise); | 204 RefPtrWillBeRawPtr<PromiseData> data = createPromiseDataIfNeeded(isolate, pr omise); |
(...skipping 37 matching lines...) Loading... | |
230 if (data->m_callStack) | 242 if (data->m_callStack) |
231 promiseDetails->setCallFrame(data->m_callStack->at(0).buildInspe ctorObject()); | 243 promiseDetails->setCallFrame(data->m_callStack->at(0).buildInspe ctorObject()); |
232 result->addItem(promiseDetails); | 244 result->addItem(promiseDetails); |
233 } | 245 } |
234 } | 246 } |
235 | 247 |
236 return result.release(); | 248 return result.release(); |
237 } | 249 } |
238 | 250 |
239 } // namespace blink | 251 } // namespace blink |
OLD | NEW |