Index: Source/modules/crypto/CryptoResultImpl.cpp |
diff --git a/Source/modules/crypto/CryptoResultImpl.cpp b/Source/modules/crypto/CryptoResultImpl.cpp |
index 13ba840dea5239b1379282550fc7492c5ce111ca..ef38706bf2199217048fb8c5f7092535c17e5ad0 100644 |
--- a/Source/modules/crypto/CryptoResultImpl.cpp |
+++ b/Source/modules/crypto/CryptoResultImpl.cpp |
@@ -88,10 +88,10 @@ ExceptionCode toExceptionCode(blink::WebCryptoErrorType errorType) |
// |
// This is achieved by making CryptoResultImpl hold a WeakPtr to the PromiseState. |
// The PromiseState deletes itself after being notified of completion. |
-// Additionally the PromiseState deletes itself when the ExecutionContext is |
+// Additionally the PromiseState is deleted when the ExecutionContext is |
// destroyed (necessary to avoid leaks when dealing with WebWorker threads, |
// which may die before the operation is completed). |
-class CryptoResultImpl::PromiseState FINAL : public ContextLifecycleObserver { |
+class CryptoResultImpl::PromiseState FINAL { |
public: |
static WeakPtr<PromiseState> create(ExecutionContext* context) |
{ |
@@ -99,10 +99,8 @@ public: |
return promiseState->m_weakFactory.createWeakPtr(); |
} |
- // Override from ContextLifecycleObserver |
- virtual void contextDestroyed() OVERRIDE |
+ void contextDestroyed() |
{ |
- ContextLifecycleObserver::contextDestroyed(); |
delete this; |
} |
@@ -142,15 +140,41 @@ public: |
} |
private: |
+ // This subclass of ScriptPromiseResolverWithContext is to be notified |
+ // when the context was destroyed. |
+ class PromiseResolver FINAL : public ScriptPromiseResolverWithContext { |
+ public: |
+ static PassRefPtr<PromiseResolver> create(ScriptState* scriptState, PromiseState* promiseState) |
+ { |
+ RefPtr<PromiseResolver> resolver = adoptRef(new PromiseResolver(scriptState, promiseState)); |
+ resolver->suspendIfNeeded(); |
+ return resolver.release(); |
+ } |
+ |
+ virtual void contextDestroyed() OVERRIDE |
+ { |
+ ScriptPromiseResolverWithContext::contextDestroyed(); |
+ m_promiseState->contextDestroyed(); |
+ } |
+ |
+ private: |
+ explicit PromiseResolver(ScriptState* scriptState, PromiseState* promiseState) |
+ : ScriptPromiseResolverWithContext(scriptState) |
+ , m_promiseState(promiseState) |
+ { |
+ } |
+ |
+ PromiseState* m_promiseState; |
+ }; |
+ |
explicit PromiseState(ExecutionContext* context) |
- : ContextLifecycleObserver(context) |
- , m_weakFactory(this) |
- , m_promiseResolver(ScriptPromiseResolverWithContext::create(ScriptState::current(toIsolate(context)))) |
+ : m_weakFactory(this) |
+ , m_promiseResolver(PromiseResolver::create(ScriptState::current(toIsolate(context)), this)) |
{ |
} |
WeakPtrFactory<PromiseState> m_weakFactory; |
- RefPtr<ScriptPromiseResolverWithContext> m_promiseResolver; |
+ RefPtr<PromiseResolver> m_promiseResolver; |
}; |
CryptoResultImpl::~CryptoResultImpl() |