From 56d8e429a2b4d7bc6a18f57f1db6656f596af9a4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 26 Oct 2016 10:34:58 -0700 Subject: [PATCH] ircd::js: Add pointer_value() to store external host pointers in JS::Value. --- include/ircd/js/value.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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