mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd::js: Add bytecodes support to Object.
This commit is contained in:
parent
4c6e182241
commit
66c28da325
1 changed files with 30 additions and 0 deletions
|
@ -47,6 +47,7 @@ bool is_array(const object_handle &);
|
|||
uint32_t size(const object_handle &);
|
||||
bool deep_freeze(const object_handle &);
|
||||
bool freeze(const object_handle &);
|
||||
size_t bytecodes(const object_handle &, uint8_t *const &buf, const size_t &size);
|
||||
|
||||
namespace basic {
|
||||
|
||||
|
@ -80,6 +81,7 @@ struct object
|
|||
object(const JSClass *const &, const object &proto);
|
||||
object(const JSClass *const &);
|
||||
|
||||
object(const uint8_t *const &bytecode, const size_t &size);
|
||||
template<class T, lifetime LL> object(const root<T, LL> &);
|
||||
using root<JSObject *, L>::root;
|
||||
template<class... args> object(json_t, args&&...);
|
||||
|
@ -249,6 +251,18 @@ object<L>::object(const JSClass *const &clasp,
|
|||
throw internal_error("NULL object (new)");
|
||||
}
|
||||
|
||||
template<lifetime L>
|
||||
object<L>::object(const uint8_t *const &bytecode,
|
||||
const size_t &size)
|
||||
:object<L>::root::type
|
||||
{
|
||||
JS_DecodeInterpretedFunction(*cx, bytecode, size)
|
||||
}
|
||||
{
|
||||
if(unlikely(!this->get()))
|
||||
throw jserror(jserror::pending);
|
||||
}
|
||||
|
||||
template<lifetime L>
|
||||
object<L>
|
||||
object<L>::global()
|
||||
|
@ -318,6 +332,22 @@ const
|
|||
|
||||
} // namespace basic
|
||||
|
||||
inline size_t
|
||||
bytecodes(const object_handle &obj,
|
||||
uint8_t *const &buf,
|
||||
const size_t &size)
|
||||
{
|
||||
uint32_t ret;
|
||||
const custom_ptr<void> ptr
|
||||
{
|
||||
JS_EncodeInterpretedFunction(*cx, obj, &ret), js_free
|
||||
};
|
||||
|
||||
const auto cpsz(std::min(size_t(ret), size));
|
||||
memcpy(buf, ptr.get(), cpsz);
|
||||
return cpsz;
|
||||
}
|
||||
|
||||
inline bool
|
||||
freeze(const object_handle &obj)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue