diff --git a/include/ircd/js/trap.h b/include/ircd/js/trap.h index 0ec80d4da..cd30945d6 100644 --- a/include/ircd/js/trap.h +++ b/include/ircd/js/trap.h @@ -38,7 +38,7 @@ class trap virtual bool on_has(const JSObject &, const jsid &); virtual bool on_enu(const JSObject &); virtual value on_call(const JSObject &, const JS::CallArgs &); - virtual value on_ctor(const JS::CallArgs &); + virtual void on_ctor(object &, const JS::CallArgs &); private: void host_exception(const char *fmt, ...) const AFP(2, 3); diff --git a/ircd/js.cc b/ircd/js.cc index cde80d323..6f8dc0639 100644 --- a/ircd/js.cc +++ b/ircd/js.cc @@ -205,9 +205,17 @@ ircd::js::trap::handle_ctor(JSContext *const c, noexcept try { assert(&our(c) == cx); - //debug("ctor"); - return false; + auto ca(JS::CallArgsFromVp(argc, argv)); + object that(ca.callee()); + + auto &trap(from(that)); + trap.debug("ctor: '%s'", trap.name().c_str()); + + object ret(JS_NewObjectForConstructor(*cx, &trap.jsclass(), ca)); + trap.on_ctor(ret, ca); + ca.rval().set(ret); + return true; } catch(const jserror &e) { @@ -216,8 +224,9 @@ catch(const jserror &e) } catch(const std::exception &e) { - //auto &trap(from(obj)); - //trap.host_exception("call: %s", e.what()); + auto ca(JS::CallArgsFromVp(argc, argv)); + auto &trap(from(object(ca.callee()))); + trap.host_exception("ctor: %s", e.what()); return false; } @@ -228,9 +237,19 @@ ircd::js::trap::handle_call(JSContext *const c, noexcept try { assert(&our(c) == cx); - //debug("call"); - return false; + auto ca(JS::CallArgsFromVp(argc, argv)); + object that(ca.computeThis(c)); + object func(ca.callee()); + + auto &trap_that(from(that)); + auto &trap_func(from(func)); + + trap_that.debug("call: '%s'", trap_func.name().c_str()); + trap_func.debug("call"); + + ca.rval().set(trap_func.on_call(*func.get(), ca)); + return true; } catch(const jserror &e) { @@ -239,8 +258,9 @@ catch(const jserror &e) } catch(const std::exception &e) { - //auto &trap(from(obj)); - //trap.host_exception("call: %s", e.what()); + auto ca(JS::CallArgsFromVp(argc, argv)); + auto &trap(from(object(ca.computeThis(c)))); + trap.host_exception("call: %s", e.what()); return false; } @@ -519,18 +539,17 @@ const va_end(ap); } -bool -ircd::js::trap::on_ctor(const unsigned &argc, - JS::Value &argv) +void +ircd::js::trap::on_ctor(object &obj, + const JS::CallArgs &) { - return false; } -bool -ircd::js::trap::on_call(const unsigned &argc, - JS::Value &argv) +ircd::js::value +ircd::js::trap::on_call(const JSObject &, + const JS::CallArgs &) { - return false; + return {}; } bool