OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef ScriptPromise_h | 31 #ifndef ScriptPromise_h |
32 #define ScriptPromise_h | 32 #define ScriptPromise_h |
33 | 33 |
34 #include "bindings/core/v8/ScriptFunction.h" | 34 #include "bindings/core/v8/ScriptFunction.h" |
35 #include "bindings/core/v8/ScriptValue.h" | 35 #include "bindings/core/v8/ScriptValue.h" |
36 #include "core/CoreExport.h" | 36 #include "core/CoreExport.h" |
37 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
| 38 #include "wtf/Allocator.h" |
38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
39 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
40 #include <v8.h> | 41 #include <v8.h> |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 class DOMException; | 45 class DOMException; |
45 | 46 |
46 // ScriptPromise is the class for representing Promise values in C++ world. | 47 // ScriptPromise is the class for representing Promise values in C++ world. |
47 // ScriptPromise holds a Promise. | 48 // ScriptPromise holds a Promise. |
48 // So holding a ScriptPromise as a member variable in DOM object causes | 49 // So holding a ScriptPromise as a member variable in DOM object causes |
49 // memory leaks since it has a reference from C++ to V8. | 50 // memory leaks since it has a reference from C++ to V8. |
50 // | 51 // |
51 class CORE_EXPORT ScriptPromise final { | 52 class CORE_EXPORT ScriptPromise final { |
| 53 ALLOW_ONLY_INLINE_ALLOCATION(); |
52 public: | 54 public: |
53 // Constructs an empty promise. | 55 // Constructs an empty promise. |
54 ScriptPromise(); | 56 ScriptPromise(); |
55 | 57 |
56 // Constructs a ScriptPromise from |promise|. | 58 // Constructs a ScriptPromise from |promise|. |
57 // If |promise| is not a Promise object, throws a v8 TypeError. | 59 // If |promise| is not a Promise object, throws a v8 TypeError. |
58 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); | 60 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); |
59 | 61 |
60 ScriptPromise(const ScriptPromise&); | 62 ScriptPromise(const ScriptPromise&); |
61 | 63 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); | 135 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); |
134 | 136 |
135 // Constructs and returns a ScriptPromise to be resolved when all |promises| | 137 // Constructs and returns a ScriptPromise to be resolved when all |promises| |
136 // are resolved. If one of |promises| is rejected, the returned | 138 // are resolved. If one of |promises| is rejected, the returned |
137 // ScriptPromise is rejected. | 139 // ScriptPromise is rejected. |
138 static ScriptPromise all(ScriptState*, const Vector<ScriptPromise>& promises
); | 140 static ScriptPromise all(ScriptState*, const Vector<ScriptPromise>& promises
); |
139 | 141 |
140 // This is a utility class intended to be used internally. | 142 // This is a utility class intended to be used internally. |
141 // ScriptPromiseResolver is for general purpose. | 143 // ScriptPromiseResolver is for general purpose. |
142 class CORE_EXPORT InternalResolver final { | 144 class CORE_EXPORT InternalResolver final { |
| 145 DISALLOW_ALLOCATION(); |
143 public: | 146 public: |
144 explicit InternalResolver(ScriptState*); | 147 explicit InternalResolver(ScriptState*); |
145 v8::Local<v8::Promise> v8Promise() const; | 148 v8::Local<v8::Promise> v8Promise() const; |
146 ScriptPromise promise() const; | 149 ScriptPromise promise() const; |
147 void resolve(v8::Local<v8::Value>); | 150 void resolve(v8::Local<v8::Value>); |
148 void reject(v8::Local<v8::Value>); | 151 void reject(v8::Local<v8::Value>); |
149 void clear() { m_resolver.clear(); } | 152 void clear() { m_resolver.clear(); } |
150 | 153 |
151 private: | 154 private: |
152 ScriptValue m_resolver; | 155 ScriptValue m_resolver; |
153 }; | 156 }; |
154 | 157 |
155 private: | 158 private: |
156 static void increaseInstanceCount(); | 159 static void increaseInstanceCount(); |
157 static void decreaseInstanceCount(); | 160 static void decreaseInstanceCount(); |
158 | 161 |
159 RefPtr<ScriptState> m_scriptState; | 162 RefPtr<ScriptState> m_scriptState; |
160 ScriptValue m_promise; | 163 ScriptValue m_promise; |
161 }; | 164 }; |
162 | 165 |
163 } // namespace blink | 166 } // namespace blink |
164 | 167 |
165 | 168 |
166 #endif // ScriptPromise_h | 169 #endif // ScriptPromise_h |
OLD | NEW |