mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 18:18:56 +02:00
ircd::js: Add basic trap debug / rename trap.res -> trap.has.
This commit is contained in:
parent
34881325bb
commit
7b5629e4a5
|
@ -35,12 +35,14 @@ class trap
|
|||
virtual bool on_set(const JSObject &, const jsid &, JS::MutableHandleValue);
|
||||
virtual bool on_get(const JSObject &, const jsid &, JS::MutableHandleValue);
|
||||
virtual bool on_del(const JSObject &, const jsid &);
|
||||
virtual bool on_res(const JSObject &, const jsid &, bool &resolved);
|
||||
virtual bool on_has(const JSObject &, const jsid &, bool &resolved);
|
||||
virtual bool on_enu(const JSObject &);
|
||||
virtual bool on_call(const unsigned &argc, JS::Value &argv);
|
||||
virtual bool on_ctor(const unsigned &argc, JS::Value &argv);
|
||||
|
||||
private:
|
||||
void debug(const char *fmt, ...) const AFP(2, 3);
|
||||
|
||||
static trap &from(const JSObject &);
|
||||
static trap &from(const JS::HandleObject &);
|
||||
|
||||
|
@ -51,7 +53,7 @@ class trap
|
|||
static bool handle_set(JSContext *, JS::HandleObject, JS::HandleId, JS::MutableHandleValue, JS::ObjectOpResult &);
|
||||
static bool handle_get(JSContext *, JS::HandleObject, JS::HandleId, JS::MutableHandleValue);
|
||||
static bool handle_del(JSContext *, JS::HandleObject, JS::HandleId, JS::ObjectOpResult &);
|
||||
static bool handle_res(JSContext *, JS::HandleObject, JS::HandleId, bool *resolved);
|
||||
static bool handle_has(JSContext *, JS::HandleObject, JS::HandleId, bool *resolved);
|
||||
static bool handle_enu(JSContext *, JS::HandleObject);
|
||||
static bool handle_call(JSContext *, unsigned argc, JS::Value *argv);
|
||||
static bool handle_ctor(JSContext *, unsigned argc, JS::Value *argv);
|
||||
|
|
38
ircd/js.cc
38
ircd/js.cc
|
@ -122,7 +122,7 @@ ircd::js::trap::trap(std::string name,
|
|||
handle_get,
|
||||
handle_set,
|
||||
handle_enu,
|
||||
handle_res,
|
||||
handle_has,
|
||||
nullptr, // JSConvertOp - Obsolete since SpiderMonkey 44 // 45 = mayResolve?
|
||||
handle_dtor,
|
||||
handle_call,
|
||||
|
@ -155,6 +155,7 @@ void
|
|||
ircd::js::trap::handle_dtor(JSFreeOp *const op,
|
||||
JSObject *const obj)
|
||||
{
|
||||
//debug("dtor");
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -163,6 +164,7 @@ ircd::js::trap::handle_ctor(JSContext *const c,
|
|||
JS::Value *const argv)
|
||||
{
|
||||
assert(&our(c) == cx);
|
||||
//debug("ctor");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -173,6 +175,7 @@ ircd::js::trap::handle_call(JSContext *const c,
|
|||
JS::Value *const argv)
|
||||
{
|
||||
assert(&our(c) == cx);
|
||||
//debug("call");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -184,11 +187,12 @@ ircd::js::trap::handle_enu(JSContext *const c,
|
|||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
trap.debug("enu");
|
||||
return trap.on_enu(*obj.get());
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::js::trap::handle_res(JSContext *const c,
|
||||
ircd::js::trap::handle_has(JSContext *const c,
|
||||
JS::HandleObject obj,
|
||||
JS::HandleId id,
|
||||
bool *const resolved)
|
||||
|
@ -196,7 +200,8 @@ ircd::js::trap::handle_res(JSContext *const c,
|
|||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
return trap.on_res(*obj.get(), id.get(), *resolved);
|
||||
trap.debug("has: %s", string(id).c_str());
|
||||
return trap.on_has(*obj.get(), id.get(), *resolved);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -208,6 +213,7 @@ ircd::js::trap::handle_del(JSContext *const c,
|
|||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
trap.debug("del: %s", string(id).c_str());
|
||||
if(!trap.on_del(*obj.get(), id.get()))
|
||||
return false;
|
||||
|
||||
|
@ -224,6 +230,7 @@ ircd::js::trap::handle_get(JSContext *const c,
|
|||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
trap.debug("get: %s", string(id).c_str());
|
||||
return trap.on_get(*obj.get(), id.get(), val);
|
||||
}
|
||||
|
||||
|
@ -237,6 +244,7 @@ ircd::js::trap::handle_set(JSContext *const c,
|
|||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
trap.debug("set: %s", string(id).c_str());
|
||||
return trap.on_get(*obj.get(), id.get(), val);
|
||||
}
|
||||
|
||||
|
@ -249,6 +257,7 @@ ircd::js::trap::handle_add(JSContext *const c,
|
|||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
trap.debug("add: %s", string(id).c_str());
|
||||
return trap.on_add(*obj.get(), id.get(), val.get());
|
||||
}
|
||||
|
||||
|
@ -260,6 +269,9 @@ ircd::js::trap::handle_inst(JSContext *const c,
|
|||
{
|
||||
assert(&our(c) == cx);
|
||||
|
||||
auto &trap(from(obj));
|
||||
trap.debug("inst");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -288,6 +300,24 @@ ircd::js::trap::from(const JSObject &o)
|
|||
return *static_cast<trap *>(c->reserved[0]); //TODO: ???
|
||||
}
|
||||
|
||||
void
|
||||
ircd::js::trap::debug(const char *const fmt,
|
||||
...)
|
||||
const
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
char buf[1024];
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
log.debug("trap(%p) \"%s\": %s",
|
||||
reinterpret_cast<const void *>(this),
|
||||
name().c_str(),
|
||||
buf);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::js::trap::on_ctor(const unsigned &argc,
|
||||
JS::Value &argv)
|
||||
|
@ -309,7 +339,7 @@ ircd::js::trap::on_enu(const JSObject &obj)
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::js::trap::on_res(const JSObject &obj,
|
||||
ircd::js::trap::on_has(const JSObject &obj,
|
||||
const jsid &id,
|
||||
bool &resolved)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue