0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

ircd::js: Add pointer_value() to store external host pointers in JS::Value.

This commit is contained in:
Jason Volk 2016-10-26 10:34:58 -07:00
parent 21e96eaedf
commit 56d8e429a2

View file

@ -25,6 +25,11 @@
namespace ircd {
namespace js {
// Use Value to carry a non-gc host pointer value
template<class T> T *pointer_value(const JS::Value &);
JS::Value pointer_value(const void *const &);
JS::Value pointer_value(void *const &);
struct value
:JS::Rooted<JS::Value>
{
@ -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<void *>(ptr));
}
inline JS::Value
pointer_value(void *const &ptr)
{
JS::Value ret;
ret.setPrivate(ptr);
return ret;
}
template<class T>
T *
pointer_value(const JS::Value &val)
{
const auto ret(val.toPrivate());
return reinterpret_cast<T *>(ret);
}
} // namespace js
} // namespace ircd