mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::js: Improve trap callback arguments; add this
value.
This commit is contained in:
parent
292b3fc8e8
commit
b8f5366f52
4 changed files with 18 additions and 15 deletions
|
@ -36,15 +36,15 @@ class trap
|
|||
std::map<persist_string, trap *, persist_string::less> children;
|
||||
|
||||
// Override these to define JS objects in C
|
||||
virtual value on_call(object::handle, const args &);
|
||||
virtual value on_call(object::handle, object::handle, const args &);
|
||||
virtual value on_set(object::handle, id::handle, value::handle);
|
||||
virtual value on_get(object::handle, id::handle, value::handle);
|
||||
virtual void on_add(object::handle, id::handle, value::handle);
|
||||
virtual bool on_del(object::handle, id::handle);
|
||||
virtual bool on_has(object::handle, id::handle);
|
||||
virtual void on_enu(object::handle);
|
||||
virtual void on_ctor(object &, const args &);
|
||||
virtual void on_dtor(JSObject &);
|
||||
virtual void on_new(object::handle, object &, const args &);
|
||||
virtual void on_gc(JSObject &);
|
||||
|
||||
private:
|
||||
void host_exception(const char *fmt, ...) const AFP(2, 3);
|
||||
|
|
|
@ -32,7 +32,7 @@ struct trap_function
|
|||
uint flags;
|
||||
|
||||
protected:
|
||||
virtual value on_call(object::handle, const args &);
|
||||
virtual value on_call(object::handle callee, value::handle that, const args &);
|
||||
|
||||
private:
|
||||
static trap_function &from(JSObject *const &);
|
||||
|
|
19
ircd/js.cc
19
ircd/js.cc
|
@ -427,14 +427,14 @@ noexcept try
|
|||
assert(&our(c) == cx);
|
||||
|
||||
const struct args args(argc, argv);
|
||||
//const auto that(args.computeThis(c));
|
||||
const value that(args.computeThis(c));
|
||||
const object func(args.callee());
|
||||
auto &trap(from(func));
|
||||
log.debug("trap_function(%p) \"%s\": call",
|
||||
(const void *)&trap,
|
||||
trap.name.c_str());
|
||||
|
||||
args.rval().set(trap.on_call(func, args));
|
||||
args.rval().set(trap.on_call(func, that, args));
|
||||
return true;
|
||||
}
|
||||
catch(const jserror &e)
|
||||
|
@ -469,6 +469,7 @@ ircd::js::trap_function::from(JSObject *const &func)
|
|||
|
||||
ircd::js::value
|
||||
ircd::js::trap_function::on_call(object::handle,
|
||||
value::handle,
|
||||
const args &)
|
||||
{
|
||||
return {};
|
||||
|
@ -676,7 +677,7 @@ noexcept try
|
|||
|
||||
auto &trap(from(*obj));
|
||||
trap.debug("dtor %p", (const void *)obj);
|
||||
trap.on_dtor(*obj);
|
||||
trap.on_gc(*obj);
|
||||
}
|
||||
catch(const jserror &e)
|
||||
{
|
||||
|
@ -706,7 +707,7 @@ noexcept try
|
|||
trap.debug("ctor: '%s'", trap.name().c_str());
|
||||
|
||||
object ret(JS_NewObjectWithGivenProto(*cx, &trap.jsclass(), that));
|
||||
trap.on_ctor(ret, args);
|
||||
trap.on_new(that, ret, args);
|
||||
args.rval().set(ret);
|
||||
return true;
|
||||
}
|
||||
|
@ -742,7 +743,7 @@ noexcept try
|
|||
trap_that.debug("call: '%s'", trap_func.name().c_str());
|
||||
trap_func.debug("call");
|
||||
|
||||
args.rval().set(trap_func.on_call(func, args));
|
||||
args.rval().set(trap_func.on_call(func, that, args));
|
||||
return true;
|
||||
}
|
||||
catch(const jserror &e)
|
||||
|
@ -1048,12 +1049,13 @@ const
|
|||
}
|
||||
|
||||
void
|
||||
ircd::js::trap::on_dtor(JSObject &)
|
||||
ircd::js::trap::on_gc(JSObject &)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ircd::js::trap::on_ctor(object &obj,
|
||||
ircd::js::trap::on_new(object::handle,
|
||||
object &,
|
||||
const args &)
|
||||
{
|
||||
}
|
||||
|
@ -1067,7 +1069,7 @@ bool
|
|||
ircd::js::trap::on_has(object::handle,
|
||||
id::handle)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1108,6 +1110,7 @@ ircd::js::trap::on_set(object::handle,
|
|||
|
||||
ircd::js::value
|
||||
ircd::js::trap::on_call(object::handle,
|
||||
object::handle,
|
||||
const args &)
|
||||
{
|
||||
return {};
|
||||
|
|
|
@ -29,7 +29,7 @@ struct future
|
|||
{
|
||||
uint64_t id_ctr;
|
||||
|
||||
void on_ctor(object &, const args &args) override;
|
||||
void on_new(object::handle, object &, const args &args) override;
|
||||
|
||||
future();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ future::future()
|
|||
}
|
||||
|
||||
void
|
||||
future::on_ctor(object &obj, const args &args)
|
||||
future::on_new(object::handle, object &obj, const args &args)
|
||||
{
|
||||
auto &task(task::get());
|
||||
|
||||
|
|
Loading…
Reference in a new issue