0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd::js: Order arguments to call() more intuitively.

This commit is contained in:
Jason Volk 2016-10-31 12:03:03 -07:00
parent 42f0c6b06b
commit bf540caead
3 changed files with 29 additions and 29 deletions

View file

@ -26,23 +26,23 @@ namespace ircd {
namespace js {
value
call(const object &obj,
const function::handle &func,
call(const function::handle &func,
const object &that,
const vector<value>::handle &args = {});
value
call(const object &obj,
const value::handle &val,
call(const value::handle &val,
const object &that,
const vector<value>::handle &args = {});
value
call(const object &obj,
const char *const &name,
call(const char *const &name,
const object &that,
const vector<value>::handle &args = {});
value
call(const object &obj,
const std::string &name,
call(const std::string &name,
const object &that,
const vector<value>::handle &args = {});
} // namespace js

View file

@ -42,7 +42,7 @@ struct function
explicit operator string<L>() const;
// js::value/js::object == lifetime::stack
js::value operator()(const js::object &, const vector<js::value>::handle &args = {}) 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
@ -131,12 +131,12 @@ function<L>::operator()(const js::object &that,
args&&... a)
const
{
vector<basic::value<lifetime::stack>> v
vector<basic::value<lifetime::stack>> argv
{{
std::forward<args>(a)...
}};
return call(that, *this, decltype(v)::handle(v));
return call(*this, that, decltype(argv)::handle());
}
template<lifetime L>
@ -145,7 +145,7 @@ function<L>::operator()(const js::object &that,
const vector<js::value>::handle &args)
const
{
return call(that, *this, args);
return call(*this, that, args);
}
template<lifetime L>

View file

@ -1010,49 +1010,49 @@ noexcept
//
ircd::js::value
ircd::js::call(const object &obj,
const function::handle &func,
ircd::js::call(const std::string &name,
const object &that,
const vector<value>::handle &args)
{
return call(name.c_str(), that, args);
}
ircd::js::value
ircd::js::call(const char *const &name,
const object &that,
const vector<value>::handle &args)
{
value ret;
if(!JS_CallFunction(*cx, obj, func, args, &ret))
if(!JS_CallFunctionName(*cx, that, name, args, &ret))
throw jserror(jserror::pending);
return ret;
}
ircd::js::value
ircd::js::call(const object &obj,
const value::handle &val,
ircd::js::call(const value::handle &val,
const object &that,
const vector<value>::handle &args)
{
value ret;
if(!JS_CallFunctionValue(*cx, obj, val, args, &ret))
if(!JS_CallFunctionValue(*cx, that, val, args, &ret))
throw jserror(jserror::pending);
return ret;
}
ircd::js::value
ircd::js::call(const object &obj,
const char *const &name,
ircd::js::call(const function::handle &func,
const object &that,
const vector<value>::handle &args)
{
value ret;
if(!JS_CallFunctionName(*cx, obj, name, args, &ret))
if(!JS_CallFunction(*cx, that, func, args, &ret))
throw jserror(jserror::pending);
return ret;
}
ircd::js::value
ircd::js::call(const object &obj,
const std::string &name,
const vector<value>::handle &args)
{
return call(obj, name.c_str(), args);
}
///////////////////////////////////////////////////////////////////////////////
//
// ircd/js/del.h