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

Side by Side Diff: gin/function_template.h

Issue 105743007: Gin: Make it easier to implement Wrappable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup 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
« no previous file with comments | « no previous file | 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 // 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 14 matching lines...) Expand all
25 namespace gin { 25 namespace gin {
26 26
27 class PerIsolateData; 27 class PerIsolateData;
28 28
29 enum CreateFunctionTemplateFlags { 29 enum CreateFunctionTemplateFlags {
30 HolderIsFirstArgument = 1 << 0, 30 HolderIsFirstArgument = 1 << 0,
31 }; 31 };
32 32
33 namespace internal { 33 namespace internal {
34 34
35 // TODO(aa): Move this to base/template_util.h as remove_const.
36 template<typename T> 35 template<typename T>
37 struct CallbackParamTraits { 36 struct CallbackParamTraits {
38 typedef T LocalType; 37 typedef T LocalType;
39 }; 38 };
40 template<typename T> 39 template<typename T>
41 struct CallbackParamTraits<const T&> { 40 struct CallbackParamTraits<const T&> {
42 typedef T LocalType; 41 typedef T LocalType;
43 }; 42 };
44 template<typename T> 43 template<typename T>
45 struct CallbackParamTraits<const T*> { 44 struct CallbackParamTraits<const T*> {
46 typedef T* LocalType; 45 typedef T* LocalType;
47 }; 46 };
48 47
49 48
50 // CallbackHolder and CallbackHolderBase are used to pass a base::Callback from 49 // CallbackHolder and CallbackHolderBase are used to pass a base::Callback from
51 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to 50 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to
52 // DispatchToCallback, where it is invoked. 51 // DispatchToCallback, where it is invoked.
53 // 52 //
54 // v8::FunctionTemplate only supports passing void* as data so how do we know 53 // v8::FunctionTemplate only supports passing void* as data so how do we know
55 // when to delete the base::Callback? That's where CallbackHolderBase comes in. 54 // 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 55 // 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 56 // via base::RefCounted has dropped to zero, and (b) there are no more
58 // JavaScript references in V8. 57 // JavaScript references in V8.
59 class CallbackHolderBase : public Wrappable { 58
60 public: 59 // This simple base class is used so that we can share a single object template
61 virtual WrapperInfo* GetWrapperInfo() OVERRIDE; 60 // among every CallbackHolder instance.
62 static WrapperInfo kWrapperInfo; 61 class CallbackHolderBase : public Wrappable<CallbackHolderBase> {
63 protected: 62 protected:
64 virtual ~CallbackHolderBase() {} 63 ~CallbackHolderBase() {}
65 }; 64 };
66 65
67 template<typename Sig> 66 template<typename Sig>
68 class CallbackHolder : public CallbackHolderBase { 67 class CallbackHolder : public CallbackHolderBase {
69 public: 68 public:
70 CallbackHolder(const base::Callback<Sig>& callback, int flags) 69 CallbackHolder(const base::Callback<Sig>& callback, int flags)
71 : callback(callback), flags(flags) {} 70 : callback(callback), flags(flags) {}
72 base::Callback<Sig> callback; 71 base::Callback<Sig> callback;
73 int flags; 72 int flags;
74 private: 73 private:
75 virtual ~CallbackHolder() {} 74 ~CallbackHolder() {}
76 }; 75 };
77 76
78 77
79 // This set of templates invokes a base::Callback, converts the return type to a 78 // This set of templates invokes a base::Callback, converts the return type to a
80 // JavaScript value, and returns that value to script via the provided 79 // JavaScript value, and returns that value to script via the provided
81 // gin::Arguments object. 80 // gin::Arguments object.
82 // 81 //
83 // In C++, you can declare the function foo(void), but you can't pass a void 82 // In C++, you can declare the function foo(void), but you can't pass a void
84 // expression to foo. As a result, we must specialize the case of Callbacks that 83 // expression to foo. As a result, we must specialize the case of Callbacks that
85 // have the void return type. 84 // have the void return type.
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 gin::Handle<HolderT> holder = CreateHandle( 345 gin::Handle<HolderT> holder = CreateHandle(
347 isolate, new HolderT(callback, callback_flags)); 346 isolate, new HolderT(callback, callback_flags));
348 return v8::FunctionTemplate::New( 347 return v8::FunctionTemplate::New(
349 &internal::Dispatcher<Sig>::DispatchToCallback, 348 &internal::Dispatcher<Sig>::DispatchToCallback,
350 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); 349 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
351 } 350 }
352 351
353 } // namespace gin 352 } // namespace gin
354 353
355 #endif // GIN_FUNCTION_TEMPLATE_H_ 354 #endif // GIN_FUNCTION_TEMPLATE_H_
OLDNEW
« no previous file with comments | « no previous file | gin/function_template.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698