Index: Source/bindings/core/v8/ScriptPromiseResolver.h |
diff --git a/Source/bindings/core/v8/ScriptPromiseResolver.h b/Source/bindings/core/v8/ScriptPromiseResolver.h |
index 62975ad0bc1763beb0fd12fff9eb1824089fb65a..fd42835125c88dad014ac84cb0e95b0000c84fc7 100644 |
--- a/Source/bindings/core/v8/ScriptPromiseResolver.h |
+++ b/Source/bindings/core/v8/ScriptPromiseResolver.h |
@@ -26,15 +26,15 @@ namespace blink { |
// ExecutionContext state. When the ExecutionContext is suspended, |
// resolve or reject will be delayed. When it is stopped, resolve or reject |
// will be ignored. |
-class CORE_EXPORT ScriptPromiseResolver : public RefCountedWillBeRefCountedGarbageCollected<ScriptPromiseResolver>, public ActiveDOMObject { |
+class CORE_EXPORT ScriptPromiseResolver : public GarbageCollectedFinalized<ScriptPromiseResolver>, public ActiveDOMObject { |
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ScriptPromiseResolver); |
WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver); |
public: |
- static PassRefPtrWillBeRawPtr<ScriptPromiseResolver> create(ScriptState* scriptState) |
+ static ScriptPromiseResolver* create(ScriptState* scriptState) |
{ |
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = adoptRefWillBeNoop(new ScriptPromiseResolver(scriptState)); |
+ ScriptPromiseResolver* resolver = new ScriptPromiseResolver(scriptState); |
resolver->suspendIfNeeded(); |
- return resolver.release(); |
+ return resolver; |
} |
#if ENABLE(ASSERT) |
@@ -107,10 +107,6 @@ private: |
Rejecting, |
ResolvedOrRejected, |
}; |
- enum LifetimeMode { |
- Default, |
- KeepAliveWhilePending, |
- }; |
template<typename T> |
void resolveOrReject(T value, ResolutionState newState) |
@@ -119,16 +115,18 @@ private: |
return; |
ASSERT(newState == Resolving || newState == Rejecting); |
m_state = newState; |
- // Retain this object until it is actually resolved or rejected. |
- // |deref| will be called in |clear|. |
- ref(); |
ScriptState::Scope scope(m_scriptState.get()); |
m_value.set( |
m_scriptState->isolate(), |
toV8(value, m_scriptState->context()->Global(), m_scriptState->isolate())); |
- if (!executionContext()->activeDOMObjectsAreSuspended()) |
- resolveOrRejectImmediately(); |
+ |
+ if (executionContext()->activeDOMObjectsAreSuspended()) { |
+ // Retain this object until it is actually resolved or rejected. |
+ keepAliveWhilePending(); |
+ return; |
+ } |
+ resolveOrRejectImmediately(); |
} |
void resolveOrRejectImmediately(); |
@@ -137,10 +135,14 @@ private: |
ResolutionState m_state; |
const RefPtr<ScriptState> m_scriptState; |
- LifetimeMode m_mode; |
Timer<ScriptPromiseResolver> m_timer; |
Resolver m_resolver; |
ScopedPersistent<v8::Value> m_value; |
+ |
+ // To support keepAliveWhilePending(), this object needs to keep itself |
+ // alive while in that state. |
+ SelfKeepAlive<ScriptPromiseResolver> m_keepAlive; |
+ |
#if ENABLE(ASSERT) |
// True if promise() is called. |
bool m_isPromiseCalled; |