From 292b3fc8e81be3e6e7b882f8c9ac55fc40bdbd98 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 3 Nov 2016 16:46:43 -0700 Subject: [PATCH] ircd::js: Get/Set object prototype. --- include/ircd/js/object.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/ircd/js/object.h b/include/ircd/js/object.h index b4c906a73..63da635d6 100644 --- a/include/ircd/js/object.h +++ b/include/ircd/js/object.h @@ -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::object(const JSClass *const &clasp, throw internal_error("NULL object (new)"); } +template +void +object::prototype(object::handle obj) +{ + if(!JS_SetPrototype(*cx, *this, obj)) + throw internal_error("Failed to set prototype for object"); +} + +template +object +object::prototype() +const +{ + object ret; + if(!JS_GetPrototype(*cx, *this, &ret)) + throw internal_error("Failed to get prototype for object"); + + return ret; +} + template void object::resize(const uint32_t &length)