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

Side by Side Diff: gin/function_template.h

Issue 89723002: Convert the rest of the functions in core.cc to use CreateFunctionTemplate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase+comments 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/dictionary.cc ('k') | gin/function_template.h.pump » ('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 // Copyright 2013 The Chromium Authors. All rights reserved. 7 // Copyright 2013 The Chromium Authors. All rights reserved.
8 // Use of this source code is governed by a BSD-style license that can be 8 // Use of this source code is governed by a BSD-style license that can be
9 // found in the LICENSE file. 9 // found in the LICENSE file.
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 }; 62 };
63 63
64 64
65 // This set of templates invokes a base::Callback, converts the return type to a 65 // This set of templates invokes a base::Callback, converts the return type to a
66 // JavaScript value, and returns that value to script via the provided 66 // JavaScript value, and returns that value to script via the provided
67 // gin::Arguments object. 67 // gin::Arguments object.
68 // 68 //
69 // In C++, you can declare the function foo(void), but you can't pass a void 69 // In C++, you can declare the function foo(void), but you can't pass a void
70 // expression to foo. As a result, we must specialize the case of Callbacks that 70 // expression to foo. As a result, we must specialize the case of Callbacks that
71 // have the void return type. 71 // have the void return type.
72 template<typename R, typename P1 = void, typename P2 = void, typename P3 = void> 72 template<typename R, typename P1 = void, typename P2 = void,
73 typename P3 = void, typename P4 = void>
73 struct Invoker { 74 struct Invoker {
74 inline static void Go( 75 inline static void Go(
75 Arguments* args, 76 Arguments* args,
77 const base::Callback<R(P1, P2, P3, P4)>& callback,
78 const P1& a1,
79 const P2& a2,
80 const P3& a3,
81 const P4& a4) {
82 args->Return(callback.Run(a1, a2, a3, a4));
83 }
84 };
85 template<typename P1, typename P2, typename P3, typename P4>
86 struct Invoker<void, P1, P2, P3, P4> {
87 inline static void Go(
88 Arguments* args,
89 const base::Callback<void(P1, P2, P3, P4)>& callback,
90 const P1& a1,
91 const P2& a2,
92 const P3& a3,
93 const P4& a4) {
94 callback.Run(a1, a2, a3, a4);
95 }
96 };
97
98 template<typename R, typename P1, typename P2, typename P3>
99 struct Invoker<R, P1, P2, P3, void> {
100 inline static void Go(
101 Arguments* args,
76 const base::Callback<R(P1, P2, P3)>& callback, 102 const base::Callback<R(P1, P2, P3)>& callback,
77 const P1& a1, 103 const P1& a1,
78 const P2& a2, 104 const P2& a2,
79 const P3& a3) { 105 const P3& a3) {
80 args->Return(callback.Run(a1, a2, a3)); 106 args->Return(callback.Run(a1, a2, a3));
81 } 107 }
82 }; 108 };
83 template<typename P1, typename P2, typename P3> 109 template<typename P1, typename P2, typename P3>
84 struct Invoker<void, P1, P2, P3> { 110 struct Invoker<void, P1, P2, P3, void> {
85 inline static void Go( 111 inline static void Go(
86 Arguments* args, 112 Arguments* args,
87 const base::Callback<void(P1, P2, P3)>& callback, 113 const base::Callback<void(P1, P2, P3)>& callback,
88 const P1& a1, 114 const P1& a1,
89 const P2& a2, 115 const P2& a2,
90 const P3& a3) { 116 const P3& a3) {
91 callback.Run(a1, a2, a3); 117 callback.Run(a1, a2, a3);
92 } 118 }
93 }; 119 };
94 120
95 template<typename R, typename P1, typename P2> 121 template<typename R, typename P1, typename P2>
96 struct Invoker<R, P1, P2, void> { 122 struct Invoker<R, P1, P2, void, void> {
97 inline static void Go( 123 inline static void Go(
98 Arguments* args, 124 Arguments* args,
99 const base::Callback<R(P1, P2)>& callback, 125 const base::Callback<R(P1, P2)>& callback,
100 const P1& a1, 126 const P1& a1,
101 const P2& a2) { 127 const P2& a2) {
102 args->Return(callback.Run(a1, a2)); 128 args->Return(callback.Run(a1, a2));
103 } 129 }
104 }; 130 };
105 template<typename P1, typename P2> 131 template<typename P1, typename P2>
106 struct Invoker<void, P1, P2, void> { 132 struct Invoker<void, P1, P2, void, void> {
107 inline static void Go( 133 inline static void Go(
108 Arguments* args, 134 Arguments* args,
109 const base::Callback<void(P1, P2)>& callback, 135 const base::Callback<void(P1, P2)>& callback,
110 const P1& a1, 136 const P1& a1,
111 const P2& a2) { 137 const P2& a2) {
112 callback.Run(a1, a2); 138 callback.Run(a1, a2);
113 } 139 }
114 }; 140 };
115 141
116 template<typename R, typename P1> 142 template<typename R, typename P1>
117 struct Invoker<R, P1, void, void> { 143 struct Invoker<R, P1, void, void, void> {
118 inline static void Go( 144 inline static void Go(
119 Arguments* args, 145 Arguments* args,
120 const base::Callback<R(P1)>& callback, 146 const base::Callback<R(P1)>& callback,
121 const P1& a1) { 147 const P1& a1) {
122 args->Return(callback.Run(a1)); 148 args->Return(callback.Run(a1));
123 } 149 }
124 }; 150 };
125 template<typename P1> 151 template<typename P1>
126 struct Invoker<void, P1, void, void> { 152 struct Invoker<void, P1, void, void, void> {
127 inline static void Go( 153 inline static void Go(
128 Arguments* args, 154 Arguments* args,
129 const base::Callback<void(P1)>& callback, 155 const base::Callback<void(P1)>& callback,
130 const P1& a1) { 156 const P1& a1) {
131 callback.Run(a1); 157 callback.Run(a1);
132 } 158 }
133 }; 159 };
134 160
135 template<typename R> 161 template<typename R>
136 struct Invoker<R, void, void, void> { 162 struct Invoker<R, void, void, void, void> {
137 inline static void Go( 163 inline static void Go(
138 Arguments* args, 164 Arguments* args,
139 const base::Callback<R()>& callback) { 165 const base::Callback<R()>& callback) {
140 args->Return(callback.Run()); 166 args->Return(callback.Run());
141 } 167 }
142 }; 168 };
143 template<> 169 template<>
144 struct Invoker<void, void, void, void> { 170 struct Invoker<void, void, void, void, void> {
145 inline static void Go( 171 inline static void Go(
146 Arguments* args, 172 Arguments* args,
147 const base::Callback<void()>& callback) { 173 const base::Callback<void()>& callback) {
148 callback.Run(); 174 callback.Run();
149 } 175 }
150 }; 176 };
151 177
152 178
153 // DispatchToCallback converts all the JavaScript arguments to C++ types and 179 // DispatchToCallback converts all the JavaScript arguments to C++ types and
154 // invokes the base::Callback. 180 // invokes the base::Callback.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!args.GetNext(&a1) || 247 if (!args.GetNext(&a1) ||
222 !args.GetNext(&a2) || 248 !args.GetNext(&a2) ||
223 !args.GetNext(&a3)) { 249 !args.GetNext(&a3)) {
224 args.ThrowError(); 250 args.ThrowError();
225 return; 251 return;
226 } 252 }
227 253
228 Invoker<R, P1, P2, P3>::Go(&args, holder->callback, a1, a2, a3); 254 Invoker<R, P1, P2, P3>::Go(&args, holder->callback, a1, a2, a3);
229 } 255 }
230 256
257 template<typename R, typename P1, typename P2, typename P3, typename P4>
258 static void DispatchToCallback(
259 const v8::FunctionCallbackInfo<v8::Value>& info) {
260 Arguments args(info);
261 CallbackHolderBase* holder_base = NULL;
262 CHECK(args.GetData(&holder_base));
263
264 typedef CallbackHolder<R(P1, P2, P3, P4)> HolderT;
265 HolderT* holder = static_cast<HolderT*>(holder_base);
266
267 typename RemoveConstRef<P1>::Type a1;
268 typename RemoveConstRef<P2>::Type a2;
269 typename RemoveConstRef<P3>::Type a3;
270 typename RemoveConstRef<P4>::Type a4;
271 if (!args.GetNext(&a1) ||
272 !args.GetNext(&a2) ||
273 !args.GetNext(&a3) ||
274 !args.GetNext(&a4)) {
275 args.ThrowError();
276 return;
277 }
278
279 Invoker<R, P1, P2, P3, P4>::Go(&args, holder->callback, a1, a2, a3, a4);
280 }
281
231 } // namespace internal 282 } // namespace internal
232 283
233 284
234 // This should be called once per-isolate to initialize the function template 285 // This should be called once per-isolate to initialize the function template
235 // system. 286 // system.
236 void InitFunctionTemplates(PerIsolateData* isolate_data); 287 void InitFunctionTemplates(PerIsolateData* isolate_data);
237 288
289
238 // This has to be outside the internal namespace because template 290 // This has to be outside the internal namespace because template
239 // specializations must be declared in the same namespace as the original 291 // specializations must be declared in the same namespace as the original
240 // template. 292 // template.
241 template<> 293 template<>
242 struct Converter<internal::CallbackHolderBase*> 294 struct Converter<internal::CallbackHolderBase*>
243 : public WrappableConverter<internal::CallbackHolderBase> {}; 295 : public WrappableConverter<internal::CallbackHolderBase> {};
244 296
245 297
246 // Creates a v8::FunctionTemplate that will run the provided base::Callback each 298 // Creates a v8::FunctionTemplate that will run the provided base::Callback each
247 // time it is called. JavaScript arguments and return values are converted via 299 // time it is called. JavaScript arguments and return values are converted via
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( 335 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
284 v8::Isolate* isolate, 336 v8::Isolate* isolate,
285 const base::Callback<R(P1, P2, P3)> callback) { 337 const base::Callback<R(P1, P2, P3)> callback) {
286 typedef internal::CallbackHolder<R(P1, P2, P3)> HolderT; 338 typedef internal::CallbackHolder<R(P1, P2, P3)> HolderT;
287 scoped_refptr<HolderT> holder(new HolderT(callback)); 339 scoped_refptr<HolderT> holder(new HolderT(callback));
288 return v8::FunctionTemplate::New( 340 return v8::FunctionTemplate::New(
289 &internal::DispatchToCallback<R, P1, P2, P3>, 341 &internal::DispatchToCallback<R, P1, P2, P3>,
290 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); 342 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
291 } 343 }
292 344
345 template<typename R, typename P1, typename P2, typename P3, typename P4>
346 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
347 v8::Isolate* isolate,
348 const base::Callback<R(P1, P2, P3, P4)> callback) {
349 typedef internal::CallbackHolder<R(P1, P2, P3, P4)> HolderT;
350 scoped_refptr<HolderT> holder(new HolderT(callback));
351 return v8::FunctionTemplate::New(
352 &internal::DispatchToCallback<R, P1, P2, P3, P4>,
353 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
354 }
355
293 } // namespace gin 356 } // namespace gin
OLDNEW
« no previous file with comments | « gin/dictionary.cc ('k') | gin/function_template.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698