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:
parent
b9137fd475
commit
3bfb3d3319
2 changed files with 14 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue