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

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

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
« no previous file with comments | « gin/function_template.cc ('k') | gin/isolate_holder.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 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // when to delete the base::Callback? That's where CallbackHolderBase comes in. 58 // when to delete the base::Callback? That's where CallbackHolderBase comes in.
59 // It inherits from Wrappable, which delete itself when both (a) the refcount 59 // It inherits from Wrappable, which delete itself when both (a) the refcount
60 // via base::RefCounted has dropped to zero, and (b) there are no more 60 // via base::RefCounted has dropped to zero, and (b) there are no more
61 // JavaScript references in V8. 61 // JavaScript references in V8.
62 62
63 // This simple base class is used so that we can share a single object template 63 // This simple base class is used so that we can share a single object template
64 // among every CallbackHolder instance. 64 // among every CallbackHolder instance.
65 class GIN_EXPORT CallbackHolderBase : public Wrappable<CallbackHolderBase> { 65 class GIN_EXPORT CallbackHolderBase : public Wrappable<CallbackHolderBase> {
66 public: 66 public:
67 static WrapperInfo kWrapperInfo; 67 static WrapperInfo kWrapperInfo;
68
69 protected: 68 protected:
70 virtual ~CallbackHolderBase() {} 69 virtual ~CallbackHolderBase() {}
71 }; 70 };
72 71
73 template<typename Sig> 72 template<typename Sig>
74 class CallbackHolder : public CallbackHolderBase { 73 class CallbackHolder : public CallbackHolderBase {
75 public: 74 public:
76 CallbackHolder(const base::Callback<Sig>& callback, int flags) 75 CallbackHolder(const base::Callback<Sig>& callback, int flags)
77 : callback(callback), flags(flags) {} 76 : callback(callback), flags(flags) {}
78 base::Callback<Sig> callback; 77 base::Callback<Sig> callback;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 179
181 Invoker<R$for ARG [[, P$(ARG)]]>::Go(&args, holder->callback$for ARG [[, a$( ARG)]]); 180 Invoker<R$for ARG [[, P$(ARG)]]>::Go(&args, holder->callback$for ARG [[, a$( ARG)]]);
182 } 181 }
183 }; 182 };
184 183
185 ]] 184 ]]
186 185
187 } // namespace internal 186 } // namespace internal
188 187
189 188
190 // This should be called once per-isolate to initialize the function template
191 // system.
192 GIN_EXPORT void InitFunctionTemplates(PerIsolateData* isolate_data);
193
194
195 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create 189 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create
196 // JavaScript functions that execute a provided C++ function or base::Callback. 190 // JavaScript functions that execute a provided C++ function or base::Callback.
197 // JavaScript arguments are automatically converted via gin::Converter, as is 191 // JavaScript arguments are automatically converted via gin::Converter, as is
198 // the return value of the C++ function, if any. 192 // the return value of the C++ function, if any.
199 template<typename Sig> 193 template<typename Sig>
200 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( 194 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
201 v8::Isolate* isolate, const base::Callback<Sig> callback, 195 v8::Isolate* isolate, const base::Callback<Sig> callback,
202 int callback_flags = 0) { 196 int callback_flags = 0) {
203 typedef internal::CallbackHolder<Sig> HolderT; 197 typedef internal::CallbackHolder<Sig> HolderT;
204 gin::Handle<HolderT> holder = CreateHandle( 198 gin::Handle<HolderT> holder = CreateHandle(
205 isolate, new HolderT(callback, callback_flags)); 199 isolate, new HolderT(callback, callback_flags));
206 return v8::FunctionTemplate::New( 200 return v8::FunctionTemplate::New(
207 &internal::Dispatcher<Sig>::DispatchToCallback, 201 &internal::Dispatcher<Sig>::DispatchToCallback,
208 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); 202 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
209 } 203 }
210 204
211 } // namespace gin 205 } // namespace gin
212 206
213 #endif // GIN_FUNCTION_TEMPLATE_H_ 207 #endif // GIN_FUNCTION_TEMPLATE_H_
OLDNEW
« no previous file with comments | « gin/function_template.cc ('k') | gin/isolate_holder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698