0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd::js: Add a branch in trap::function handler for constructors.

This commit is contained in:
Jason Volk 2016-11-25 22:53:31 -08:00
parent a149d56afa
commit 7fd111487d
2 changed files with 35 additions and 11 deletions

View file

@ -37,6 +37,7 @@ struct trap::function
protected:
virtual value on_call(object::handle callee, value::handle that, const args &);
virtual value on_new(object::handle callee, const args &);
private:
static function &from(JSObject *const &);

View file

@ -688,19 +688,34 @@ noexcept try
const struct args args(argc, argv);
const object func(args.callee());
const value that(args.computeThis(c));
auto &trap(from(func));
log.debug("trap(%p) this(%p) %s() call argv[%u]",
(const void *)&trap,
(const void *)that.address(),
trap.name.c_str(),
argc);
if(args.isConstructing())
{
log.debug("trap(%p) %s() ctor argv[%u]",
(const void *)&trap,
trap.name.c_str(),
argc);
args.rval().set(trap.on_call(func, that, args));
log.debug("trap(%p) this(%p) %s() leave",
(const void *)&trap,
(const void *)that.address(),
trap.name.c_str());
const value that(trap.on_new(func, args));
args.rval().set(that);
log.debug("trap(%p) this(%p) %s() leave",
(const void *)&trap,
(const void *)that.address(),
trap.name.c_str());
} else {
const value that(args.computeThis(c));
log.debug("trap(%p) this(%p) %s() call argv[%u]",
(const void *)&trap,
(const void *)that.address(),
trap.name.c_str(),
argc);
args.rval().set(trap.on_call(func, that, args));
log.debug("trap(%p) this(%p) %s() leave",
(const void *)&trap,
(const void *)that.address(),
trap.name.c_str());
}
return true;
}
@ -742,6 +757,14 @@ ircd::js::trap::function::on_call(object::handle obj,
return lambda(obj, val, args);
}
ircd::js::value
ircd::js::trap::function::on_new(object::handle obj,
const args &args)
{
value ud;
return on_call(obj, ud, args);
}
///////////////////////////////////////////////////////////////////////////////
//
// ircd/js/trap.h