mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::js: Improve trap debug formatting.
This commit is contained in:
parent
1e1b7c8ce9
commit
8d92c8a9c4
2 changed files with 49 additions and 57 deletions
|
@ -45,7 +45,8 @@ struct trap
|
||||||
static trap &from(const JSObject &);
|
static trap &from(const JSObject &);
|
||||||
static trap &from(const JS::HandleObject &);
|
static trap &from(const JS::HandleObject &);
|
||||||
|
|
||||||
void debug(const char *fmt, ...) const AFP(2, 3);
|
protected:
|
||||||
|
void debug(const void *const &that, const char *fmt, ...) const AFP(3, 4);
|
||||||
|
|
||||||
// Override these to define JS objects in C
|
// Override these to define JS objects in C
|
||||||
virtual value on_call(object::handle, value::handle, const args &);
|
virtual value on_call(object::handle, value::handle, const args &);
|
||||||
|
@ -62,7 +63,7 @@ struct trap
|
||||||
private:
|
private:
|
||||||
void add_this();
|
void add_this();
|
||||||
void del_this();
|
void del_this();
|
||||||
void host_exception(const char *fmt, ...) const AFP(2, 3);
|
void host_exception(const void *const &that, const char *fmt, ...) const AFP(3, 4);
|
||||||
|
|
||||||
// Internal callback interface
|
// Internal callback interface
|
||||||
static void handle_trace(JSTracer *, JSObject *) noexcept;
|
static void handle_trace(JSTracer *, JSObject *) noexcept;
|
||||||
|
|
101
ircd/js.cc
101
ircd/js.cc
|
@ -517,16 +517,17 @@ noexcept try
|
||||||
const value that(args.computeThis(c));
|
const value that(args.computeThis(c));
|
||||||
const object func(args.callee());
|
const object func(args.callee());
|
||||||
auto &trap(from(func));
|
auto &trap(from(func));
|
||||||
log.debug("trap(%p) \"%s()\": this(%p) call",
|
log.debug("trap(%p) this(%p) %s() call argv[%u]",
|
||||||
(const void *)&trap,
|
(const void *)&trap,
|
||||||
|
(const void *)that.address(),
|
||||||
trap.name.c_str(),
|
trap.name.c_str(),
|
||||||
(const void *)that.address());
|
argc);
|
||||||
|
|
||||||
args.rval().set(trap.on_call(func, that, args));
|
args.rval().set(trap.on_call(func, that, args));
|
||||||
log.debug("trap(%p) \"%s()\": this(%p) return",
|
log.debug("trap(%p) this(%p) %s() leave",
|
||||||
(const void *)&trap,
|
(const void *)&trap,
|
||||||
trap.name.c_str(),
|
(const void *)that.address(),
|
||||||
(const void *)that.address());
|
trap.name.c_str());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -790,9 +791,7 @@ noexcept try
|
||||||
assert(&our_runtime(*op) == rt);
|
assert(&our_runtime(*op) == rt);
|
||||||
|
|
||||||
auto &trap(from(*obj));
|
auto &trap(from(*obj));
|
||||||
trap.debug("this(%p) dtor",
|
trap.debug(obj, "dtor");
|
||||||
(const void *)obj);
|
|
||||||
|
|
||||||
trap.on_gc(obj);
|
trap.on_gc(obj);
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
|
@ -818,8 +817,7 @@ noexcept try
|
||||||
object that(args.callee());
|
object that(args.callee());
|
||||||
|
|
||||||
auto &trap(from(that));
|
auto &trap(from(that));
|
||||||
trap.debug("this(%p) ctor: '%s' argv[%zu]",
|
trap.debug(that.get(), "ctor '%s' argv[%zu]",
|
||||||
(const void *)that.get(),
|
|
||||||
trap.name().c_str(),
|
trap.name().c_str(),
|
||||||
args.size());
|
args.size());
|
||||||
|
|
||||||
|
@ -836,8 +834,9 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto ca(JS::CallArgsFromVp(argc, argv));
|
auto ca(JS::CallArgsFromVp(argc, argv));
|
||||||
auto &trap(from(object(ca.callee())));
|
object that(ca.callee());
|
||||||
trap.host_exception("ctor: %s", e.what());
|
auto &trap(from(that));
|
||||||
|
trap.host_exception(that.get(), "ctor: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,11 +856,8 @@ noexcept try
|
||||||
//auto &trap_that(from(that));
|
//auto &trap_that(from(that));
|
||||||
auto &trap_func(from(func));
|
auto &trap_func(from(func));
|
||||||
|
|
||||||
//trap_that.debug("call: '%s'", trap_func.name().c_str());
|
//trap_that.debug(that.get(), "call: '%s'", trap_func.name().c_str());
|
||||||
trap_func.debug("this(%p) call argv[%zu]",
|
trap_func.debug(func.get(), "call argv[%zu]", args.size());
|
||||||
(const void *)that.address(),
|
|
||||||
args.size());
|
|
||||||
|
|
||||||
args.rval().set(trap_func.on_call(func, that, args));
|
args.rval().set(trap_func.on_call(func, that, args));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -873,8 +869,9 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto ca(JS::CallArgsFromVp(argc, argv));
|
auto ca(JS::CallArgsFromVp(argc, argv));
|
||||||
auto &trap(from(object(ca.computeThis(c))));
|
object func(ca.callee());
|
||||||
trap.host_exception("call: %s", e.what());
|
auto &trap(from(func));
|
||||||
|
trap.host_exception(func.get(), "call: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,7 +883,7 @@ noexcept try
|
||||||
assert(&our(c) == cx);
|
assert(&our(c) == cx);
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) enu", (const void *)obj.get());
|
trap.debug(obj.get(), "enumerate");
|
||||||
trap.on_enu(obj);
|
trap.on_enu(obj);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -898,7 +895,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.host_exception("enu: %s", e.what());
|
trap.host_exception(obj.get(), "enu: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,10 +910,7 @@ noexcept try
|
||||||
assert(!pending_exception(*cx));
|
assert(!pending_exception(*cx));
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) has: '%s'",
|
trap.debug(obj.get(), "has '%s'", string(id).c_str());
|
||||||
(const void *)obj.get(),
|
|
||||||
string(id).c_str());
|
|
||||||
|
|
||||||
*resolved = trap.on_has(obj, id);
|
*resolved = trap.on_has(obj, id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -928,7 +922,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.host_exception("has: '%s': %s",
|
trap.host_exception(obj.get(), "has '%s': %s",
|
||||||
string(id).c_str(),
|
string(id).c_str(),
|
||||||
e.what());
|
e.what());
|
||||||
return false;
|
return false;
|
||||||
|
@ -945,10 +939,7 @@ noexcept try
|
||||||
assert(!pending_exception(*cx));
|
assert(!pending_exception(*cx));
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) del: '%s'",
|
trap.debug(obj.get(), "del '%s'", string(id).c_str());
|
||||||
(const void *)obj.get(),
|
|
||||||
string(id).c_str());
|
|
||||||
|
|
||||||
if(trap.on_del(obj, id))
|
if(trap.on_del(obj, id))
|
||||||
res.succeed();
|
res.succeed();
|
||||||
|
|
||||||
|
@ -979,10 +970,7 @@ noexcept try
|
||||||
assert(!pending_exception(*cx));
|
assert(!pending_exception(*cx));
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) get: '%s'",
|
trap.debug(obj.get(), "get '%s'", string(id).c_str());
|
||||||
(const void *)obj.get(),
|
|
||||||
string(id).c_str());
|
|
||||||
|
|
||||||
const value ret(trap.on_get(obj, id, val));
|
const value ret(trap.on_get(obj, id, val));
|
||||||
val.set(ret.get());
|
val.set(ret.get());
|
||||||
return true;
|
return true;
|
||||||
|
@ -995,7 +983,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.host_exception("get: '%s': %s",
|
trap.host_exception(obj.get(), "get: '%s': %s",
|
||||||
string(id).c_str(),
|
string(id).c_str(),
|
||||||
e.what());
|
e.what());
|
||||||
return false;
|
return false;
|
||||||
|
@ -1013,10 +1001,7 @@ noexcept try
|
||||||
assert(!pending_exception(*cx));
|
assert(!pending_exception(*cx));
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) set: '%s'",
|
trap.debug(obj.get(), "set '%s'", string(id).c_str());
|
||||||
(const void *)obj.get(),
|
|
||||||
string(id).c_str());
|
|
||||||
|
|
||||||
const value ret(trap.on_set(obj, id, val));
|
const value ret(trap.on_set(obj, id, val));
|
||||||
val.set(ret.get());
|
val.set(ret.get());
|
||||||
if(!val.isUndefined())
|
if(!val.isUndefined())
|
||||||
|
@ -1032,7 +1017,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.host_exception("set: '%s': %s",
|
trap.host_exception(obj.get(), "set '%s': %s",
|
||||||
string(id).c_str(),
|
string(id).c_str(),
|
||||||
e.what());
|
e.what());
|
||||||
return false;
|
return false;
|
||||||
|
@ -1049,9 +1034,11 @@ noexcept try
|
||||||
assert(!pending_exception(*cx));
|
assert(!pending_exception(*cx));
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) add: '%s'",
|
const string name(id);
|
||||||
(const void *)obj.get(),
|
trap.debug(obj.get(), "add '%s' %s @%p",
|
||||||
string(id).c_str());
|
name.c_str(),
|
||||||
|
reflect(basic::type(val)),
|
||||||
|
(const void *)val.address());
|
||||||
|
|
||||||
trap.on_add(obj, id, val);
|
trap.on_add(obj, id, val);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1064,7 +1051,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.host_exception("add: '%s': %s",
|
trap.host_exception(obj.get(), "add '%s': %s",
|
||||||
string(id).c_str(),
|
string(id).c_str(),
|
||||||
e.what());
|
e.what());
|
||||||
return false;
|
return false;
|
||||||
|
@ -1080,8 +1067,7 @@ noexcept try
|
||||||
assert(&our(c) == cx);
|
assert(&our(c) == cx);
|
||||||
|
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.debug("this(%p) inst", (const void *)obj.get());
|
trap.debug(obj.get(), "inst");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch(const jserror &e)
|
catch(const jserror &e)
|
||||||
|
@ -1092,7 +1078,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(obj));
|
auto &trap(from(obj));
|
||||||
trap.host_exception("inst: %s", e.what());
|
trap.host_exception(obj.get(), "inst: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,7 +1092,7 @@ noexcept try
|
||||||
assert(obj);
|
assert(obj);
|
||||||
|
|
||||||
auto &trap(from(*obj));
|
auto &trap(from(*obj));
|
||||||
trap.debug("trace object(%p)", (const void *)obj);
|
trap.debug(obj, "trace");
|
||||||
trap.on_trace(obj);
|
trap.on_trace(obj);
|
||||||
}
|
}
|
||||||
catch(const jserror &e)
|
catch(const jserror &e)
|
||||||
|
@ -1117,7 +1103,7 @@ catch(const jserror &e)
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
auto &trap(from(*obj));
|
auto &trap(from(*obj));
|
||||||
trap.host_exception("trace: %s", e.what());
|
trap.host_exception(obj, "trace: %s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1147,7 +1133,8 @@ ircd::js::trap::from(const JSObject &o)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::js::trap::debug(const char *const fmt,
|
ircd::js::trap::debug(const void *const &that,
|
||||||
|
const char *const fmt,
|
||||||
...)
|
...)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -1156,16 +1143,18 @@ const
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
log.debug("trap(%p) \"%s\": %s",
|
log.debug("trap(%p) this(%p) %s %s",
|
||||||
reinterpret_cast<const void *>(this),
|
reinterpret_cast<const void *>(this),
|
||||||
name().c_str(),
|
that,
|
||||||
|
!name().empty()? name().c_str() : "this",
|
||||||
buf);
|
buf);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::js::trap::host_exception(const char *const fmt,
|
ircd::js::trap::host_exception(const void *const &that,
|
||||||
|
const char *const fmt,
|
||||||
...)
|
...)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -1174,13 +1163,15 @@ const
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
log.error("trap(%p) \"%s\": %s",
|
log.error("trap(%p) this(%p) \"%s\" %s",
|
||||||
reinterpret_cast<const void *>(this),
|
reinterpret_cast<const void *>(this),
|
||||||
|
that,
|
||||||
name().c_str(),
|
name().c_str(),
|
||||||
buf);
|
buf);
|
||||||
|
|
||||||
JS_ReportError(*cx, "BUG: trap(%p) \"%s\" %s",
|
JS_ReportError(*cx, "BUG: trap(%p) this(%p) \"%s\" %s",
|
||||||
reinterpret_cast<const void *>(this),
|
reinterpret_cast<const void *>(this),
|
||||||
|
that,
|
||||||
name().c_str(),
|
name().c_str(),
|
||||||
buf);
|
buf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue