OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef PromiseOfficer_h | |
32 #define PromiseOfficer_h | |
33 | |
34 #include "bindings/v8/custom/V8PromiseCustom.h" | |
35 #include "bindings/v8/ScriptObject.h" | |
36 #include "bindings/v8/ScriptState.h" | |
37 #include "core/inspector/ScriptCallStack.h" | |
38 #include "wtf/HashMap.h" | |
39 #include "wtf/Noncopyable.h" | |
40 #include "wtf/RefPtr.h" | |
41 | |
42 namespace WebCore { | |
43 | |
44 class ExecutionContext; | |
45 | |
46 class PromiseOfficer { | |
47 WTF_MAKE_NONCOPYABLE(PromiseOfficer); | |
48 public: | |
49 PromiseOfficer() : m_isEnabled(false) { } | |
50 | |
51 bool isEnabled() const { return m_isEnabled; } | |
52 void enable(); | |
53 void disable(); | |
54 | |
55 void clear(); | |
56 | |
57 void didCreatePromise(const ScriptObject& promise); | |
58 void didUpdatePromiseParent(const ScriptObject& promise, const ScriptObject& parentPromise); | |
59 void didUpdatePromiseState(const ScriptObject& promise, V8PromiseCustom::Pro miseState, const ScriptValue& result); | |
60 | |
61 private: | |
62 class PromiseData : public RefCounted<PromiseData> { | |
yurys
2014/03/12 10:56:53
Forward declaration of PromiseData should be enoug
aandrey
2014/03/12 11:23:14
I doubt.
| |
63 public: | |
64 PromiseData(const ScriptObject& promise, const ScriptObject& parentPromi se, const ScriptValue& result, V8PromiseCustom::PromiseState state, double times tamp); | |
65 | |
66 void didSettlePromise(double timestamp); | |
67 | |
68 ScriptObject m_promise; | |
69 ScriptObject m_parentPromise; | |
70 ScriptValue m_result; | |
71 V8PromiseCustom::PromiseState m_state; | |
72 | |
73 // Time in milliseconds. | |
74 double m_timeOnCreate; | |
75 double m_timeOnSettle; | |
76 | |
77 RefPtr<ScriptCallStack> m_callStackOnCreate; | |
78 RefPtr<ScriptCallStack> m_callStackOnSettle; | |
79 }; | |
80 | |
81 struct ScriptObjectHash { | |
aandrey
2014/03/11 10:43:38
plz move these to a separate file bindings/v8/Scri
Alexandra Mikhaylova
2014/03/12 12:11:51
Done.
| |
82 static unsigned hash(const ScriptObject& object) { return object.v8Objec t()->GetIdentityHash(); } | |
83 static bool equal(const ScriptObject& a, const ScriptObject& b) { return a == b; } | |
84 static const bool safeToCompareToEmptyOrDeleted = true; | |
85 }; | |
86 | |
87 struct ScriptObjectHashTraits : WTF::GenericHashTraits<ScriptObject> { | |
88 static const bool emptyValueIsZero = false; | |
89 static ScriptObject emptyValue() { return ScriptObject(ScriptState::curr ent(), ScriptValue::createNull()); } | |
90 static void constructDeletedValue(ScriptObject& slot) { slot = ScriptObj ect(); } | |
91 static bool isDeletedValue(ScriptObject value) { return value == ScriptO bject(); } | |
aandrey
2014/03/11 10:43:38
{ return value.hasNoValue(); }
Alexandra Mikhaylova
2014/03/12 12:11:51
Done.
| |
92 }; | |
93 | |
94 bool m_isEnabled; | |
95 typedef HashMap<ScriptObject, RefPtr<PromiseData>, ScriptObjectHash, ScriptO bjectHashTraits> PromiseDataMap; | |
96 PromiseDataMap m_promiseDataMap; | |
97 }; | |
98 | |
99 } // namespace WebCore | |
100 | |
101 #endif // !defined(PromiseOfficer_h) | |
OLD | NEW |