| 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 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 68 |
| 69 protected: | 69 protected: |
| 70 virtual ~CallbackHolderBase() {} | 70 virtual ~CallbackHolderBase() {} |
| 71 |
| 72 private: |
| 73 friend class Wrappable<CallbackHolderBase>; |
| 74 static v8::Local<v8::ObjectTemplate> GetObjectTemplate(v8::Isolate* isolate); |
| 71 }; | 75 }; |
| 72 | 76 |
| 73 template<typename Sig> | 77 template<typename Sig> |
| 74 class CallbackHolder : public CallbackHolderBase { | 78 class CallbackHolder : public CallbackHolderBase { |
| 75 public: | 79 public: |
| 76 CallbackHolder(const base::Callback<Sig>& callback, int flags) | 80 CallbackHolder(const base::Callback<Sig>& callback, int flags) |
| 77 : callback(callback), flags(flags) {} | 81 : callback(callback), flags(flags) {} |
| 78 base::Callback<Sig> callback; | 82 base::Callback<Sig> callback; |
| 79 int flags; | 83 int flags; |
| 80 private: | 84 private: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 184 |
| 181 Invoker<R$for ARG [[, P$(ARG)]]>::Go(&args, holder->callback$for ARG [[, a$(
ARG)]]); | 185 Invoker<R$for ARG [[, P$(ARG)]]>::Go(&args, holder->callback$for ARG [[, a$(
ARG)]]); |
| 182 } | 186 } |
| 183 }; | 187 }; |
| 184 | 188 |
| 185 ]] | 189 ]] |
| 186 | 190 |
| 187 } // namespace internal | 191 } // namespace internal |
| 188 | 192 |
| 189 | 193 |
| 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 | 194 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create |
| 196 // JavaScript functions that execute a provided C++ function or base::Callback. | 195 // JavaScript functions that execute a provided C++ function or base::Callback. |
| 197 // JavaScript arguments are automatically converted via gin::Converter, as is | 196 // JavaScript arguments are automatically converted via gin::Converter, as is |
| 198 // the return value of the C++ function, if any. | 197 // the return value of the C++ function, if any. |
| 199 template<typename Sig> | 198 template<typename Sig> |
| 200 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( | 199 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( |
| 201 v8::Isolate* isolate, const base::Callback<Sig> callback, | 200 v8::Isolate* isolate, const base::Callback<Sig> callback, |
| 202 int callback_flags = 0) { | 201 int callback_flags = 0) { |
| 203 typedef internal::CallbackHolder<Sig> HolderT; | 202 typedef internal::CallbackHolder<Sig> HolderT; |
| 204 gin::Handle<HolderT> holder = CreateHandle( | 203 gin::Handle<HolderT> holder = CreateHandle( |
| 205 isolate, new HolderT(callback, callback_flags)); | 204 isolate, new HolderT(callback, callback_flags)); |
| 206 return v8::FunctionTemplate::New( | 205 return v8::FunctionTemplate::New( |
| 207 &internal::Dispatcher<Sig>::DispatchToCallback, | 206 &internal::Dispatcher<Sig>::DispatchToCallback, |
| 208 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); | 207 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); |
| 209 } | 208 } |
| 210 | 209 |
| 211 } // namespace gin | 210 } // namespace gin |
| 212 | 211 |
| 213 #endif // GIN_FUNCTION_TEMPLATE_H_ | 212 #endif // GIN_FUNCTION_TEMPLATE_H_ |
| OLD | NEW |