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

Side by Side Diff: gin/function_template.h.pump

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 | « gin/function_template.cc ('k') | gin/object_template_builder.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 $$ This is a pump file for generating file templates. Pump is a python 1 $$ This is a pump file for generating file templates. Pump is a python
2 $$ script that is part of the Google Test suite of utilities. Description 2 $$ script that is part of the Google Test suite of utilities. Description
3 $$ can be found here: 3 $$ can be found here:
4 $$ 4 $$
5 $$ http://code.google.com/p/googletest/wiki/PumpManual 5 $$ http://code.google.com/p/googletest/wiki/PumpManual
6 $$ 6 $$
7 7
8 #ifndef GIN_FUNCTION_TEMPLATE_H_ 8 #ifndef GIN_FUNCTION_TEMPLATE_H_
9 #define GIN_FUNCTION_TEMPLATE_H_ 9 #define GIN_FUNCTION_TEMPLATE_H_
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // CallbackHolder and CallbackHolderBase are used to pass a base::Callback from 52 // CallbackHolder and CallbackHolderBase are used to pass a base::Callback from
53 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to 53 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to
54 // DispatchToCallback, where it is invoked. 54 // DispatchToCallback, where it is invoked.
55 // 55 //
56 // v8::FunctionTemplate only supports passing void* as data so how do we know 56 // v8::FunctionTemplate only supports passing void* as data so how do we know
57 // when to delete the base::Callback? That's where CallbackHolderBase comes in. 57 // when to delete the base::Callback? That's where CallbackHolderBase comes in.
58 // It inherits from Wrappable, which delete itself when both (a) the refcount 58 // It inherits from Wrappable, which delete itself when both (a) the refcount
59 // via base::RefCounted has dropped to zero, and (b) there are no more 59 // via base::RefCounted has dropped to zero, and (b) there are no more
60 // JavaScript references in V8. 60 // JavaScript references in V8.
61 class CallbackHolderBase : public Wrappable { 61
62 public: 62 // This simple base class is used so that we can share a single object template
63 virtual WrapperInfo* GetWrapperInfo() OVERRIDE; 63 // among every CallbackHolder instance.
64 static WrapperInfo kWrapperInfo; 64 class CallbackHolderBase : public Wrappable<CallbackHolderBase> {
65 protected: 65 protected:
66 virtual ~CallbackHolderBase() {} 66 ~CallbackHolderBase() {}
67 }; 67 };
68 68
69 template<typename Sig> 69 template<typename Sig>
70 class CallbackHolder : public CallbackHolderBase { 70 class CallbackHolder : public CallbackHolderBase {
71 public: 71 public:
72 CallbackHolder(const base::Callback<Sig>& callback, int flags) 72 CallbackHolder(const base::Callback<Sig>& callback, int flags)
73 : callback(callback), flags(flags) {} 73 : callback(callback), flags(flags) {}
74 base::Callback<Sig> callback; 74 base::Callback<Sig> callback;
75 int flags; 75 int flags;
76 private: 76 private:
77 virtual ~CallbackHolder() {} 77 ~CallbackHolder() {}
78 }; 78 };
79 79
80 80
81 // This set of templates invokes a base::Callback, converts the return type to a 81 // This set of templates invokes a base::Callback, converts the return type to a
82 // JavaScript value, and returns that value to script via the provided 82 // JavaScript value, and returns that value to script via the provided
83 // gin::Arguments object. 83 // gin::Arguments object.
84 // 84 //
85 // In C++, you can declare the function foo(void), but you can't pass a void 85 // In C++, you can declare the function foo(void), but you can't pass a void
86 // expression to foo. As a result, we must specialize the case of Callbacks that 86 // expression to foo. As a result, we must specialize the case of Callbacks that
87 // have the void return type. 87 // have the void return type.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 gin::Handle<HolderT> holder = CreateHandle( 200 gin::Handle<HolderT> holder = CreateHandle(
201 isolate, new HolderT(callback, callback_flags)); 201 isolate, new HolderT(callback, callback_flags));
202 return v8::FunctionTemplate::New( 202 return v8::FunctionTemplate::New(
203 &internal::Dispatcher<Sig>::DispatchToCallback, 203 &internal::Dispatcher<Sig>::DispatchToCallback,
204 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); 204 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
205 } 205 }
206 206
207 } // namespace gin 207 } // namespace gin
208 208
209 #endif // GIN_FUNCTION_TEMPLATE_H_ 209 #endif // GIN_FUNCTION_TEMPLATE_H_
OLDNEW
« no previous file with comments | « gin/function_template.cc ('k') | gin/object_template_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698