From 3bfb3d33196a24f812af53484ce54a450a0e5cf5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 27 Oct 2016 22:58:39 -0700 Subject: [PATCH] ircd::js: Argument forwarding for function call operator. --- include/ircd/js/function.h | 24 +++++++++++++----------- include/ircd/js/js.h | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/ircd/js/function.h b/include/ircd/js/function.h index e4b39238a..11fa494c0 100644 --- a/include/ircd/js/function.h +++ b/include/ircd/js/function.h @@ -41,8 +41,8 @@ struct function explicit operator string() const; // js::value/js::object == lifetime::stack - js::value operator()(const js::object &, const JS::HandleValueArray &args) const; - js::value operator()(const js::object &) const; + js::value operator()(const js::object &, const vector::handle &args = {}) const; + template js::value operator()(const js::object &, args&&...) const; // new function function(JS::AutoObjectVector &stack, @@ -122,27 +122,29 @@ function::function(JS::AutoObjectVector &stack, } template +template js::value -function::operator()(const js::object &that) +function::operator()(const js::object &that, + args&&... a) const { - return this->operator()(that, JS::HandleValueArray::empty()); + vector> v + {{ + std::forward(a)... + }}; + + return call(that, *this, decltype(v)::handle(v)); } template js::value function::operator()(const js::object &that, - const JS::HandleValueArray &args) + const vector::handle &args) const { - js::value ret; - if(!JS_CallFunction(*cx, that, *this, args, &ret)) - throw jserror(jserror::pending); - - return ret; + return call(that, *this, args); } - template function::operator string() const diff --git a/include/ircd/js/js.h b/include/ircd/js/js.h index 7371f912f..4f37ad318 100644 --- a/include/ircd/js/js.h +++ b/include/ircd/js/js.h @@ -72,10 +72,10 @@ inline JSVersion version(const char *const &v) { return JS_StringToVersion(v); #include "string.h" #include "id.h" #include "object.h" +#include "vector.h" #include "script.h" #include "function.h" #include "function_literal.h" -#include "vector.h" #include "priv.h" #include "has.h" #include "get.h"