[gjs] Export prototype in GJS_DEFINE_PROTO
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Export prototype in GJS_DEFINE_PROTO
- Date: Sat, 8 Apr 2017 19:25:39 +0000 (UTC)
commit 3141fc0637b70414c78de997d7d78e866e02e4f6
Author: Johan Dahlin <johan gnome org>
Date: Tue Mar 30 19:59:59 2010 -0300
Export prototype in GJS_DEFINE_PROTO
When creating a new prototype using the GJS_DEFINE_PROTO macros,
save a static reference to the JSObject* representing the created
prototype. Previously only a reference to the JSClass structure was
saved, which is basically just a vtable without any actual state.
This is necessary to be able to create new instances of that prototype
without calling the provided constructor.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
gjs/jsapi-util.h | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 912db24..9592044 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -203,6 +203,7 @@ _GJS_DEFINE_PROTO_FULL(tn, cn, NULL, gtype, flags)
extern JSPropertySpec gjs_##cname##_proto_props[]; \
extern JSFunctionSpec gjs_##cname##_proto_funcs[]; \
static void gjs_##cname##_finalize(JSFreeOp *fop, JSObject *obj); \
+static JS::PersistentRootedObject gjs_##cname##_prototype; \
static struct JSClass gjs_##cname##_class = { \
type_name, \
JSCLASS_HAS_PRIVATE | jsclass_flags, \
@@ -233,12 +234,13 @@ gjs_##cname##_create_proto(JSContext *context, \
return JS::NullValue(); \
return rval; \
} \
- JS::RootedObject prototype(context, \
+ gjs_##cname##_prototype.init(context); \
+ gjs_##cname##_prototype = \
JS_InitClass(context, global, parent, &gjs_##cname##_class, ctor, \
0, &gjs_##cname##_proto_props[0], \
&gjs_##cname##_proto_funcs[0], \
- NULL, NULL)); \
- if (prototype == NULL) { \
+ nullptr, nullptr); \
+ if (!gjs_##cname##_prototype) { \
return JS::NullValue(); \
} \
if (!gjs_object_require_property( \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]