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

Side by Side Diff: gin/function_template.h

Issue 113893005: [gin] Introduce Wrappable::GetObjectTemplate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // This file was GENERATED by command: 1 // This file was GENERATED by command:
2 // pump.py function_template.h.pump 2 // pump.py function_template.h.pump
3 // DO NOT EDIT BY HAND!!! 3 // DO NOT EDIT BY HAND!!!
4 4
5 5
6 6
7 #ifndef GIN_FUNCTION_TEMPLATE_H_ 7 #ifndef GIN_FUNCTION_TEMPLATE_H_
8 #define GIN_FUNCTION_TEMPLATE_H_ 8 #define GIN_FUNCTION_TEMPLATE_H_
9 9
10 // Copyright 2013 The Chromium Authors. All rights reserved. 10 // Copyright 2013 The Chromium Authors. All rights reserved.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // when to delete the base::Callback? That's where CallbackHolderBase comes in. 55 // when to delete the base::Callback? That's where CallbackHolderBase comes in.
56 // It inherits from Wrappable, which delete itself when both (a) the refcount 56 // It inherits from Wrappable, which delete itself when both (a) the refcount
57 // via base::RefCounted has dropped to zero, and (b) there are no more 57 // via base::RefCounted has dropped to zero, and (b) there are no more
58 // JavaScript references in V8. 58 // JavaScript references in V8.
59 59
60 // This simple base class is used so that we can share a single object template 60 // This simple base class is used so that we can share a single object template
61 // among every CallbackHolder instance. 61 // among every CallbackHolder instance.
62 class GIN_EXPORT CallbackHolderBase : public Wrappable<CallbackHolderBase> { 62 class GIN_EXPORT CallbackHolderBase : public Wrappable<CallbackHolderBase> {
63 public: 63 public:
64 static WrapperInfo kWrapperInfo; 64 static WrapperInfo kWrapperInfo;
65
65 protected: 66 protected:
66 virtual ~CallbackHolderBase() {} 67 virtual ~CallbackHolderBase() {}
68
69 private:
70 friend class Wrappable<CallbackHolderBase>;
71 static v8::Local<v8::ObjectTemplate> GetObjectTemplate(v8::Isolate* isolate);
67 }; 72 };
68 73
69 template<typename Sig> 74 template<typename Sig>
70 class CallbackHolder : public CallbackHolderBase { 75 class CallbackHolder : public CallbackHolderBase {
71 public: 76 public:
72 CallbackHolder(const base::Callback<Sig>& callback, int flags) 77 CallbackHolder(const base::Callback<Sig>& callback, int flags)
73 : callback(callback), flags(flags) {} 78 : callback(callback), flags(flags) {}
74 base::Callback<Sig> callback; 79 base::Callback<Sig> callback;
75 int flags; 80 int flags;
76 private: 81 private:
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 return; 329 return;
325 } 330 }
326 331
327 Invoker<R, P1, P2, P3, P4>::Go(&args, holder->callback, a1, a2, a3, a4); 332 Invoker<R, P1, P2, P3, P4>::Go(&args, holder->callback, a1, a2, a3, a4);
328 } 333 }
329 }; 334 };
330 335
331 } // namespace internal 336 } // namespace internal
332 337
333 338
334 // This should be called once per-isolate to initialize the function template
335 // system.
336 GIN_EXPORT void InitFunctionTemplates(PerIsolateData* isolate_data);
337
338
339 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create 339 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create
340 // JavaScript functions that execute a provided C++ function or base::Callback. 340 // JavaScript functions that execute a provided C++ function or base::Callback.
341 // JavaScript arguments are automatically converted via gin::Converter, as is 341 // JavaScript arguments are automatically converted via gin::Converter, as is
342 // the return value of the C++ function, if any. 342 // the return value of the C++ function, if any.
343 template<typename Sig> 343 template<typename Sig>
344 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( 344 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
345 v8::Isolate* isolate, const base::Callback<Sig> callback, 345 v8::Isolate* isolate, const base::Callback<Sig> callback,
346 int callback_flags = 0) { 346 int callback_flags = 0) {
347 typedef internal::CallbackHolder<Sig> HolderT; 347 typedef internal::CallbackHolder<Sig> HolderT;
348 gin::Handle<HolderT> holder = CreateHandle( 348 gin::Handle<HolderT> holder = CreateHandle(
349 isolate, new HolderT(callback, callback_flags)); 349 isolate, new HolderT(callback, callback_flags));
350 return v8::FunctionTemplate::New( 350 return v8::FunctionTemplate::New(
351 &internal::Dispatcher<Sig>::DispatchToCallback, 351 &internal::Dispatcher<Sig>::DispatchToCallback,
352 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); 352 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
353 } 353 }
354 354
355 } // namespace gin 355 } // namespace gin
356 356
357 #endif // GIN_FUNCTION_TEMPLATE_H_ 357 #endif // GIN_FUNCTION_TEMPLATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698