0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 16:30:52 +01:00

ircd::js: Get/Set object prototype.

This commit is contained in:
Jason Volk 2016-11-03 16:46:43 -07:00
parent 67d9f11fbc
commit 292b3fc8e8

View file

@ -62,6 +62,10 @@ struct object
uint32_t size() const;
void resize(const uint32_t &);
// Get/set prototype
object prototype() const;
void prototype(object::handle);
// new object
object(const JSClass *const &, const handle &ctor, const JS::HandleValueArray &args);
object(const JSClass *const &, const JS::CallArgs &args);
@ -211,6 +215,26 @@ object<L>::object(const JSClass *const &clasp,
throw internal_error("NULL object (new)");
}
template<lifetime L>
void
object<L>::prototype(object::handle obj)
{
if(!JS_SetPrototype(*cx, *this, obj))
throw internal_error("Failed to set prototype for object");
}
template<lifetime L>
object<L>
object<L>::prototype()
const
{
object ret;
if(!JS_GetPrototype(*cx, *this, &ret))
throw internal_error("Failed to get prototype for object");
return ret;
}
template<lifetime L>
void
object<L>::resize(const uint32_t &length)