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

ircd::js: Functions to get current zone; debug callbacks for zone; etc.

This commit is contained in:
Jason Volk 2016-10-30 05:51:22 -07:00
parent c70ddd5a80
commit 12c1755899
3 changed files with 55 additions and 13 deletions

View file

@ -117,6 +117,8 @@ JSCompartment *current_compartment(context &);
JSCompartment *current_compartment();
JSObject *current_global(context &c);
JSObject *current_global(); // thread_local
JS::Zone *current_zone(context &);
JS::Zone *current_zone();
// Memory
void set(context &c, const JSGCParamKey &, const uint32_t &val);
@ -183,6 +185,18 @@ pending_exception(const context &c)
return JS_IsExceptionPending(c);
}
inline JS::Zone *
current_zone()
{
return current_zone(*cx);
}
inline JS::Zone *
current_zone(context &c)
{
return ::js::GetContextZone(c);
}
inline JSObject *
current_global()
{
@ -195,6 +209,18 @@ current_global(context &c)
return JS::CurrentGlobalOrNull(c);
}
inline JSCompartment *
current_compartment()
{
return current_compartment(*cx);
}
inline JSCompartment *
current_compartment(context &c)
{
return ::js::GetContextCompartment(c);
}
inline void
priv(context &c,
privdata *const &ptr)

View file

@ -34,6 +34,8 @@ class runtime
static void handle_gc(JSRuntime *, JSGCStatus, void *) noexcept;
static void handle_finalize(JSFreeOp *, JSFinalizeStatus, bool is_compartment, void *) noexcept;
static void handle_telemetry(int id, uint32_t sample, const char *key) noexcept;
static void handle_zone_sweep(JS::Zone *) noexcept;
static void handle_zone_destroy(JS::Zone *) noexcept;
static void handle_compartment_name(JSRuntime *, JSCompartment *, char *buf, size_t) noexcept;
static void handle_compartment_destroy(JSFreeOp *, JSCompartment *) noexcept;
static bool handle_context(JSContext *, uint op, void *) noexcept;

View file

@ -2216,18 +2216,6 @@ ircd::js::set(context &c,
JS_SetGCParameter(c.runtime(), key, val);
}
JSCompartment *
ircd::js::current_compartment()
{
return current_compartment(*cx);
}
JSCompartment *
ircd::js::current_compartment(context &c)
{
return ::js::GetContextCompartment(c);
}
///////////////////////////////////////////////////////////////////////////////
//
// ircd/js/timer.h
@ -2410,6 +2398,8 @@ ircd::js::runtime::runtime(const struct opts &opts,
JS_SetGCCallback(get(), handle_gc, nullptr);
JS_AddFinalizeCallback(get(), handle_finalize, nullptr);
JS_SetAccumulateTelemetryCallback(get(), handle_telemetry);
JS_SetSweepZoneCallback(get(), handle_zone_sweep);
JS_SetDestroyZoneCallback(get(), handle_zone_destroy);
JS_SetCompartmentNameCallback(get(), handle_compartment_name);
JS_SetDestroyCompartmentCallback(get(), handle_compartment_destroy);
JS_SetContextCallback(get(), handle_context, nullptr);
@ -2504,9 +2494,11 @@ ircd::js::runtime::handle_compartment_destroy(JSFreeOp *const fop,
JSCompartment *const compartment)
noexcept
{
log.debug("runtime(%p): compartment(%p) destroy: fop(%p)",
log.debug("runtime(%p): compartment: %p %s%sdestroy: fop(%p)",
(const void *)(our_runtime(*fop).ptr()),
(const void *)compartment,
::js::IsSystemCompartment(compartment)? "[system] " : "",
::js::IsAtomsCompartment(compartment)? "[atoms] " : "",
(const void *)fop);
}
@ -2524,6 +2516,28 @@ noexcept
max);
}
void
ircd::js::runtime::handle_zone_destroy(JS::Zone *const zone)
noexcept
{
log.debug("runtime(%p): zone: %p %s%sdestroy",
(const void *)rt,
(const void *)zone,
::js::IsSystemZone(zone)? "[system] " : "",
::js::IsAtomsZone(zone)? "[atoms] " : "");
}
void
ircd::js::runtime::handle_zone_sweep(JS::Zone *const zone)
noexcept
{
log.debug("runtime(%p): zone: %p %s%ssweep",
(const void *)rt,
(const void *)zone,
::js::IsSystemZone(zone)? "[system] " : "",
::js::IsAtomsZone(zone)? "[atoms] " : "");
}
void
ircd::js::runtime::handle_telemetry(const int id,
const uint32_t sample,