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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 class DOMException; | 45 class DOMException; |
46 | 46 |
47 // ScriptPromise is the class for representing Promise values in C++ world. | 47 // ScriptPromise is the class for representing Promise values in C++ world. |
48 // ScriptPromise holds a Promise. | 48 // ScriptPromise holds a Promise. |
49 // 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 |
50 // memory leaks since it has a reference from C++ to V8. | 50 // memory leaks since it has a reference from C++ to V8. |
51 // | 51 // |
52 class CORE_EXPORT ScriptPromise final { | 52 class CORE_EXPORT ScriptPromise final { |
53 ALLOW_ONLY_INLINE_ALLOCATION(); | 53 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
54 public: | 54 public: |
55 // Constructs an empty promise. | 55 // Constructs an empty promise. |
56 ScriptPromise(); | 56 ScriptPromise(); |
57 | 57 |
58 // Constructs a ScriptPromise from |promise|. | 58 // Constructs a ScriptPromise from |promise|. |
59 // If |promise| is not a Promise object, throws a v8 TypeError. | 59 // If |promise| is not a Promise object, throws a v8 TypeError. |
60 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); | 60 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); |
61 | 61 |
62 ScriptPromise(const ScriptPromise&); | 62 ScriptPromise(const ScriptPromise&); |
63 | 63 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); | 135 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); |
136 | 136 |
137 // Constructs and returns a ScriptPromise to be resolved when all |promises| | 137 // Constructs and returns a ScriptPromise to be resolved when all |promises| |
138 // are resolved. If one of |promises| is rejected, the returned | 138 // are resolved. If one of |promises| is rejected, the returned |
139 // ScriptPromise is rejected. | 139 // ScriptPromise is rejected. |
140 static ScriptPromise all(ScriptState*, const Vector<ScriptPromise>& promises
); | 140 static ScriptPromise all(ScriptState*, const Vector<ScriptPromise>& promises
); |
141 | 141 |
142 // This is a utility class intended to be used internally. | 142 // This is a utility class intended to be used internally. |
143 // ScriptPromiseResolver is for general purpose. | 143 // ScriptPromiseResolver is for general purpose. |
144 class CORE_EXPORT InternalResolver final { | 144 class CORE_EXPORT InternalResolver final { |
145 DISALLOW_ALLOCATION(); | 145 DISALLOW_NEW(); |
146 public: | 146 public: |
147 explicit InternalResolver(ScriptState*); | 147 explicit InternalResolver(ScriptState*); |
148 v8::Local<v8::Promise> v8Promise() const; | 148 v8::Local<v8::Promise> v8Promise() const; |
149 ScriptPromise promise() const; | 149 ScriptPromise promise() const; |
150 void resolve(v8::Local<v8::Value>); | 150 void resolve(v8::Local<v8::Value>); |
151 void reject(v8::Local<v8::Value>); | 151 void reject(v8::Local<v8::Value>); |
152 void clear() { m_resolver.clear(); } | 152 void clear() { m_resolver.clear(); } |
153 | 153 |
154 private: | 154 private: |
155 ScriptValue m_resolver; | 155 ScriptValue m_resolver; |
156 }; | 156 }; |
157 | 157 |
158 private: | 158 private: |
159 static void increaseInstanceCount(); | 159 static void increaseInstanceCount(); |
160 static void decreaseInstanceCount(); | 160 static void decreaseInstanceCount(); |
161 | 161 |
162 RefPtr<ScriptState> m_scriptState; | 162 RefPtr<ScriptState> m_scriptState; |
163 ScriptValue m_promise; | 163 ScriptValue m_promise; |
164 }; | 164 }; |
165 | 165 |
166 } // namespace blink | 166 } // namespace blink |
167 | 167 |
168 | 168 |
169 #endif // ScriptPromise_h | 169 #endif // ScriptPromise_h |
OLD | NEW |