Chromium Code Reviews| Index: Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.h b/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| index c55f73917b5721c23169c5349ec8cef9a581c951..29947fc3a1f5c9ccfc0cd5f3a73a0d72c8457e8e 100644 |
| --- a/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| +++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| @@ -27,6 +27,10 @@ namespace WebCore { |
| // ExecutionContext state. When the ExecutionContext is suspended, |
| // resolve or reject will be delayed. When it is stopped, resolve or reject |
| // will be ignored. |
| +// |
| +// If you use ScriptPromiseResolverWithContext::resolve or reject from a |
|
adamk
2014/04/24 17:34:17
Is this comment now dead?
yhirano
2014/04/24 21:20:02
Yes, Thanks!
|
| +// non script execution environment, you should NOT enter a v8 context |
| +// at the call site. |
| class ScriptPromiseResolverWithContext FINAL : public ActiveDOMObject, public RefCounted<ScriptPromiseResolverWithContext> { |
| WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext); |
| @@ -42,26 +46,14 @@ public: |
| template <typename T> |
| void resolve(T value) |
| { |
| - if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
| - return; |
| - m_state = Resolving; |
| - NewScriptState::Scope scope(m_scriptState.get()); |
| - m_value.set(m_scriptState->isolate(), toV8Value(value)); |
| - if (!executionContext()->activeDOMObjectsAreSuspended()) |
| - resolveOrRejectImmediately(&m_timer); |
| + resolveOrReject(value, Resolving); |
| } |
| // Anything that can be passed to toV8Value can be passed to this function. |
| template <typename T> |
| void reject(T value) |
| { |
| - if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
| - return; |
| - m_state = Rejecting; |
| - NewScriptState::Scope scope(m_scriptState.get()); |
| - m_value.set(m_scriptState->isolate(), toV8Value(value)); |
| - if (!executionContext()->activeDOMObjectsAreSuspended()) |
| - resolveOrRejectImmediately(&m_timer); |
| + resolveOrReject(value, Rejecting); |
| } |
| NewScriptState* scriptState() { return m_scriptState.get(); } |
| @@ -102,7 +94,29 @@ private: |
| return ToV8Value<ScriptPromiseResolverWithContext, NewScriptState*>::toV8Value(value, m_scriptState.get(), m_scriptState->isolate()); |
| } |
| - void resolveOrRejectImmediately(Timer<ScriptPromiseResolverWithContext>*); |
| + template <typename T> |
| + void resolveOrReject(T value, ResolutionState newState) |
| + { |
| + if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
| + return; |
| + m_state = newState; |
| + // Retain this object until it is actually resolved or rejected. |
| + // |deref| will be called in |clear|. |
| + ref(); |
| + |
| + NewScriptState::Scope scope(m_scriptState.get()); |
| + m_value.set(m_scriptState->isolate(), toV8Value(value)); |
| + if (!executionContext()->activeDOMObjectsAreSuspended()) { |
| + resolveOrRejectImmediately(); |
| + // |this| can't be deleted here, so it is safe to call an instance |
| + // method. |
| + postRunMicrotasks(); |
| + } |
| + } |
| + |
| + void resolveOrRejectImmediately(); |
| + void postRunMicrotasks(); |
| + void onTimerFired(Timer<ScriptPromiseResolverWithContext>*); |
| void clear(); |
| ResolutionState m_state; |