diff --git a/include/ircd/js/value.h b/include/ircd/js/value.h index dd6b721ba..9a8d49a30 100644 --- a/include/ircd/js/value.h +++ b/include/ircd/js/value.h @@ -25,6 +25,11 @@ namespace ircd { namespace js { +// Use Value to carry a non-gc host pointer value +template T *pointer_value(const JS::Value &); +JS::Value pointer_value(const void *const &); +JS::Value pointer_value(void *const &); + struct value :JS::Rooted { @@ -322,5 +327,27 @@ undefined(const value &val) return type(val) == JSTYPE_VOID; } +inline JS::Value +pointer_value(const void *const &ptr) +{ + return pointer_value(const_cast(ptr)); +} + +inline JS::Value +pointer_value(void *const &ptr) +{ + JS::Value ret; + ret.setPrivate(ptr); + return ret; +} + +template +T * +pointer_value(const JS::Value &val) +{ + const auto ret(val.toPrivate()); + return reinterpret_cast(ret); +} + } // namespace js } // namespace ircd