mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd::js: Add pointer_value() to store external host pointers in JS::Value.
This commit is contained in:
parent
21e96eaedf
commit
56d8e429a2
1 changed files with 27 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue