Chromium Code Reviews| Index: Source/bindings/v8/ScriptPromiseResolverWithContext.cpp |
| diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp b/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp |
| index 1a39cac07223f4c777f9d4df80e891041609d0fa..d35f9516ebd48a3969d7d1e9606f377a42990c23 100644 |
| --- a/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp |
| +++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp |
| @@ -9,13 +9,28 @@ |
| namespace WebCore { |
| -ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState* scriptState) |
| +ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState* scriptState, Mode mode) |
| : ActiveDOMObject(scriptState->executionContext()) |
| , m_state(Pending) |
| , m_scriptState(scriptState) |
| + , m_mode(mode) |
| , m_timer(this, &ScriptPromiseResolverWithContext::onTimerFired) |
| , m_resolver(ScriptPromiseResolver::create(m_scriptState.get())) |
| { |
| + if (mode == KeepSelfWhilePending) { |
| + // Keep |this| while the promise is Pending. |
| + // deref() will be called in clear(). |
| + ref(); |
| + } |
| +} |
| + |
| +ScriptPromiseResolverWithContext::~ScriptPromiseResolverWithContext() |
| +{ |
| + if (m_state != ResolvedOrRejected) { |
| + ScriptState::Scope scope(m_scriptState.get()); |
| + reject(v8::Exception::Error(v8::String::NewFromUtf8(m_scriptState->isolate(), |
| + "ScriptPromiseResolverWithContext is destructed without resolve / reject"))); |
| + } |
| } |
| void ScriptPromiseResolverWithContext::suspend() |
| @@ -31,6 +46,7 @@ void ScriptPromiseResolverWithContext::resume() |
| void ScriptPromiseResolverWithContext::stop() |
| { |
| + ScriptState::Scope scope(m_scriptState.get()); |
| m_timer.stop(); |
| clear(); |
| } |
| @@ -63,6 +79,9 @@ void ScriptPromiseResolverWithContext::resolveOrRejectImmediately() |
| void ScriptPromiseResolverWithContext::clear() |
| { |
| + if (m_state == ResolvedOrRejected) |
| + return; |
| + RefPtr<ScriptPromiseResolverWithContext> protect(this); |
|
haraken
2014/06/16 10:54:04
Why is this protect needed?
yhirano
2014/06/16 11:47:51
It was needed because I checked m_mode after calli
|
| ResolutionState state = m_state; |
| m_state = ResolvedOrRejected; |
| m_resolver.clear(); |
| @@ -71,7 +90,10 @@ void ScriptPromiseResolverWithContext::clear() |
| // |ref| was called in |resolveOrReject|. |
| deref(); |
|
haraken
2014/06/16 10:54:04
Just help me understand: What's the relationship b
yhirano
2014/06/16 11:47:51
ref() in constructor is for keeping the resolver w
|
| } |
| - // |this| may be deleted here. |
| + if (m_mode == KeepSelfWhilePending) { |
| + // |ref| was called in the constructor. |
| + deref(); |
| + } |
| } |
| } // namespace WebCore |