0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +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;
// 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<js::value>::handle &args = {}) const;
template<class... args> js::value operator()(const js::object &, args&&...) const;
// new function
function(JS::AutoObjectVector &stack,
@ -122,27 +122,29 @@ function<L>::function(JS::AutoObjectVector &stack,
}
template<lifetime L>
template<class... args>
js::value
function<L>::operator()(const js::object &that)
function<L>::operator()(const js::object &that,
args&&... a)
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>
js::value
function<L>::operator()(const js::object &that,
const JS::HandleValueArray &args)
const vector<js::value>::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<lifetime L>
function<L>::operator string<L>()
const

View file

@ -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"