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

Side by Side Diff: gin/function_template.h

Issue 1112923003: Replace Handle<> with Local in remaining gin/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « gin/dictionary.cc ('k') | gin/function_template.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GIN_FUNCTION_TEMPLATE_H_ 5 #ifndef GIN_FUNCTION_TEMPLATE_H_
6 #define GIN_FUNCTION_TEMPLATE_H_ 6 #define GIN_FUNCTION_TEMPLATE_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "gin/arguments.h" 10 #include "gin/arguments.h"
(...skipping 26 matching lines...) Expand all
37 37
38 38
39 // CallbackHolder and CallbackHolderBase are used to pass a base::Callback from 39 // CallbackHolder and CallbackHolderBase are used to pass a base::Callback from
40 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to 40 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to
41 // DispatchToCallback, where it is invoked. 41 // DispatchToCallback, where it is invoked.
42 42
43 // This simple base class is used so that we can share a single object template 43 // This simple base class is used so that we can share a single object template
44 // among every CallbackHolder instance. 44 // among every CallbackHolder instance.
45 class GIN_EXPORT CallbackHolderBase { 45 class GIN_EXPORT CallbackHolderBase {
46 public: 46 public:
47 v8::Handle<v8::External> GetHandle(v8::Isolate* isolate); 47 v8::Local<v8::External> GetHandle(v8::Isolate* isolate);
48 48
49 protected: 49 protected:
50 explicit CallbackHolderBase(v8::Isolate* isolate); 50 explicit CallbackHolderBase(v8::Isolate* isolate);
51 virtual ~CallbackHolderBase(); 51 virtual ~CallbackHolderBase();
52 52
53 private: 53 private:
54 static void FirstWeakCallback( 54 static void FirstWeakCallback(
55 const v8::WeakCallbackInfo<CallbackHolderBase>& data); 55 const v8::WeakCallbackInfo<CallbackHolderBase>& data);
56 static void SecondWeakCallback( 56 static void SecondWeakCallback(
57 const v8::WeakCallbackInfo<CallbackHolderBase>& data); 57 const v8::WeakCallbackInfo<CallbackHolderBase>& data);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // DispatchToCallback converts all the JavaScript arguments to C++ types and 193 // DispatchToCallback converts all the JavaScript arguments to C++ types and
194 // invokes the base::Callback. 194 // invokes the base::Callback.
195 template <typename Sig> 195 template <typename Sig>
196 struct Dispatcher {}; 196 struct Dispatcher {};
197 197
198 template <typename ReturnType, typename... ArgTypes> 198 template <typename ReturnType, typename... ArgTypes>
199 struct Dispatcher<ReturnType(ArgTypes...)> { 199 struct Dispatcher<ReturnType(ArgTypes...)> {
200 static void DispatchToCallback( 200 static void DispatchToCallback(
201 const v8::FunctionCallbackInfo<v8::Value>& info) { 201 const v8::FunctionCallbackInfo<v8::Value>& info) {
202 Arguments args(info); 202 Arguments args(info);
203 v8::Handle<v8::External> v8_holder; 203 v8::Local<v8::External> v8_holder;
204 CHECK(args.GetData(&v8_holder)); 204 CHECK(args.GetData(&v8_holder));
205 CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>( 205 CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
206 v8_holder->Value()); 206 v8_holder->Value());
207 207
208 typedef CallbackHolder<ReturnType(ArgTypes...)> HolderT; 208 typedef CallbackHolder<ReturnType(ArgTypes...)> HolderT;
209 HolderT* holder = static_cast<HolderT*>(holder_base); 209 HolderT* holder = static_cast<HolderT*>(holder_base);
210 210
211 using Indices = typename IndicesGenerator<sizeof...(ArgTypes)>::type; 211 using Indices = typename IndicesGenerator<sizeof...(ArgTypes)>::type;
212 Invoker<Indices, ArgTypes...> invoker(&args, holder->flags); 212 Invoker<Indices, ArgTypes...> invoker(&args, holder->flags);
213 if (invoker.IsOK()) 213 if (invoker.IsOK())
(...skipping 16 matching lines...) Expand all
230 template<typename Sig> 230 template<typename Sig>
231 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( 231 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
232 v8::Isolate* isolate, const base::Callback<Sig> callback, 232 v8::Isolate* isolate, const base::Callback<Sig> callback,
233 int callback_flags = 0) { 233 int callback_flags = 0) {
234 typedef internal::CallbackHolder<Sig> HolderT; 234 typedef internal::CallbackHolder<Sig> HolderT;
235 HolderT* holder = new HolderT(isolate, callback, callback_flags); 235 HolderT* holder = new HolderT(isolate, callback, callback_flags);
236 236
237 return v8::FunctionTemplate::New( 237 return v8::FunctionTemplate::New(
238 isolate, 238 isolate,
239 &internal::Dispatcher<Sig>::DispatchToCallback, 239 &internal::Dispatcher<Sig>::DispatchToCallback,
240 ConvertToV8<v8::Handle<v8::External> >(isolate, 240 ConvertToV8<v8::Local<v8::External> >(isolate,
241 holder->GetHandle(isolate))); 241 holder->GetHandle(isolate)));
242 } 242 }
243 243
244 // CreateFunctionHandler installs a CallAsFunction handler on the given 244 // CreateFunctionHandler installs a CallAsFunction handler on the given
245 // object template that forwards to a provided C++ function or base::Callback. 245 // object template that forwards to a provided C++ function or base::Callback.
246 template<typename Sig> 246 template<typename Sig>
247 void CreateFunctionHandler(v8::Isolate* isolate, 247 void CreateFunctionHandler(v8::Isolate* isolate,
248 v8::Local<v8::ObjectTemplate> tmpl, 248 v8::Local<v8::ObjectTemplate> tmpl,
249 const base::Callback<Sig> callback, 249 const base::Callback<Sig> callback,
250 int callback_flags = 0) { 250 int callback_flags = 0) {
251 typedef internal::CallbackHolder<Sig> HolderT; 251 typedef internal::CallbackHolder<Sig> HolderT;
252 HolderT* holder = new HolderT(isolate, callback, callback_flags); 252 HolderT* holder = new HolderT(isolate, callback, callback_flags);
253 tmpl->SetCallAsFunctionHandler(&internal::Dispatcher<Sig>::DispatchToCallback, 253 tmpl->SetCallAsFunctionHandler(&internal::Dispatcher<Sig>::DispatchToCallback,
254 ConvertToV8<v8::Handle<v8::External> >( 254 ConvertToV8<v8::Local<v8::External> >(
255 isolate, holder->GetHandle(isolate))); 255 isolate, holder->GetHandle(isolate)));
256 } 256 }
257 257
258 } // namespace gin 258 } // namespace gin
259 259
260 #endif // GIN_FUNCTION_TEMPLATE_H_ 260 #endif // GIN_FUNCTION_TEMPLATE_H_
OLDNEW
« no previous file with comments | « gin/dictionary.cc ('k') | gin/function_template.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698