diff --git a/v8pp/call_from_v8.hpp b/v8pp/call_from_v8.hpp index 3c7c54aa..021fdf7b 100644 --- a/v8pp/call_from_v8.hpp +++ b/v8pp/call_from_v8.hpp @@ -39,15 +39,11 @@ struct call_from_v8_traits using type = void; }; - template - using arg_type = typename tuple_element::type; - - template, + template::type, typename U = typename std::remove_pointer::type > - using arg_convert = typename std::conditional< + using arg_converter = typename std::conditional< is_wrapped_class::type>::value, typename std::conditional< std::is_pointer::value, @@ -57,6 +53,13 @@ struct call_from_v8_traits convert::type> >::type; + template + using arg_type = typename tuple_element::type; + + template + using arg_convert = arg_converter, Traits>; + template static decltype(arg_convert::from_v8(std::declval(), std::declval>())) arg_from_v8(v8::FunctionCallbackInfo const& args) diff --git a/v8pp/function.hpp b/v8pp/function.hpp index 4b42bc60..7711b5ee 100644 --- a/v8pp/function.hpp +++ b/v8pp/function.hpp @@ -153,7 +153,9 @@ void forward_ret(v8::FunctionCallbackInfo const& args, std::true_type template void forward_ret(v8::FunctionCallbackInfo const& args, std::false_type /*is_void_return*/) { - args.GetReturnValue().Set(to_v8(args.GetIsolate(), + using return_type = typename function_traits::return_type; + using converter = call_from_v8_traits::arg_converter; + args.GetReturnValue().Set(converter::to_v8(args.GetIsolate(), invoke(args, std::is_member_function_pointer()))); } @@ -179,25 +181,25 @@ void forward_function(v8::FunctionCallbackInfo const& args) } // namespace detail /// Wrap C++ function into new V8 function template -template +template v8::Local wrap_function_template(v8::Isolate* isolate, F&& func) { using F_type = typename std::decay::type; return v8::FunctionTemplate::New(isolate, - &detail::forward_function, + &detail::forward_function, detail::set_external_data(isolate, std::forward(func))); } /// Wrap C++ function into new V8 function /// Set nullptr or empty string for name /// to make the function anonymous -template +template v8::Local wrap_function(v8::Isolate* isolate, - char const* name, F&& func) + char const* name, F && func) { using F_type = typename std::decay::type; v8::Local fn = v8::Function::New(isolate->GetCurrentContext(), - &detail::forward_function, + &detail::forward_function, detail::set_external_data(isolate, std::forward(func))).ToLocalChecked(); if (name && *name) {