| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class DOMException; | 42 class DOMException; |
| 43 | 43 |
| 44 // ScriptPromise is the class for representing Promise values in C++ world. | 44 // ScriptPromise is the class for representing Promise values in C++ world. |
| 45 // ScriptPromise holds a Promise. | 45 // ScriptPromise holds a Promise. |
| 46 // So holding a ScriptPromise as a member variable in DOM object causes | 46 // So holding a ScriptPromise as a member variable in DOM object causes |
| 47 // memory leaks since it has a reference from C++ to V8. | 47 // memory leaks since it has a reference from C++ to V8. |
| 48 // | 48 // |
| 49 class ScriptPromise FINAL { | 49 class ScriptPromise final { |
| 50 public: | 50 public: |
| 51 // Constructs an empty promise. | 51 // Constructs an empty promise. |
| 52 ScriptPromise() { } | 52 ScriptPromise() { } |
| 53 | 53 |
| 54 // Constructs a ScriptPromise from |promise|. | 54 // Constructs a ScriptPromise from |promise|. |
| 55 // If |promise| is not a Promise object, throws a v8 TypeError. | 55 // If |promise| is not a Promise object, throws a v8 TypeError. |
| 56 ScriptPromise(ScriptState*, v8::Handle<v8::Value> promise); | 56 ScriptPromise(ScriptState*, v8::Handle<v8::Value> promise); |
| 57 | 57 |
| 58 ScriptPromise then(v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Func
tion> onRejected = v8::Handle<v8::Function>()); | 58 ScriptPromise then(v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Func
tion> onRejected = v8::Handle<v8::Function>()); |
| 59 | 59 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 static ScriptPromise reject(ScriptState*, const ScriptValue&); | 112 static ScriptPromise reject(ScriptState*, const ScriptValue&); |
| 113 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>); | 113 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>); |
| 114 | 114 |
| 115 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtrWillBeRa
wPtr<DOMException>); | 115 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtrWillBeRa
wPtr<DOMException>); |
| 116 | 116 |
| 117 static v8::Local<v8::Promise> rejectRaw(v8::Isolate*, v8::Handle<v8::Value>)
; | 117 static v8::Local<v8::Promise> rejectRaw(v8::Isolate*, v8::Handle<v8::Value>)
; |
| 118 | 118 |
| 119 // This is a utility class intended to be used internally. | 119 // This is a utility class intended to be used internally. |
| 120 // ScriptPromiseResolver is for general purpose. | 120 // ScriptPromiseResolver is for general purpose. |
| 121 class InternalResolver FINAL { | 121 class InternalResolver final { |
| 122 public: | 122 public: |
| 123 explicit InternalResolver(ScriptState*); | 123 explicit InternalResolver(ScriptState*); |
| 124 v8::Local<v8::Promise> v8Promise() const; | 124 v8::Local<v8::Promise> v8Promise() const; |
| 125 ScriptPromise promise() const; | 125 ScriptPromise promise() const; |
| 126 void resolve(v8::Local<v8::Value>); | 126 void resolve(v8::Local<v8::Value>); |
| 127 void reject(v8::Local<v8::Value>); | 127 void reject(v8::Local<v8::Value>); |
| 128 void clear() { m_resolver.clear(); } | 128 void clear() { m_resolver.clear(); } |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 ScriptValue m_resolver; | 131 ScriptValue m_resolver; |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 RefPtr<ScriptState> m_scriptState; | 135 RefPtr<ScriptState> m_scriptState; |
| 136 ScriptValue m_promise; | 136 ScriptValue m_promise; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 } // namespace blink | 139 } // namespace blink |
| 140 | 140 |
| 141 | 141 |
| 142 #endif // ScriptPromise_h | 142 #endif // ScriptPromise_h |
| OLD | NEW |