| OLD | NEW |
| 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 #ifndef GIN_FUNCTION_TEMPLATE_H_ | 7 #ifndef GIN_FUNCTION_TEMPLATE_H_ |
| 8 #define GIN_FUNCTION_TEMPLATE_H_ | 8 #define GIN_FUNCTION_TEMPLATE_H_ |
| 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/gin_export.h" |
| 18 #include "gin/handle.h" | 19 #include "gin/handle.h" |
| 19 #include "gin/public/gin_embedders.h" | 20 #include "gin/public/gin_embedders.h" |
| 20 #include "gin/public/wrapper_info.h" | 21 #include "gin/public/wrapper_info.h" |
| 21 #include "gin/wrappable.h" | 22 #include "gin/wrappable.h" |
| 22 | 23 |
| 23 #include "v8/include/v8.h" | 24 #include "v8/include/v8.h" |
| 24 | 25 |
| 25 namespace gin { | 26 namespace gin { |
| 26 | 27 |
| 27 class PerIsolateData; | 28 class PerIsolateData; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 51 // DispatchToCallback, where it is invoked. | 52 // DispatchToCallback, where it is invoked. |
| 52 // | 53 // |
| 53 // v8::FunctionTemplate only supports passing void* as data so how do we know | 54 // v8::FunctionTemplate only supports passing void* as data so how do we know |
| 54 // when to delete the base::Callback? That's where CallbackHolderBase comes in. | 55 // when to delete the base::Callback? That's where CallbackHolderBase comes in. |
| 55 // It inherits from Wrappable, which delete itself when both (a) the refcount | 56 // It inherits from Wrappable, which delete itself when both (a) the refcount |
| 56 // via base::RefCounted has dropped to zero, and (b) there are no more | 57 // via base::RefCounted has dropped to zero, and (b) there are no more |
| 57 // JavaScript references in V8. | 58 // JavaScript references in V8. |
| 58 | 59 |
| 59 // This simple base class is used so that we can share a single object template | 60 // This simple base class is used so that we can share a single object template |
| 60 // among every CallbackHolder instance. | 61 // among every CallbackHolder instance. |
| 61 class CallbackHolderBase : public Wrappable<CallbackHolderBase> { | 62 class GIN_EXPORT CallbackHolderBase : public Wrappable<CallbackHolderBase> { |
| 62 public: | 63 public: |
| 63 static WrapperInfo kWrapperInfo; | 64 static WrapperInfo kWrapperInfo; |
| 64 | |
| 65 protected: | 65 protected: |
| 66 virtual ~CallbackHolderBase() {} | 66 virtual ~CallbackHolderBase() {} |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 template<typename Sig> | 69 template<typename Sig> |
| 70 class CallbackHolder : public CallbackHolderBase { | 70 class CallbackHolder : public CallbackHolderBase { |
| 71 public: | 71 public: |
| 72 CallbackHolder(const base::Callback<Sig>& callback, int flags) | 72 CallbackHolder(const base::Callback<Sig>& callback, int flags) |
| 73 : callback(callback), flags(flags) {} | 73 : callback(callback), flags(flags) {} |
| 74 base::Callback<Sig> callback; | 74 base::Callback<Sig> callback; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 Invoker<R, P1, P2, P3, P4>::Go(&args, holder->callback, a1, a2, a3, a4); | 327 Invoker<R, P1, P2, P3, P4>::Go(&args, holder->callback, a1, a2, a3, a4); |
| 328 } | 328 } |
| 329 }; | 329 }; |
| 330 | 330 |
| 331 } // namespace internal | 331 } // namespace internal |
| 332 | 332 |
| 333 | 333 |
| 334 // This should be called once per-isolate to initialize the function template | 334 // This should be called once per-isolate to initialize the function template |
| 335 // system. | 335 // system. |
| 336 void InitFunctionTemplates(PerIsolateData* isolate_data); | 336 GIN_EXPORT void InitFunctionTemplates(PerIsolateData* isolate_data); |
| 337 | 337 |
| 338 | 338 |
| 339 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create | 339 // CreateFunctionTemplate creates a v8::FunctionTemplate that will create |
| 340 // JavaScript functions that execute a provided C++ function or base::Callback. | 340 // JavaScript functions that execute a provided C++ function or base::Callback. |
| 341 // JavaScript arguments are automatically converted via gin::Converter, as is | 341 // JavaScript arguments are automatically converted via gin::Converter, as is |
| 342 // the return value of the C++ function, if any. | 342 // the return value of the C++ function, if any. |
| 343 template<typename Sig> | 343 template<typename Sig> |
| 344 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( | 344 v8::Local<v8::FunctionTemplate> CreateFunctionTemplate( |
| 345 v8::Isolate* isolate, const base::Callback<Sig> callback, | 345 v8::Isolate* isolate, const base::Callback<Sig> callback, |
| 346 int callback_flags = 0) { | 346 int callback_flags = 0) { |
| 347 typedef internal::CallbackHolder<Sig> HolderT; | 347 typedef internal::CallbackHolder<Sig> HolderT; |
| 348 gin::Handle<HolderT> holder = CreateHandle( | 348 gin::Handle<HolderT> holder = CreateHandle( |
| 349 isolate, new HolderT(callback, callback_flags)); | 349 isolate, new HolderT(callback, callback_flags)); |
| 350 return v8::FunctionTemplate::New( | 350 return v8::FunctionTemplate::New( |
| 351 &internal::Dispatcher<Sig>::DispatchToCallback, | 351 &internal::Dispatcher<Sig>::DispatchToCallback, |
| 352 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); | 352 ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get())); |
| 353 } | 353 } |
| 354 | 354 |
| 355 } // namespace gin | 355 } // namespace gin |
| 356 | 356 |
| 357 #endif // GIN_FUNCTION_TEMPLATE_H_ | 357 #endif // GIN_FUNCTION_TEMPLATE_H_ |
| OLD | NEW |