| 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 class DOMException; | 43 class DOMException; |
| 44 | 44 |
| 45 // ScriptPromise is the class for representing Promise values in C++ world. | 45 // ScriptPromise is the class for representing Promise values in C++ world. |
| 46 // ScriptPromise holds a Promise. | 46 // ScriptPromise holds a Promise. |
| 47 // So holding a ScriptPromise as a member variable in DOM object causes | 47 // So holding a ScriptPromise as a member variable in DOM object causes |
| 48 // memory leaks since it has a reference from C++ to V8. | 48 // memory leaks since it has a reference from C++ to V8. |
| 49 // | 49 // |
| 50 class CORE_EXPORT ScriptPromise final { | 50 class CORE_EXPORT ScriptPromise final { |
| 51 public: | 51 public: |
| 52 // Constructs an empty promise. | 52 // Constructs an empty promise. |
| 53 ScriptPromise() { } | 53 ScriptPromise(); |
| 54 | 54 |
| 55 // Constructs a ScriptPromise from |promise|. | 55 // Constructs a ScriptPromise from |promise|. |
| 56 // If |promise| is not a Promise object, throws a v8 TypeError. | 56 // If |promise| is not a Promise object, throws a v8 TypeError. |
| 57 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); | 57 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); |
| 58 | 58 |
| 59 ScriptPromise(const ScriptPromise&); |
| 60 |
| 61 ~ScriptPromise(); |
| 62 |
| 59 ScriptPromise then(v8::Local<v8::Function> onFulfilled, v8::Local<v8::Functi
on> onRejected = v8::Local<v8::Function>()); | 63 ScriptPromise then(v8::Local<v8::Function> onFulfilled, v8::Local<v8::Functi
on> onRejected = v8::Local<v8::Function>()); |
| 60 | 64 |
| 61 bool isObject() const | 65 bool isObject() const |
| 62 { | 66 { |
| 63 return m_promise.isObject(); | 67 return m_promise.isObject(); |
| 64 } | 68 } |
| 65 | 69 |
| 66 bool isNull() const | 70 bool isNull() const |
| 67 { | 71 { |
| 68 return m_promise.isNull(); | 72 return m_promise.isNull(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/); | 124 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/); |
| 121 static ScriptPromise cast(ScriptState*, v8::Local<v8::Value> /*value*/); | 125 static ScriptPromise cast(ScriptState*, v8::Local<v8::Value> /*value*/); |
| 122 | 126 |
| 123 static ScriptPromise reject(ScriptState*, const ScriptValue&); | 127 static ScriptPromise reject(ScriptState*, const ScriptValue&); |
| 124 static ScriptPromise reject(ScriptState*, v8::Local<v8::Value>); | 128 static ScriptPromise reject(ScriptState*, v8::Local<v8::Value>); |
| 125 | 129 |
| 126 static ScriptPromise rejectWithDOMException(ScriptState*, DOMException*); | 130 static ScriptPromise rejectWithDOMException(ScriptState*, DOMException*); |
| 127 | 131 |
| 128 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); | 132 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); |
| 129 | 133 |
| 134 static unsigned instanceCount() { return s_instanceCount; } |
| 135 |
| 130 // This is a utility class intended to be used internally. | 136 // This is a utility class intended to be used internally. |
| 131 // ScriptPromiseResolver is for general purpose. | 137 // ScriptPromiseResolver is for general purpose. |
| 132 class CORE_EXPORT InternalResolver final { | 138 class CORE_EXPORT InternalResolver final { |
| 133 public: | 139 public: |
| 134 explicit InternalResolver(ScriptState*); | 140 explicit InternalResolver(ScriptState*); |
| 135 v8::Local<v8::Promise> v8Promise() const; | 141 v8::Local<v8::Promise> v8Promise() const; |
| 136 ScriptPromise promise() const; | 142 ScriptPromise promise() const; |
| 137 void resolve(v8::Local<v8::Value>); | 143 void resolve(v8::Local<v8::Value>); |
| 138 void reject(v8::Local<v8::Value>); | 144 void reject(v8::Local<v8::Value>); |
| 139 void clear() { m_resolver.clear(); } | 145 void clear() { m_resolver.clear(); } |
| 140 | 146 |
| 141 private: | 147 private: |
| 142 ScriptValue m_resolver; | 148 ScriptValue m_resolver; |
| 143 }; | 149 }; |
| 144 | 150 |
| 145 private: | 151 private: |
| 146 RefPtr<ScriptState> m_scriptState; | 152 RefPtr<ScriptState> m_scriptState; |
| 147 ScriptValue m_promise; | 153 ScriptValue m_promise; |
| 154 |
| 155 static unsigned s_instanceCount; |
| 148 }; | 156 }; |
| 149 | 157 |
| 150 } // namespace blink | 158 } // namespace blink |
| 151 | 159 |
| 152 | 160 |
| 153 #endif // ScriptPromise_h | 161 #endif // ScriptPromise_h |
| OLD | NEW |