| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ScriptPromise_h | |
| 6 #define ScriptPromise_h | |
| 7 | |
| 8 #include "bindings/common/AbstractScriptPromise.h" | |
| 9 #include "core/dom/DOMException.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 class ScriptPromise FINAL { | |
| 14 public: | |
| 15 explicit ScriptPromise(PassRefPtr<AbstractScriptPromise> impl) | |
| 16 : m_promise(impl) { } | |
| 17 | |
| 18 static ScriptPromise empty(ScriptState* state) | |
| 19 { | |
| 20 return ScriptPromise(state->createEmptyPromise()); | |
| 21 } | |
| 22 | |
| 23 static ScriptPromise rejectWithDOMException(ScriptState* state, PassRefPtrWi
llBeRawPtr<DOMException> exception) | |
| 24 { | |
| 25 return ScriptPromise(state->createRejectedPromise(exception)); | |
| 26 } | |
| 27 | |
| 28 static ScriptPromise rejectWithTypeError(ScriptState* state, const String& m
essage) | |
| 29 { | |
| 30 return ScriptPromise(state->createPromiseRejectedWithTypeError(message))
; | |
| 31 } | |
| 32 | |
| 33 ScriptPromise& operator=(PassRefPtr<AbstractScriptPromise> impl) | |
| 34 { | |
| 35 ASSERT(m_promise == nullptr); | |
| 36 m_promise = impl; | |
| 37 return *this; | |
| 38 } | |
| 39 | |
| 40 bool operator==(const ScriptPromise& other) const | |
| 41 { | |
| 42 return m_promise->equals(other.m_promise); | |
| 43 } | |
| 44 | |
| 45 bool operator!=(const ScriptPromise& other) const | |
| 46 { | |
| 47 return !operator==(other); | |
| 48 } | |
| 49 | |
| 50 ScriptPromise then(PassOwnPtr<ScriptFunction> onFulfilled, PassOwnPtr<Script
Function> onRejected = PassOwnPtr<ScriptFunction>()) { return ScriptPromise(m_pr
omise->then(onFulfilled, onRejected)); } | |
| 51 | |
| 52 bool isObject() const { return m_promise->isObject(); } | |
| 53 bool isNull() const { return m_promise->isNull(); } | |
| 54 bool isUndefinedOrNull() const { return m_promise->isUndefinedOrNull(); } | |
| 55 bool isEmpty() const { return m_promise->isEmpty(); } | |
| 56 void clear() { m_promise->clear(); } | |
| 57 | |
| 58 // FIXMEMULTIVM: Remove. | |
| 59 v8::Handle<v8::Value> v8Value() const { return m_promise->v8Value(); } | |
| 60 v8::Isolate* isolate() const { return m_promise->isolate(); } | |
| 61 | |
| 62 PassRefPtr<AbstractScriptPromise> scriptPromise() const { return m_promise;
} | |
| 63 | |
| 64 private: | |
| 65 RefPtr<AbstractScriptPromise> m_promise; | |
| 66 }; | |
| 67 | |
| 68 } // namespace blink | |
| 69 | |
| 70 #endif // ScriptPromise_h | |
| OLD | NEW |