0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 08:21:09 +01:00

ircd::js: Argument forwarding for function call operator.

This commit is contained in:
Jason Volk 2016-10-27 22:58:39 -07:00
parent b9137fd475
commit 3bfb3d3319
2 changed files with 14 additions and 12 deletions

View file

@ -41,8 +41,8 @@ struct function
explicit operator string<L>() const; explicit operator string<L>() const;
// js::value/js::object == lifetime::stack // js::value/js::object == lifetime::stack
js::value operator()(const js::object &, const JS::HandleValueArray &args) const; js::value operator()(const js::object &, const vector<js::value>::handle &args = {}) const;
js::value operator()(const js::object &) const; template<class... args> js::value operator()(const js::object &, args&&...) const;
// new function // new function
function(JS::AutoObjectVector &stack, function(JS::AutoObjectVector &stack,
@ -122,27 +122,29 @@ function<L>::function(JS::AutoObjectVector &stack,
} }
template<lifetime L> template<lifetime L>
template<class... args>
js::value js::value
function<L>::operator()(const js::object &that) function<L>::operator()(const js::object &that,
args&&... a)
const const
{ {
return this->operator()(that, JS::HandleValueArray::empty()); vector<basic::value<lifetime::stack>> v
{{
std::forward<args>(a)...
}};
return call(that, *this, decltype(v)::handle(v));
} }
template<lifetime L> template<lifetime L>
js::value js::value
function<L>::operator()(const js::object &that, function<L>::operator()(const js::object &that,
const JS::HandleValueArray &args) const vector<js::value>::handle &args)
const const
{ {
js::value ret; return call(that, *this, args);
if(!JS_CallFunction(*cx, that, *this, args, &ret))
throw jserror(jserror::pending);
return ret;
} }
template<lifetime L> template<lifetime L>
function<L>::operator string<L>() function<L>::operator string<L>()
const const

View file

@ -72,10 +72,10 @@ inline JSVersion version(const char *const &v) { return JS_StringToVersion(v);
#include "string.h" #include "string.h"
#include "id.h" #include "id.h"
#include "object.h" #include "object.h"
#include "vector.h"
#include "script.h" #include "script.h"
#include "function.h" #include "function.h"
#include "function_literal.h" #include "function_literal.h"
#include "vector.h"
#include "priv.h" #include "priv.h"
#include "has.h" #include "has.h"
#include "get.h" #include "get.h"