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 #ifndef PromiseTracker_h | 5 #ifndef PromiseTracker_h |
6 #define PromiseTracker_h | 6 #define PromiseTracker_h |
7 | 7 |
8 #include "bindings/core/v8/V8GlobalValueMap.h" | 8 #include "bindings/core/v8/V8GlobalValueMap.h" |
9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
10 #include "core/InspectorFrontend.h" | 10 #include "core/InspectorFrontend.h" |
11 #include "core/InspectorTypeBuilder.h" | 11 #include "core/InspectorTypeBuilder.h" |
12 #include "platform/heap/Handle.h" | |
13 #include "wtf/HashMap.h" | 12 #include "wtf/HashMap.h" |
14 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
| 14 #include "wtf/PassOwnPtr.h" |
15 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
16 #include "wtf/Vector.h" | 16 #include "wtf/Vector.h" |
| 17 #include "wtf/WeakPtr.h" |
17 #include <v8.h> | 18 #include <v8.h> |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 class ScriptState; | 22 class ScriptState; |
22 class ScriptValue; | 23 class ScriptValue; |
23 | 24 |
24 class PromiseTracker final : public NoBaseWillBeGarbageCollectedFinalized<Promis
eTracker> { | 25 class PromiseTracker final { |
25 WTF_MAKE_NONCOPYABLE(PromiseTracker); | 26 WTF_MAKE_NONCOPYABLE(PromiseTracker); |
26 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(PromiseTracker); | 27 WTF_MAKE_FAST_ALLOCATED(PromiseTracker); |
27 public: | 28 public: |
28 class CORE_EXPORT Listener : public WillBeGarbageCollectedMixin { | 29 class CORE_EXPORT Listener { |
29 public: | 30 public: |
30 virtual ~Listener() { } | 31 virtual ~Listener() { } |
31 virtual void didUpdatePromise(InspectorFrontend::Debugger::EventType::En
um, PassRefPtr<TypeBuilder::Debugger::PromiseDetails>) = 0; | 32 virtual void didUpdatePromise(InspectorFrontend::Debugger::EventType::En
um, PassRefPtr<TypeBuilder::Debugger::PromiseDetails>) = 0; |
32 }; | 33 }; |
33 | 34 |
34 static PassOwnPtrWillBeRawPtr<PromiseTracker> create(Listener* listener, v8:
:Isolate* isolate) | 35 static PassOwnPtr<PromiseTracker> create(Listener* listener, v8::Isolate* is
olate) |
35 { | 36 { |
36 return adoptPtrWillBeNoop(new PromiseTracker(listener, isolate)); | 37 return adoptPtr(new PromiseTracker(listener, isolate)); |
37 } | 38 } |
38 | 39 |
39 ~PromiseTracker(); | 40 ~PromiseTracker(); |
40 | 41 |
41 bool isEnabled() const { return m_isEnabled; } | 42 bool isEnabled() const { return m_isEnabled; } |
42 void setEnabled(bool enabled, bool captureStacks); | 43 void setEnabled(bool enabled, bool captureStacks); |
43 void clear(); | 44 void clear(); |
44 void didReceiveV8PromiseEvent(ScriptState*, v8::Local<v8::Object> promise, v
8::Local<v8::Value> parentPromise, int status); | 45 void didReceiveV8PromiseEvent(ScriptState*, v8::Local<v8::Object> promise, v
8::Local<v8::Value> parentPromise, int status); |
45 ScriptValue promiseById(int promiseId); | 46 ScriptValue promiseById(int promiseId); |
46 | 47 |
47 DECLARE_TRACE(); | |
48 | |
49 private: | 48 private: |
50 PromiseTracker(Listener*, v8::Isolate*); | 49 PromiseTracker(Listener*, v8::Isolate*); |
51 | 50 |
52 int circularSequentialId(); | 51 int circularSequentialId(); |
53 int promiseId(v8::Local<v8::Object> promise, bool* isNewPromise); | 52 int promiseId(v8::Local<v8::Object> promise, bool* isNewPromise); |
54 | 53 |
55 int m_circularSequentialId; | 54 int m_circularSequentialId; |
56 bool m_isEnabled; | 55 bool m_isEnabled; |
57 bool m_captureStacks; | 56 bool m_captureStacks; |
58 RawPtrWillBeMember<Listener> m_listener; | 57 Listener* m_listener; |
59 | 58 |
60 v8::Isolate* m_isolate; | 59 v8::Isolate* m_isolate; |
61 v8::Persistent<v8::NativeWeakMap> m_promiseToId; | 60 v8::Persistent<v8::NativeWeakMap> m_promiseToId; |
62 | 61 |
63 #if !ENABLE(OILPAN) | |
64 WeakPtrFactory<PromiseTracker> m_weakPtrFactory; | 62 WeakPtrFactory<PromiseTracker> m_weakPtrFactory; |
65 #endif | |
66 | 63 |
67 class PromiseWeakCallbackData; | 64 class PromiseWeakCallbackData; |
68 class IdToPromiseMapTraits : public V8GlobalValueMapTraits<int, v8::Object,
v8::kWeakWithParameter> { | 65 class IdToPromiseMapTraits : public V8GlobalValueMapTraits<int, v8::Object,
v8::kWeakWithParameter> { |
69 public: | 66 public: |
70 // Weak traits: | 67 // Weak traits: |
71 typedef PromiseWeakCallbackData WeakCallbackDataType; | 68 typedef PromiseWeakCallbackData WeakCallbackDataType; |
72 typedef v8::GlobalValueMap<int, v8::Object, IdToPromiseMapTraits> MapTyp
e; | 69 typedef v8::GlobalValueMap<int, v8::Object, IdToPromiseMapTraits> MapTyp
e; |
73 | 70 |
74 static WeakCallbackDataType* WeakCallbackParameter(MapType*, int key, v8
::Local<v8::Object>& value); | 71 static WeakCallbackDataType* WeakCallbackParameter(MapType*, int key, v8
::Local<v8::Object>& value); |
75 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataTy
pe>&) { } | 72 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataTy
pe>&) { } |
76 // This method will be called if the value is removed from the map. | 73 // This method will be called if the value is removed from the map. |
77 static void DisposeCallbackData(WeakCallbackDataType*); | 74 static void DisposeCallbackData(WeakCallbackDataType*); |
78 // This method is called if weakly referenced value is collected. | 75 // This method is called if weakly referenced value is collected. |
79 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>
&); | 76 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>
&); |
80 | 77 |
81 static MapType* MapFromWeakCallbackInfo(const v8::WeakCallbackInfo<WeakC
allbackDataType>&); | 78 static MapType* MapFromWeakCallbackInfo(const v8::WeakCallbackInfo<WeakC
allbackDataType>&); |
82 static int KeyFromWeakCallbackInfo(const v8::WeakCallbackInfo<WeakCallba
ckDataType>&); | 79 static int KeyFromWeakCallbackInfo(const v8::WeakCallbackInfo<WeakCallba
ckDataType>&); |
83 }; | 80 }; |
84 | 81 |
85 IdToPromiseMapTraits::MapType m_idToPromise; | 82 IdToPromiseMapTraits::MapType m_idToPromise; |
86 }; | 83 }; |
87 | 84 |
88 } // namespace blink | 85 } // namespace blink |
89 | 86 |
90 #endif // !defined(PromiseTracker_h) | 87 #endif // !defined(PromiseTracker_h) |
OLD | NEW |