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

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

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/function_template.h ('k') | gin/modules/module_registry.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 $var MAX_ARITY = 3 8 $var MAX_ARITY = 4
9 9
10 // Copyright 2013 The Chromium Authors. All rights reserved. 10 // Copyright 2013 The Chromium Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style license that can be 11 // Use of this source code is governed by a BSD-style license that can be
12 // found in the LICENSE file. 12 // found in the LICENSE file.
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "gin/arguments.h" 16 #include "gin/arguments.h"
17 #include "gin/converter.h" 17 #include "gin/converter.h"
18 #include "gin/public/gin_embedders.h" 18 #include "gin/public/gin_embedders.h"
(...skipping 22 matching lines...) Expand all
41 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to 41 // CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to
42 // DispatchToCallback, where it is invoked. 42 // DispatchToCallback, where it is invoked.
43 // 43 //
44 // v8::FunctionTemplate only supports passing void* as data so how do we know 44 // v8::FunctionTemplate only supports passing void* as data so how do we know
45 // when to delete the base::Callback? That's where CallbackHolderBase comes in. 45 // when to delete the base::Callback? That's where CallbackHolderBase comes in.
46 // It inherits from Wrappable, which delete itself when both (a) the refcount 46 // It inherits from Wrappable, which delete itself when both (a) the refcount
47 // via base::RefCounted has dropped to zero, and (b) there are no more 47 // via base::RefCounted has dropped to zero, and (b) there are no more
48 // JavaScript references in V8. 48 // JavaScript references in V8.
49 class CallbackHolderBase : public Wrappable { 49 class CallbackHolderBase : public Wrappable {
50 public: 50 public:
51 static void EnsureRegistered(PerIsolateData* isolate_data);
52 virtual WrapperInfo* GetWrapperInfo() OVERRIDE; 51 virtual WrapperInfo* GetWrapperInfo() OVERRIDE;
53 static WrapperInfo kWrapperInfo; 52 static WrapperInfo kWrapperInfo;
54 protected: 53 protected:
55 virtual ~CallbackHolderBase() {} 54 virtual ~CallbackHolderBase() {}
56 }; 55 };
57 56
58 template<typename Sig> 57 template<typename Sig>
59 class CallbackHolder : public CallbackHolderBase { 58 class CallbackHolder : public CallbackHolderBase {
60 public: 59 public:
61 CallbackHolder(const base::Callback<Sig>& callback) 60 CallbackHolder(const base::Callback<Sig>& callback)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ]] 139 ]]
141 140
142 Invoker<R$for ARG [[, P$(ARG)]]>::Go(&args, holder->callback$for ARG [[, a$(AR G)]]); 141 Invoker<R$for ARG [[, P$(ARG)]]>::Go(&args, holder->callback$for ARG [[, a$(AR G)]]);
143 } 142 }
144 143
145 ]] 144 ]]
146 145
147 } // namespace internal 146 } // namespace internal
148 147
149 148
149 // This should be called once per-isolate to initialize the function template
150 // system.
151 void InitFunctionTemplates(PerIsolateData* isolate_data);
152
153
150 // This has to be outside the internal namespace because template 154 // This has to be outside the internal namespace because template
151 // specializations must be declared in the same namespace as the original 155 // specializations must be declared in the same namespace as the original
152 // template. 156 // template.
153 template<> 157 template<>
154 struct Converter<internal::CallbackHolderBase*> 158 struct Converter<internal::CallbackHolderBase*>
155 : public WrappableConverter<internal::CallbackHolderBase> {}; 159 : public WrappableConverter<internal::CallbackHolderBase> {};
156 160
157 161
158 // Creates a v8::FunctionTemplate that will run the provided base::Callback each 162 // Creates a v8::FunctionTemplate that will run the provided base::Callback each
159 // time it is called. JavaScript arguments and return values are converted via 163 // time it is called. JavaScript arguments and return values are converted via
160 // gin::Converter. 164 // gin::Converter.
161 $range ARITY 0..MAX_ARITY 165 $range ARITY 0..MAX_ARITY
162 $for ARITY [[ 166 $for ARITY [[
163 $range ARG 1..ARITY 167 $range ARG 1..ARITY
164 168
165 template<typename R$for ARG [[, typename P$(ARG)]]> 169 template<typename R$for ARG [[, typename P$(ARG)]]>
166 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( 170 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
167 v8::Isolate* isolate, 171 v8::Isolate* isolate,
168 const base::Callback<R($for ARG , [[P$(ARG)]])> callback) { 172 const base::Callback<R($for ARG , [[P$(ARG)]])> callback) {
169 typedef internal::CallbackHolder<R($for ARG , [[P$(ARG)]])> HolderT; 173 typedef internal::CallbackHolder<R($for ARG , [[P$(ARG)]])> HolderT;
170 scoped_refptr<HolderT> holder(new HolderT(callback)); 174 scoped_refptr<HolderT> holder(new HolderT(callback));
171 return v8::FunctionTemplate::New( 175 return v8::FunctionTemplate::New(
172 &internal::DispatchToCallback<R$for ARG [[, P$(ARG)]]>, 176 &internal::DispatchToCallback<R$for ARG [[, P$(ARG)]]>,
173 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); 177 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
174 } 178 }
175 179
176 ]] 180 ]]
177 181
178 } // namespace gin 182 } // namespace gin
OLDNEW
« no previous file with comments | « gin/function_template.h ('k') | gin/modules/module_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698