| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::Handle<v8::Value> promise); | 57 ScriptPromise(ScriptState*, v8::Local<v8::Value> promise); |
| 58 | 58 |
| 59 ScriptPromise then(v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Func
tion> onRejected = v8::Handle<v8::Function>()); | 59 ScriptPromise then(v8::Local<v8::Function> onFulfilled, v8::Local<v8::Functi
on> onRejected = v8::Local<v8::Function>()); |
| 60 | 60 |
| 61 bool isObject() const | 61 bool isObject() const |
| 62 { | 62 { |
| 63 return m_promise.isObject(); | 63 return m_promise.isObject(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool isNull() const | 66 bool isNull() const |
| 67 { | 67 { |
| 68 return m_promise.isNull(); | 68 return m_promise.isNull(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool isUndefinedOrNull() const | 71 bool isUndefinedOrNull() const |
| 72 { | 72 { |
| 73 return m_promise.isUndefined() || m_promise.isNull(); | 73 return m_promise.isUndefined() || m_promise.isNull(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 ScriptValue scriptValue() const | 76 ScriptValue scriptValue() const |
| 77 { | 77 { |
| 78 return m_promise; | 78 return m_promise; |
| 79 } | 79 } |
| 80 | 80 |
| 81 v8::Handle<v8::Value> v8Value() const | 81 v8::Local<v8::Value> v8Value() const |
| 82 { | 82 { |
| 83 return m_promise.v8Value(); | 83 return m_promise.v8Value(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 v8::Isolate* isolate() const | 86 v8::Isolate* isolate() const |
| 87 { | 87 { |
| 88 return m_promise.isolate(); | 88 return m_promise.isolate(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool isEmpty() const | 91 bool isEmpty() const |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 bool operator!=(const ScriptPromise& value) const | 106 bool operator!=(const ScriptPromise& value) const |
| 107 { | 107 { |
| 108 return !operator==(value); | 108 return !operator==(value); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Constructs and returns a ScriptPromise from |value|. | 111 // Constructs and returns a ScriptPromise from |value|. |
| 112 // if |value| is not a Promise object, returns a Promise object | 112 // if |value| is not a Promise object, returns a Promise object |
| 113 // resolved with |value|. | 113 // resolved with |value|. |
| 114 // Returns |value| itself if it is a Promise. | 114 // Returns |value| itself if it is a Promise. |
| 115 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/); | 115 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/); |
| 116 static ScriptPromise cast(ScriptState*, v8::Handle<v8::Value> /*value*/); | 116 static ScriptPromise cast(ScriptState*, v8::Local<v8::Value> /*value*/); |
| 117 | 117 |
| 118 static ScriptPromise reject(ScriptState*, const ScriptValue&); | 118 static ScriptPromise reject(ScriptState*, const ScriptValue&); |
| 119 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>); | 119 static ScriptPromise reject(ScriptState*, v8::Local<v8::Value>); |
| 120 | 120 |
| 121 static ScriptPromise rejectWithDOMException(ScriptState*, DOMException*); | 121 static ScriptPromise rejectWithDOMException(ScriptState*, DOMException*); |
| 122 | 122 |
| 123 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Handle<v8::Value>)
; | 123 static v8::Local<v8::Promise> rejectRaw(ScriptState*, v8::Local<v8::Value>); |
| 124 | 124 |
| 125 // This is a utility class intended to be used internally. | 125 // This is a utility class intended to be used internally. |
| 126 // ScriptPromiseResolver is for general purpose. | 126 // ScriptPromiseResolver is for general purpose. |
| 127 class InternalResolver final { | 127 class InternalResolver final { |
| 128 public: | 128 public: |
| 129 explicit InternalResolver(ScriptState*); | 129 explicit InternalResolver(ScriptState*); |
| 130 v8::Local<v8::Promise> v8Promise() const; | 130 v8::Local<v8::Promise> v8Promise() const; |
| 131 ScriptPromise promise() const; | 131 ScriptPromise promise() const; |
| 132 void resolve(v8::Local<v8::Value>); | 132 void resolve(v8::Local<v8::Value>); |
| 133 void reject(v8::Local<v8::Value>); | 133 void reject(v8::Local<v8::Value>); |
| 134 void clear() { m_resolver.clear(); } | 134 void clear() { m_resolver.clear(); } |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 ScriptValue m_resolver; | 137 ScriptValue m_resolver; |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 RefPtr<ScriptState> m_scriptState; | 141 RefPtr<ScriptState> m_scriptState; |
| 142 ScriptValue m_promise; | 142 ScriptValue m_promise; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 } // namespace blink | 145 } // namespace blink |
| 146 | 146 |
| 147 | 147 |
| 148 #endif // ScriptPromise_h | 148 #endif // ScriptPromise_h |
| OLD | NEW |