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

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

Issue 236713003: [ServiceWorker, PushMessaging] Use ScriptPromiseResolverWithContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptPromiseResolverWithContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef CallbackPromiseAdapter_h 31 #ifndef CallbackPromiseAdapter_h
32 #define CallbackPromiseAdapter_h 32 #define CallbackPromiseAdapter_h
33 33
34 #include "bindings/v8/NewScriptState.h" 34 #include "bindings/v8/ScriptPromiseResolverWithContext.h"
35 #include "bindings/v8/ScriptPromiseResolver.h"
36 #include "public/platform/WebCallbacks.h" 35 #include "public/platform/WebCallbacks.h"
37 36
38 namespace WebCore { 37 namespace WebCore {
39 38
40 // This class provides an easy way to convert from a Script-exposed 39 // This class provides an easy way to convert from a Script-exposed
41 // class (i.e. a class that has a toV8() overload) that uses Promises 40 // class (i.e. a class that has a toV8() overload) that uses Promises
42 // to a WebKit API class that uses WebCallbacks. You can define 41 // to a WebKit API class that uses WebCallbacks. You can define
43 // seperate Success and Error classes, but this example just uses one 42 // seperate Success and Error classes, but this example just uses one
44 // object for both. 43 // object for both.
45 // 44 //
(...skipping 11 matching lines...) Expand all
57 // 56 //
58 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s) 57 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s)
59 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext)); 58 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext));
60 // 59 //
61 // Note that this class does not manage its own lifetime. In this 60 // Note that this class does not manage its own lifetime. In this
62 // example that ownership of the WebCallbacks instance is being passed 61 // example that ownership of the WebCallbacks instance is being passed
63 // in and it is up to the callee to free the WebCallbacks instace. 62 // in and it is up to the callee to free the WebCallbacks instace.
64 template<typename S, typename T> 63 template<typename S, typename T>
65 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> { 64 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> {
66 public: 65 public:
67 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver, Execution Context* context) 66 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolverWithContext> resolver )
68 : m_resolver(resolver) 67 : m_resolver(resolver)
69 , m_scriptState(NewScriptState::current(toIsolate(context)))
70 { 68 {
71 } 69 }
72 virtual ~CallbackPromiseAdapter() { } 70 virtual ~CallbackPromiseAdapter() { }
73 71
74 virtual void onSuccess(typename S::WebType* result) OVERRIDE 72 virtual void onSuccess(typename S::WebType* result) OVERRIDE
75 { 73 {
76 NewScriptState::Scope scope(m_scriptState.get()); 74 v8::HandleScope handleScope(m_resolver->scriptState()->isolate());
77 m_resolver->resolve(S::from(m_scriptState.get(), result)); 75 m_resolver->resolve(S::from(m_resolver->scriptState(), result));
78 } 76 }
79 virtual void onError(typename T::WebType* error) OVERRIDE 77 virtual void onError(typename T::WebType* error) OVERRIDE
80 { 78 {
81 NewScriptState::Scope scope(m_scriptState.get()); 79 v8::HandleScope handleScope(m_resolver->scriptState()->isolate());
82 m_resolver->reject(T::from(m_scriptState.get(), error)); 80 m_resolver->reject(T::from(m_resolver->scriptState(), error));
83 } 81 }
84 private: 82 private:
85 RefPtr<ScriptPromiseResolver> m_resolver; 83 RefPtr<ScriptPromiseResolverWithContext> m_resolver;
86 RefPtr<NewScriptState> m_scriptState;
87 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); 84 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter);
88 }; 85 };
89 86
90 } // namespace WebCore 87 } // namespace WebCore
91 88
92 #endif 89 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptPromiseResolverWithContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698