OLD | NEW |
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 |
11 $var MAX_ARITY = 4 | 11 $var MAX_ARITY = 4 |
12 | 12 |
13 // Copyright 2013 The Chromium Authors. All rights reserved. | 13 // Copyright 2013 The Chromium Authors. All rights reserved. |
14 // Use of this source code is governed by a BSD-style license that can be | 14 // Use of this source code is governed by a BSD-style license that can be |
15 // found in the LICENSE file. | 15 // found in the LICENSE file. |
16 | 16 |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "gin/arguments.h" | 19 #include "gin/arguments.h" |
20 #include "gin/converter.h" | 20 #include "gin/converter.h" |
| 21 #include "gin/gin_export.h" |
21 #include "gin/handle.h" | 22 #include "gin/handle.h" |
22 #include "gin/public/gin_embedders.h" | 23 #include "gin/public/gin_embedders.h" |
23 #include "gin/public/wrapper_info.h" | 24 #include "gin/public/wrapper_info.h" |
24 #include "gin/wrappable.h" | 25 #include "gin/wrappable.h" |
25 | 26 |
26 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
27 | 28 |
28 namespace gin { | 29 namespace gin { |
29 | 30 |
30 class PerIsolateData; | 31 class PerIsolateData; |
(...skipping 23 matching lines...) Expand all Loading... |
54 // DispatchToCallback, where it is invoked. | 55 // DispatchToCallback, where it is invoked. |
55 // | 56 // |
56 // v8::FunctionTemplate only supports passing void* as data so how do we know | 57 // 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. | 58 // 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 | 59 // 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 | 60 // via base::RefCounted has dropped to zero, and (b) there are no more |
60 // JavaScript references in V8. | 61 // JavaScript references in V8. |
61 | 62 |
62 // 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 |
63 // among every CallbackHolder instance. | 64 // among every CallbackHolder instance. |
64 class CallbackHolderBase : public Wrappable<CallbackHolderBase> { | 65 class GIN_EXPORT CallbackHolderBase : public Wrappable<CallbackHolderBase> { |
65 public: | 66 public: |
66 static WrapperInfo kWrapperInfo; | 67 static WrapperInfo kWrapperInfo; |
67 | 68 |
68 protected: | 69 protected: |
69 virtual ~CallbackHolderBase() {} | 70 virtual ~CallbackHolderBase() {} |
70 }; | 71 }; |
71 | 72 |
72 template<typename Sig> | 73 template<typename Sig> |
73 class CallbackHolder : public CallbackHolderBase { | 74 class CallbackHolder : public CallbackHolderBase { |
74 public: | 75 public: |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 182 } |
182 }; | 183 }; |
183 | 184 |
184 ]] | 185 ]] |
185 | 186 |
186 } // namespace internal | 187 } // namespace internal |
187 | 188 |
188 | 189 |
189 // This should be called once per-isolate to initialize the function template | 190 // This should be called once per-isolate to initialize the function template |
190 // system. | 191 // system. |
191 void InitFunctionTemplates(PerIsolateData* isolate_data); | 192 GIN_EXPORT void InitFunctionTemplates(PerIsolateData* isolate_data); |
192 | 193 |
193 | 194 |
194 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create | 195 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create |
195 // JavaScript functions that execute a provided C++ function or base::Callback. | 196 // JavaScript functions that execute a provided C++ function or base::Callback. |
196 // JavaScript arguments are automatically converted via gin::Converter, as is | 197 // JavaScript arguments are automatically converted via gin::Converter, as is |
197 // the return value of the C++ function, if any. | 198 // the return value of the C++ function, if any. |
198 template<typename Sig> | 199 template<typename Sig> |
199 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( | 200 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( |
200 v8::Isolate* isolate, const base::Callback<Sig> callback, | 201 v8::Isolate* isolate, const base::Callback<Sig> callback, |
201 int callback_flags = 0) { | 202 int callback_flags = 0) { |
202 typedef internal::CallbackHolder<Sig> HolderT; | 203 typedef internal::CallbackHolder<Sig> HolderT; |
203 gin::Handle<HolderT> holder = CreateHandle( | 204 gin::Handle<HolderT> holder = CreateHandle( |
204 isolate, new HolderT(callback, callback_flags)); | 205 isolate, new HolderT(callback, callback_flags)); |
205 return v8::FunctionTemplate::New( | 206 return v8::FunctionTemplate::New( |
206 &internal::Dispatcher<Sig>::DispatchToCallback, | 207 &internal::Dispatcher<Sig>::DispatchToCallback, |
207 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); | 208 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); |
208 } | 209 } |
209 | 210 |
210 } // namespace gin | 211 } // namespace gin |
211 | 212 |
212 #endif // GIN_FUNCTION_TEMPLATE_H_ | 213 #endif // GIN_FUNCTION_TEMPLATE_H_ |
OLD | NEW |