mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::js: Add a branch in trap::function handler for constructors.
This commit is contained in:
parent
a149d56afa
commit
7fd111487d
2 changed files with 35 additions and 11 deletions
|
@ -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 &);
|
||||
|
|
45
ircd/js.cc
45
ircd/js.cc
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue