| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GIN_FUNCTION_TEMPLATE_H_ | 5 #ifndef GIN_FUNCTION_TEMPLATE_H_ |
| 6 #define GIN_FUNCTION_TEMPLATE_H_ | 6 #define GIN_FUNCTION_TEMPLATE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "gin/arguments.h" | 10 #include "gin/arguments.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // at position |index|. | 124 // at position |index|. |
| 125 template <size_t index, typename ArgType> | 125 template <size_t index, typename ArgType> |
| 126 struct ArgumentHolder { | 126 struct ArgumentHolder { |
| 127 using ArgLocalType = typename CallbackParamTraits<ArgType>::LocalType; | 127 using ArgLocalType = typename CallbackParamTraits<ArgType>::LocalType; |
| 128 | 128 |
| 129 ArgLocalType value; | 129 ArgLocalType value; |
| 130 bool ok; | 130 bool ok; |
| 131 | 131 |
| 132 ArgumentHolder(Arguments* args, int create_flags) | 132 ArgumentHolder(Arguments* args, int create_flags) |
| 133 : ok(GetNextArgument(args, create_flags, index == 0, &value)) { | 133 : ok(GetNextArgument(args, create_flags, index == 0, &value)) { |
| 134 if (!ok) | 134 if (!ok) { |
| 135 // Ideally we would include the expected c++ type in the error |
| 136 // message which we can access via typeid(ArgType).name() |
| 137 // however we compile with no-rtti, which disables typeid. |
| 135 args->ThrowError(); | 138 args->ThrowError(); |
| 139 } |
| 136 } | 140 } |
| 137 }; | 141 }; |
| 138 | 142 |
| 139 // Class template for converting arguments from JavaScript to C++ and running | 143 // Class template for converting arguments from JavaScript to C++ and running |
| 140 // the callback with them. | 144 // the callback with them. |
| 141 template <typename IndicesType, typename... ArgTypes> | 145 template <typename IndicesType, typename... ArgTypes> |
| 142 class Invoker {}; | 146 class Invoker {}; |
| 143 | 147 |
| 144 template <size_t... indices, typename... ArgTypes> | 148 template <size_t... indices, typename... ArgTypes> |
| 145 class Invoker<IndicesHolder<indices...>, ArgTypes...> | 149 class Invoker<IndicesHolder<indices...>, ArgTypes...> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 typedef internal::CallbackHolder<Sig> HolderT; | 244 typedef internal::CallbackHolder<Sig> HolderT; |
| 241 HolderT* holder = new HolderT(isolate, callback, callback_flags); | 245 HolderT* holder = new HolderT(isolate, callback, callback_flags); |
| 242 tmpl->SetCallAsFunctionHandler(&internal::Dispatcher<Sig>::DispatchToCallback, | 246 tmpl->SetCallAsFunctionHandler(&internal::Dispatcher<Sig>::DispatchToCallback, |
| 243 ConvertToV8<v8::Handle<v8::External> >( | 247 ConvertToV8<v8::Handle<v8::External> >( |
| 244 isolate, holder->GetHandle(isolate))); | 248 isolate, holder->GetHandle(isolate))); |
| 245 } | 249 } |
| 246 | 250 |
| 247 } // namespace gin | 251 } // namespace gin |
| 248 | 252 |
| 249 #endif // GIN_FUNCTION_TEMPLATE_H_ | 253 #endif // GIN_FUNCTION_TEMPLATE_H_ |
| OLD | NEW |