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) | 30 #if ENABLE(OILPAN) |
| 31 void dispose() |
| 32 { |
| 33 m_promise.clear(); |
| 34 m_parentPromise.clear(); |
| 35 } |
| 36 #else |
31 WeakPtr<PromiseData> createWeakPtr() | 37 WeakPtr<PromiseData> createWeakPtr() |
32 { | 38 { |
33 return m_weakPtrFactory.createWeakPtr(); | 39 return m_weakPtrFactory.createWeakPtr(); |
34 } | 40 } |
35 #endif | 41 #endif |
36 | 42 |
37 void trace(Visitor* visitor) | 43 void trace(Visitor* visitor) |
38 { | 44 { |
39 visitor->trace(m_callStack); | 45 visitor->trace(m_callStack); |
40 } | 46 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 { | 102 { |
97 #if ENABLE(OILPAN) | 103 #if ENABLE(OILPAN) |
98 OwnPtr<Persistent<PromiseDataWrapper> > persistentWrapper = adoptPtr(dat
a.GetParameter()); | 104 OwnPtr<Persistent<PromiseDataWrapper> > persistentWrapper = adoptPtr(dat
a.GetParameter()); |
99 RawPtr<PromiseDataWrapper> wrapper = *persistentWrapper; | 105 RawPtr<PromiseDataWrapper> wrapper = *persistentWrapper; |
100 #else | 106 #else |
101 OwnPtr<PromiseDataWrapper> wrapper = adoptPtr(data.GetParameter()); | 107 OwnPtr<PromiseDataWrapper> wrapper = adoptPtr(data.GetParameter()); |
102 #endif | 108 #endif |
103 WeakPtrWillBeRawPtr<PromiseTracker::PromiseData> promiseData = wrapper->
m_data; | 109 WeakPtrWillBeRawPtr<PromiseTracker::PromiseData> promiseData = wrapper->
m_data; |
104 if (!promiseData || !wrapper->m_tracker) | 110 if (!promiseData || !wrapper->m_tracker) |
105 return; | 111 return; |
| 112 |
| 113 #if ENABLE(OILPAN) |
| 114 // Oilpan: let go of ScopedPersistent<>s right here (and not wait until
the |
| 115 // PromiseDataWrapper is GCed later.) The v8 weak callback handling expe
cts |
| 116 // to see the callback data upon return. |
| 117 promiseData->dispose(); |
| 118 #endif |
106 PromiseTracker::PromiseDataMap& map = wrapper->m_tracker->promiseDataMap
(); | 119 PromiseTracker::PromiseDataMap& map = wrapper->m_tracker->promiseDataMap
(); |
107 int promiseHash = promiseData->promiseHash(); | 120 int promiseHash = promiseData->promiseHash(); |
108 PromiseTracker::PromiseDataVector* vector = &map.find(promiseHash)->valu
e; | 121 |
| 122 PromiseTracker::PromiseDataMap::iterator it = map.find(promiseHash); |
| 123 // The PromiseTracker may have been disabled (and, possibly, re-enabled
later), |
| 124 // leaving the promiseHash as unmapped. |
| 125 if (it == map.end()) |
| 126 return; |
| 127 |
| 128 PromiseTracker::PromiseDataVector* vector = &it->value; |
109 int index = indexOf(vector, promiseData->promise()); | 129 int index = indexOf(vector, promiseData->promise()); |
110 ASSERT(index >= 0); | 130 ASSERT(index >= 0); |
111 vector->remove(index); | 131 vector->remove(index); |
112 if (vector->isEmpty()) | 132 if (vector->isEmpty()) |
113 map.remove(promiseHash); | 133 map.remove(promiseHash); |
114 } | 134 } |
115 | 135 |
116 void trace(Visitor* visitor) | 136 void trace(Visitor* visitor) |
117 { | 137 { |
118 #if ENABLE(OILPAN) | 138 #if ENABLE(OILPAN) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 if (data->m_callStack) | 265 if (data->m_callStack) |
246 promiseDetails->setCallFrame(data->m_callStack->at(0).buildInspe
ctorObject()); | 266 promiseDetails->setCallFrame(data->m_callStack->at(0).buildInspe
ctorObject()); |
247 result->addItem(promiseDetails); | 267 result->addItem(promiseDetails); |
248 } | 268 } |
249 } | 269 } |
250 | 270 |
251 return result.release(); | 271 return result.release(); |
252 } | 272 } |
253 | 273 |
254 } // namespace blink | 274 } // namespace blink |
OLD | NEW |