Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: Source/bindings/core/v8/CallbackPromiseAdapter.h

Issue 396963002: ServiceWorker: Bypass resolving a promise when ExecutionContext is gone (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // 53 //
54 // // Since promise resolving is done as an async task, it's not 54 // // Since promise resolving is done as an async task, it's not
55 // // guaranteed that the script context has seen the promise resolve 55 // // guaranteed that the script context has seen the promise resolve
56 // // immediately after calling onSuccess/onError. You can use the 56 // // immediately after calling onSuccess/onError. You can use the
57 // // ScriptPromise from the resolver to schedule a task that executes 57 // // ScriptPromise from the resolver to schedule a task that executes
58 // // after resolving: 58 // // after resolving:
59 // ScriptState::Scope scope(resolver->scriptState()); 59 // ScriptState::Scope scope(resolver->scriptState());
60 // resolver->promise().then(...); 60 // resolver->promise().then(...);
61 // } 61 // }
62 // 62 //
63 // // Called when aborting to resolve/reject a promise due to an empty
64 // // execution context.
65 // static void dispose(blink::WebMyClass* webInstance) {
66 // // delete as appropriate, but often it's just:
67 // delete webInstance;
68 // }
69 //
63 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC lass, blink::WebMyClass>*: 70 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC lass, blink::WebMyClass>*:
64 // 71 //
65 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s) 72 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s)
66 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext)); 73 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext));
67 // 74 //
68 // Note that this class does not manage its own lifetime. In this 75 // Note that this class does not manage its own lifetime. In this
69 // example that ownership of the WebCallbacks instance is being passed 76 // example that ownership of the WebCallbacks instance is being passed
70 // in and it is up to the callee to free the WebCallbacks instace. 77 // in and it is up to the callee to free the WebCallbacks instace.
71 template<typename S, typename T> 78 template<typename S, typename T>
72 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> { 79 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> {
73 public: 80 public:
74 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) 81 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver)
75 : m_resolver(resolver) 82 : m_resolver(resolver)
76 { 83 {
84 ASSERT(m_resolver);
77 } 85 }
78 virtual ~CallbackPromiseAdapter() { } 86 virtual ~CallbackPromiseAdapter() { }
79 87
80 virtual void onSuccess(typename S::WebType* result) OVERRIDE 88 virtual void onSuccess(typename S::WebType* result) OVERRIDE
81 { 89 {
90 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) {
91 S::dispose(result);
92 return;
93 }
82 m_resolver->resolve(S::from(m_resolver.get(), result)); 94 m_resolver->resolve(S::from(m_resolver.get(), result));
83 } 95 }
96
84 virtual void onError(typename T::WebType* error) OVERRIDE 97 virtual void onError(typename T::WebType* error) OVERRIDE
85 { 98 {
99 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) {
100 T::dispose(error);
101 return;
102 }
86 m_resolver->reject(T::from(m_resolver.get(), error)); 103 m_resolver->reject(T::from(m_resolver.get(), error));
87 } 104 }
105
88 private: 106 private:
89 RefPtr<ScriptPromiseResolver> m_resolver; 107 RefPtr<ScriptPromiseResolver> m_resolver;
90 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); 108 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter);
91 }; 109 };
92 110
93 } // namespace blink 111 } // namespace blink
94 112
95 #endif 113 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698