Chromium Code Reviews| 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 (); |
| 120 if (map.isEmpty()) | |
| 121 return; | |
|
aandrey
2014/09/15 12:38:44
let's bail out if (map.find() == map.end()) instea
sof
2014/09/15 12:40:30
That would mask a bug -- all promise hashes should
aandrey
2014/09/15 12:46:04
The PromiseTracker could be disabled and re-enable
| |
| 107 int promiseHash = promiseData->promiseHash(); | 122 int promiseHash = promiseData->promiseHash(); |
| 108 PromiseTracker::PromiseDataVector* vector = &map.find(promiseHash)->valu e; | 123 PromiseTracker::PromiseDataVector* vector = &map.find(promiseHash)->valu e; |
| 109 int index = indexOf(vector, promiseData->promise()); | 124 int index = indexOf(vector, promiseData->promise()); |
| 110 ASSERT(index >= 0); | 125 ASSERT(index >= 0); |
| 111 vector->remove(index); | 126 vector->remove(index); |
| 112 if (vector->isEmpty()) | 127 if (vector->isEmpty()) |
| 113 map.remove(promiseHash); | 128 map.remove(promiseHash); |
| 114 } | 129 } |
| 115 | 130 |
| 116 void trace(Visitor* visitor) | 131 void trace(Visitor* visitor) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 if (data->m_callStack) | 260 if (data->m_callStack) |
| 246 promiseDetails->setCallFrame(data->m_callStack->at(0).buildInspe ctorObject()); | 261 promiseDetails->setCallFrame(data->m_callStack->at(0).buildInspe ctorObject()); |
| 247 result->addItem(promiseDetails); | 262 result->addItem(promiseDetails); |
| 248 } | 263 } |
| 249 } | 264 } |
| 250 | 265 |
| 251 return result.release(); | 266 return result.release(); |
| 252 } | 267 } |
| 253 | 268 |
| 254 } // namespace blink | 269 } // namespace blink |
| OLD | NEW |