| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ScriptPromiseResolverWithContext_h | 5 #ifndef ScriptPromiseResolverWithContext_h |
| 6 #define ScriptPromiseResolverWithContext_h | 6 #define ScriptPromiseResolverWithContext_h |
| 7 | 7 |
| 8 #include "bindings/v8/ScopedPersistent.h" | 8 #include "bindings/v8/ScopedPersistent.h" |
| 9 #include "bindings/v8/ScriptPromise.h" | 9 #include "bindings/v8/ScriptPromise.h" |
| 10 #include "bindings/v8/ScriptPromiseResolver.h" | 10 #include "bindings/v8/ScriptPromiseResolver.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext); | 31 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext); |
| 32 | 32 |
| 33 public: | 33 public: |
| 34 static PassRefPtr<ScriptPromiseResolverWithContext> create(ScriptState* scri
ptState) | 34 static PassRefPtr<ScriptPromiseResolverWithContext> create(ScriptState* scri
ptState) |
| 35 { | 35 { |
| 36 RefPtr<ScriptPromiseResolverWithContext> resolver = adoptRef(new ScriptP
romiseResolverWithContext(scriptState)); | 36 RefPtr<ScriptPromiseResolverWithContext> resolver = adoptRef(new ScriptP
romiseResolverWithContext(scriptState)); |
| 37 resolver->suspendIfNeeded(); | 37 resolver->suspendIfNeeded(); |
| 38 return resolver.release(); | 38 return resolver.release(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual ~ScriptPromiseResolverWithContext(); | 41 virtual ~ScriptPromiseResolverWithContext() |
| 42 { |
| 43 // This assertion fails if: |
| 44 // - promise() is called at least once and |
| 45 // - this resolver is destructed before it is resolved, rejected or |
| 46 // the associated ExecutionContext is stopped. |
| 47 ASSERT(m_state == ResolvedOrRejected || !m_isPromiseCalled); |
| 48 } |
| 42 | 49 |
| 43 // Anything that can be passed to toV8Value can be passed to this function. | 50 // Anything that can be passed to toV8Value can be passed to this function. |
| 44 template <typename T> | 51 template <typename T> |
| 45 void resolve(T value) | 52 void resolve(T value) |
| 46 { | 53 { |
| 47 resolveOrReject(value, Resolving); | 54 resolveOrReject(value, Resolving); |
| 48 } | 55 } |
| 49 | 56 |
| 50 // Anything that can be passed to toV8Value can be passed to this function. | 57 // Anything that can be passed to toV8Value can be passed to this function. |
| 51 template <typename T> | 58 template <typename T> |
| 52 void reject(T value) | 59 void reject(T value) |
| 53 { | 60 { |
| 54 resolveOrReject(value, Rejecting); | 61 resolveOrReject(value, Rejecting); |
| 55 } | 62 } |
| 56 | 63 |
| 57 ScriptState* scriptState() { return m_scriptState.get(); } | 64 ScriptState* scriptState() { return m_scriptState.get(); } |
| 58 | 65 |
| 59 // Note that an empty ScriptPromise will be returned after resolve or | 66 // Note that an empty ScriptPromise will be returned after resolve or |
| 60 // reject is called. | 67 // reject is called. |
| 61 ScriptPromise promise() | 68 ScriptPromise promise() |
| 62 { | 69 { |
| 70 #if ASSERT_ENABLED |
| 71 m_isPromiseCalled = true; |
| 72 #endif |
| 63 return m_resolver ? m_resolver->promise() : ScriptPromise(); | 73 return m_resolver ? m_resolver->promise() : ScriptPromise(); |
| 64 } | 74 } |
| 65 | 75 |
| 66 ScriptState* scriptState() const { return m_scriptState.get(); } | 76 ScriptState* scriptState() const { return m_scriptState.get(); } |
| 67 | 77 |
| 68 // ActiveDOMObject implementation. | 78 // ActiveDOMObject implementation. |
| 69 virtual void suspend() OVERRIDE; | 79 virtual void suspend() OVERRIDE; |
| 70 virtual void resume() OVERRIDE; | 80 virtual void resume() OVERRIDE; |
| 71 virtual void stop() OVERRIDE; | 81 virtual void stop() OVERRIDE; |
| 72 | 82 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void resolveOrRejectImmediately(); | 127 void resolveOrRejectImmediately(); |
| 118 void onTimerFired(Timer<ScriptPromiseResolverWithContext>*); | 128 void onTimerFired(Timer<ScriptPromiseResolverWithContext>*); |
| 119 void clear(); | 129 void clear(); |
| 120 | 130 |
| 121 ResolutionState m_state; | 131 ResolutionState m_state; |
| 122 const RefPtr<ScriptState> m_scriptState; | 132 const RefPtr<ScriptState> m_scriptState; |
| 123 LifetimeMode m_mode; | 133 LifetimeMode m_mode; |
| 124 Timer<ScriptPromiseResolverWithContext> m_timer; | 134 Timer<ScriptPromiseResolverWithContext> m_timer; |
| 125 RefPtr<ScriptPromiseResolver> m_resolver; | 135 RefPtr<ScriptPromiseResolver> m_resolver; |
| 126 ScopedPersistent<v8::Value> m_value; | 136 ScopedPersistent<v8::Value> m_value; |
| 137 #if ASSERT_ENABLED |
| 138 // True if promise() is called. |
| 139 bool m_isPromiseCalled; |
| 140 #endif |
| 127 }; | 141 }; |
| 128 | 142 |
| 129 } // namespace WebCore | 143 } // namespace WebCore |
| 130 | 144 |
| 131 #endif // #ifndef ScriptPromiseResolverWithContext_h | 145 #endif // #ifndef ScriptPromiseResolverWithContext_h |
| OLD | NEW |