• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef PromiseTracker_h
6 #define PromiseTracker_h
7 
8 #include "core/InspectorTypeBuilder.h"
9 #include "platform/heap/Handle.h"
10 #include "wtf/HashMap.h"
11 #include "wtf/Noncopyable.h"
12 #include "wtf/RefPtr.h"
13 #include "wtf/Vector.h"
14 #include <v8.h>
15 
16 namespace blink {
17 
18 class ScriptState;
19 class ScriptValue;
20 
21 class PromiseTracker FINAL : public NoBaseWillBeGarbageCollected<PromiseTracker> {
22     WTF_MAKE_NONCOPYABLE(PromiseTracker);
23     DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(PromiseTracker);
24 public:
create()25     static PassOwnPtrWillBeRawPtr<PromiseTracker> create()
26     {
27         return adoptPtrWillBeNoop(new PromiseTracker());
28     }
29 
isEnabled()30     bool isEnabled() const { return m_isEnabled; }
31     void setEnabled(bool);
32 
33     void clear();
34 
35     void didReceiveV8PromiseEvent(ScriptState*, v8::Handle<v8::Object> promise, v8::Handle<v8::Value> parentPromise, int status);
36 
37     PassRefPtr<TypeBuilder::Array<TypeBuilder::Debugger::PromiseDetails> > promises();
38     ScriptValue promiseById(int promiseId) const;
39 
40     class PromiseData;
41 
42     typedef WillBeHeapVector<RefPtrWillBeMember<PromiseData> > PromiseDataVector;
43     typedef WillBeHeapHashMap<int, PromiseDataVector> PromiseDataMap;
44 
45     void trace(Visitor*);
46 
promiseDataMap()47     PromiseDataMap& promiseDataMap() { return m_promiseDataMap; }
48 
49 private:
50     PromiseTracker();
51 
52     int circularSequentialId();
53     PassRefPtrWillBeRawPtr<PromiseData> createPromiseDataIfNeeded(ScriptState*, v8::Handle<v8::Object> promise);
54 
55     int m_circularSequentialId;
56     PromiseDataMap m_promiseDataMap;
57     bool m_isEnabled;
58 };
59 
60 } // namespace blink
61 
62 #endif // !defined(PromiseTracker_h)
63