| 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 ScriptPromiseResolver_h |
| 6 #define ScriptPromiseResolver_h |
| 7 |
| 8 #include "bindings/common/AbstractScriptPromiseResolver.h" |
| 9 #include "bindings/common/ScriptPromise.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class ScriptPromiseResolver : public ActiveDOMObject, public RefCounted<ScriptPr
omiseResolver> { |
| 14 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver); |
| 15 public: |
| 16 static PassRefPtr<ScriptPromiseResolver> create(ScriptState* scriptState) |
| 17 { |
| 18 RefPtr<ScriptPromiseResolver> resolver = adoptRef(new ScriptPromiseResol
ver(scriptState)); |
| 19 resolver->suspendIfNeeded(); |
| 20 return resolver.release(); |
| 21 } |
| 22 |
| 23 virtual ~ScriptPromiseResolver() { } |
| 24 |
| 25 // Note that an empty ScriptPromise will be returned after resolve or |
| 26 // reject is called. |
| 27 ScriptPromise promise() { return ScriptPromise(m_impl->promise()); } |
| 28 |
| 29 void resolve() { return m_impl->resolve(); } |
| 30 void reject() { return m_impl->reject(); } |
| 31 |
| 32 template <typename T> |
| 33 void resolve(T value) { return m_impl->resolve(value); } |
| 34 template <typename T> |
| 35 void reject(T error) { return m_impl->reject(error); } |
| 36 |
| 37 // Once this function is called this resolver stays alive while the |
| 38 // promise is pending and the associated ExecutionContext isn't stopped. |
| 39 void keepAliveWhilePending() { return m_impl->keepAliveWhilePending(); } |
| 40 |
| 41 ScriptState* scriptState() { return m_impl->scriptState(); } |
| 42 ScriptState* scriptState() const { return m_impl->scriptState(); } |
| 43 |
| 44 // ActiveDOMObject implementation. |
| 45 void suspend() { return m_impl->suspend(); } |
| 46 void resume() { return m_impl->resume(); } |
| 47 void stop() { return m_impl->stop(); } |
| 48 |
| 49 protected: |
| 50 // You need to call suspendIfNeeded after the construction because |
| 51 // this is an ActiveDOMObject. |
| 52 ScriptPromiseResolver(ScriptState* scriptState) |
| 53 : ActiveDOMObject(scriptState->executionContext()) |
| 54 , m_impl(scriptState->createPromiseResolver(this)) { } |
| 55 |
| 56 OwnPtr<AbstractScriptPromiseResolver> m_impl; |
| 57 }; |
| 58 |
| 59 } // namespace blink |
| 60 |
| 61 #endif // #ifndef ScriptPromiseResolver_h |
| OLD | NEW |