[gjs/wip/ptomato/mozjs52: 24/35] js: New JSClass struct layout
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs52: 24/35] js: New JSClass struct layout
- Date: Sun, 11 Jun 2017 03:14:13 +0000 (UTC)
commit 4677ca3e1e3caa6cf7565b47b3c7e04d048e4aa6
Author: Philip Chimento <philip chimento gmail com>
Date: Mon May 1 22:44:34 2017 -0700
js: New JSClass struct layout
Instead of the various operation hooks being members of JSClass directly,
now JSClass contains a pointer to a JSClassOps struct. The JSClassOps
instead contains the function pointers to the operation hooks.
For importer.cpp, we still use the internal js::Class instead of JSClass.
This also contains a pointer to another struct, JSObjectOps, which we still
need for our internal lazy enumerate hook.
gi/boxed.cpp | 21 ++++++++++--------
gi/function.cpp | 11 ++++++---
gi/fundamental.cpp | 15 ++++++-------
gi/gerror.cpp | 11 ++++++---
gi/interface.cpp | 11 ++++++---
gi/ns.cpp | 10 ++++++--
gi/object.cpp | 11 ++++++---
gi/param.cpp | 11 ++++++---
gi/repo.cpp | 10 ++++++--
gi/union.cpp | 10 ++++++--
gjs/byteArray.cpp | 11 ++++++---
gjs/coverage.cpp | 10 ++++++--
gjs/importer.cpp | 49 ++++++++++++++++++++++---------------------
gjs/jsapi-class.h | 9 +++++--
gjs/jsapi-dynamic-class.cpp | 4 +-
gjs/jsapi-util.cpp | 10 ++++++--
test/gjs-test-rooting.cpp | 10 ++++++--
17 files changed, 136 insertions(+), 88 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 361165c..b31920f 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -913,16 +913,8 @@ boxed_trace(JSTracer *tracer,
/* The bizarre thing about this vtable is that it applies to both
* instances of the object, and to the prototype that instances of the
* class have.
- *
- * We allocate 1 reserved slot; this is typically unused, but if the
- * boxed is for a nested structure inside a parent structure, the
- * reserved slot is used to hold onto the parent Javascript object and
- * make sure it doesn't get freed.
*/
-struct JSClass gjs_boxed_class = {
- "GObject_Boxed",
- JSCLASS_HAS_PRIVATE |
- JSCLASS_HAS_RESERVED_SLOTS(1),
+static const struct JSClassOps gjs_boxed_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -937,6 +929,17 @@ struct JSClass gjs_boxed_class = {
boxed_trace
};
+/* We allocate 1 reserved slot; this is typically unused, but if the
+ * boxed is for a nested structure inside a parent structure, the
+ * reserved slot is used to hold onto the parent Javascript object and
+ * make sure it doesn't get freed.
+ */
+struct JSClass gjs_boxed_class = {
+ "GObject_Boxed",
+ JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(1),
+ &gjs_boxed_class_ops
+};
+
JSPropertySpec gjs_boxed_proto_props[] = {
JS_PS_END
};
diff --git a/gi/function.cpp b/gi/function.cpp
index 074904d..70306cd 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1483,10 +1483,7 @@ function_to_string (JSContext *context,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-struct JSClass gjs_function_class = {
- "GIRepositoryFunction", /* means "new GIRepositoryFunction()" works */
- JSCLASS_HAS_PRIVATE |
- JSCLASS_BACKGROUND_FINALIZE,
+static const struct JSClassOps gjs_function_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -1498,6 +1495,12 @@ struct JSClass gjs_function_class = {
function_call
};
+struct JSClass gjs_function_class = {
+ "GIRepositoryFunction", /* means "new GIRepositoryFunction()" works */
+ JSCLASS_HAS_PRIVATE | JSCLASS_BACKGROUND_FINALIZE,
+ &gjs_function_class_ops
+};
+
static JSPropertySpec gjs_function_proto_props[] = {
JS_PSG("length", get_num_arguments, JSPROP_PERMANENT),
JS_PS_END
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index dcacd1b..96a7fc5 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -543,15 +543,8 @@ fundamental_trace(JSTracer *tracer,
* tell, it would only be used if no constructor were provided to
* JS_InitClass. The constructor from JS_InitClass is not applied to
* the prototype unless JSCLASS_CONSTRUCT_PROTOTYPE is in flags.
- *
- * We allocate 1 reserved slot; this is typically unused, but if the
- * fundamental is for a nested structure inside a parent structure, the
- * reserved slot is used to hold onto the parent Javascript object and
- * make sure it doesn't get freed.
*/
-struct JSClass gjs_fundamental_instance_class = {
- "GFundamental_Object",
- JSCLASS_HAS_PRIVATE,
+static const struct JSClassOps gjs_fundamental_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -566,6 +559,12 @@ struct JSClass gjs_fundamental_instance_class = {
fundamental_trace
};
+struct JSClass gjs_fundamental_instance_class = {
+ "GFundamental_Object",
+ JSCLASS_HAS_PRIVATE,
+ &gjs_fundamental_class_ops
+};
+
static JSPropertySpec gjs_fundamental_instance_proto_props[] = {
JS_PS_END
};
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 00cc3cf..d6111f3 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -269,10 +269,7 @@ error_constructor_value_of(JSContext *context,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-struct JSClass gjs_error_class = {
- "GLib_Error",
- JSCLASS_HAS_PRIVATE |
- JSCLASS_BACKGROUND_FINALIZE,
+static const struct JSClassOps gjs_error_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -283,6 +280,12 @@ struct JSClass gjs_error_class = {
error_finalize
};
+struct JSClass gjs_error_class = {
+ "GLib_Error",
+ JSCLASS_HAS_PRIVATE | JSCLASS_BACKGROUND_FINALIZE,
+ &gjs_error_class_ops
+};
+
/* We need to shadow all fields of GError, to prevent calling the getter from GBoxed
(which would trash memory accessing the instance private data) */
JSPropertySpec gjs_error_proto_props[] = {
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 40a4209..361f5bc 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -157,10 +157,7 @@ interface_resolve(JSContext *context,
return true;
}
-struct JSClass gjs_interface_class = {
- "GObject_Interface",
- JSCLASS_HAS_PRIVATE |
- JSCLASS_BACKGROUND_FINALIZE,
+static const struct JSClassOps gjs_interface_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -171,6 +168,12 @@ struct JSClass gjs_interface_class = {
interface_finalize
};
+struct JSClass gjs_interface_class = {
+ "GObject_Interface",
+ JSCLASS_HAS_PRIVATE | JSCLASS_BACKGROUND_FINALIZE,
+ &gjs_interface_class_ops
+};
+
JSPropertySpec gjs_interface_proto_props[] = {
JS_PS_END
};
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 6c7b756..5fc9ca0 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -151,9 +151,7 @@ ns_finalize(JSFreeOp *fop,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-struct JSClass gjs_ns_class = {
- "GIRepositoryNamespace",
- JSCLASS_HAS_PRIVATE,
+static const struct JSClassOps gjs_ns_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -164,6 +162,12 @@ struct JSClass gjs_ns_class = {
ns_finalize
};
+struct JSClass gjs_ns_class = {
+ "GIRepositoryNamespace",
+ JSCLASS_HAS_PRIVATE,
+ &gjs_ns_class_ops
+};
+
static JSPropertySpec gjs_ns_proto_props[] = {
JS_PSG("__name__", get_name, GJS_MODULE_PROP_FLAGS),
JS_PS_END
diff --git a/gi/object.cpp b/gi/object.cpp
index 1cf8e61..ae414d7 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1774,9 +1774,7 @@ to_string_func(JSContext *context,
priv->gobj, rec.rval());
}
-struct JSClass gjs_object_instance_class = {
- "GObject_Object",
- JSCLASS_HAS_PRIVATE,
+static const struct JSClassOps gjs_object_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
object_instance_get_prop,
@@ -1789,7 +1787,12 @@ struct JSClass gjs_object_instance_class = {
NULL,
NULL,
object_instance_trace,
-
+};
+
+struct JSClass gjs_object_instance_class = {
+ "GObject_Object",
+ JSCLASS_HAS_PRIVATE,
+ &gjs_object_class_ops
};
static bool
diff --git a/gi/param.cpp b/gi/param.cpp
index 1693858..2806d2a 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -142,10 +142,7 @@ param_finalize(JSFreeOp *fop,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-struct JSClass gjs_param_class = {
- "GObject_ParamSpec",
- JSCLASS_HAS_PRIVATE |
- JSCLASS_BACKGROUND_FINALIZE,
+static const struct JSClassOps gjs_param_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -156,6 +153,12 @@ struct JSClass gjs_param_class = {
param_finalize
};
+struct JSClass gjs_param_class = {
+ "GObject_ParamSpec",
+ JSCLASS_HAS_PRIVATE | JSCLASS_BACKGROUND_FINALIZE,
+ &gjs_param_class_ops
+};
+
JSPropertySpec gjs_param_proto_props[] = {
JS_PS_END
};
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 97e7a25..0406ce4 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -221,9 +221,7 @@ repo_finalize(JSFreeOp *fop,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-struct JSClass gjs_repo_class = {
- "GIRepository", /* means "new GIRepository()" works */
- JSCLASS_HAS_PRIVATE,
+static const struct JSClassOps gjs_repo_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -234,6 +232,12 @@ struct JSClass gjs_repo_class = {
repo_finalize
};
+struct JSClass gjs_repo_class = {
+ "GIRepository", /* means "new GIRepository()" works */
+ JSCLASS_HAS_PRIVATE,
+ &gjs_repo_class_ops,
+};
+
static JSPropertySpec *gjs_repo_proto_props = nullptr;
static JSFunctionSpec *gjs_repo_proto_funcs = nullptr;
static JSFunctionSpec *gjs_repo_static_funcs = nullptr;
diff --git a/gi/union.cpp b/gi/union.cpp
index f358524..aa54a1f 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -287,9 +287,7 @@ to_string_func(JSContext *context,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-struct JSClass gjs_union_class = {
- "GObject_Union",
- JSCLASS_HAS_PRIVATE,
+static const struct JSClassOps gjs_union_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -300,6 +298,12 @@ struct JSClass gjs_union_class = {
union_finalize
};
+struct JSClass gjs_union_class = {
+ "GObject_Union",
+ JSCLASS_HAS_PRIVATE,
+ &gjs_union_class_ops
+};
+
JSPropertySpec gjs_union_proto_props[] = {
JS_PS_END
};
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 1fbd787..88b38e2 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -55,10 +55,7 @@ static void byte_array_finalize (JSFreeOp *fop,
static JSObject *gjs_byte_array_get_proto(JSContext *);
-struct JSClass gjs_byte_array_class = {
- "ByteArray",
- JSCLASS_HAS_PRIVATE |
- JSCLASS_BACKGROUND_FINALIZE,
+static const struct JSClassOps gjs_byte_array_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
byte_array_get_prop,
@@ -69,6 +66,12 @@ struct JSClass gjs_byte_array_class = {
byte_array_finalize
};
+struct JSClass gjs_byte_array_class = {
+ "ByteArray",
+ JSCLASS_HAS_PRIVATE | JSCLASS_BACKGROUND_FINALIZE,
+ &gjs_byte_array_class_ops
+};
+
bool
gjs_typecheck_bytearray(JSContext *context,
JS::HandleObject object,
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index 0f88f51..4845b15 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -1261,9 +1261,7 @@ gjs_coverage_init(GjsCoverage *self)
{
}
-static JSClass coverage_global_class = {
- "GjsCoverageGlobal",
- JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
+static const struct JSClassOps gjs_coverage_global_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -1278,6 +1276,12 @@ static JSClass coverage_global_class = {
JS_GlobalObjectTraceHook
};
+static JSClass coverage_global_class = {
+ "GjsCoverageGlobal",
+ JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
+ &gjs_coverage_global_class_ops
+};
+
static bool
gjs_context_eval_file_in_compartment(GjsContext *context,
const char *filename,
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index a1e7b07..2904211 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -848,9 +848,7 @@ importer_finalize(js::FreeOp *fop,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-const js::Class gjs_importer_real_class = {
- "GjsFileImporter",
- JSCLASS_HAS_PRIVATE,
+static const js::ClassOps gjs_importer_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -858,27 +856,30 @@ const js::Class gjs_importer_real_class = {
NULL, /* enumerate (see below) */
importer_resolve,
nullptr, /* mayResolve */
- importer_finalize,
- NULL, /* call */
- NULL, /* hasInstance */
- NULL, /* construct */
- NULL, /* trace */
- JS_NULL_CLASS_SPEC,
- JS_NULL_CLASS_EXT,
- {
- NULL, /* lookupProperty */
- NULL, /* defineProperty */
- NULL, /* hasProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* getOwnPropertyDescriptor */
- NULL, /* deleteProperty */
- NULL, /* watch */
- NULL, /* unwatch */
- NULL, /* getElements */
- importer_enumerate,
- NULL, /* thisObject */
- }
+ importer_finalize
+};
+
+static const js::ObjectOps gjs_importer_object_ops = {
+ NULL, /* lookupProperty */
+ NULL, /* defineProperty */
+ NULL, /* hasProperty */
+ NULL, /* getProperty */
+ NULL, /* setProperty */
+ NULL, /* getOwnPropertyDescriptor */
+ NULL, /* deleteProperty */
+ NULL, /* watch */
+ NULL, /* unwatch */
+ NULL, /* getElements */
+ importer_enumerate
+};
+
+const js::Class gjs_importer_real_class = {
+ "GjsFileImporter",
+ JSCLASS_HAS_PRIVATE,
+ &gjs_importer_class_ops,
+ nullptr,
+ nullptr,
+ &gjs_importer_object_ops
};
static JSPropertySpec *gjs_importer_proto_props = nullptr;
diff --git a/gjs/jsapi-class.h b/gjs/jsapi-class.h
index 47696e0..729b790 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -170,9 +170,7 @@ extern JSPropertySpec gjs_##cname##_proto_props[]; \
extern JSFunctionSpec gjs_##cname##_proto_funcs[]; \
extern JSFunctionSpec gjs_##cname##_static_funcs[]; \
static void gjs_##cname##_finalize(JSFreeOp *fop, JSObject *obj); \
-static struct JSClass gjs_##cname##_class = { \
- type_name, \
- JSCLASS_HAS_PRIVATE | jsclass_flags, \
+static const struct JSClassOps gjs_##cname##_class_ops = { \
nullptr, /* addProperty */ \
nullptr, /* deleteProperty */ \
nullptr, /* getProperty */ \
@@ -182,6 +180,11 @@ static struct JSClass gjs_##cname##_class = { \
nullptr, /* mayResolve */ \
gjs_##cname##_finalize \
}; \
+static struct JSClass gjs_##cname##_class = { \
+ type_name, \
+ JSCLASS_HAS_PRIVATE | jsclass_flags, \
+ &gjs_##cname##_class_ops \
+}; \
_GJS_DEFINE_GET_PROTO(cname) \
_GJS_DEFINE_DEFINE_PROTO(cname, parent_cname, ctor, gtype)
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index d0e947b..a660c19 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -88,7 +88,7 @@ gjs_init_class_dynamic(JSContext *context,
goto out;
/* Bypass resolve hooks when defining the initial properties */
- if (clasp->resolve) {
+ if (clasp->cOps->resolve) {
JSPropertySpec *ps_iter;
JSFunctionSpec *fs_iter;
for (ps_iter = proto_ps; ps_iter && ps_iter->name; ps_iter++)
@@ -115,7 +115,7 @@ gjs_init_class_dynamic(JSContext *context,
if (static_fs && !JS_DefineFunctions(context, constructor, static_fs))
goto out;
- if (!clasp->resolve) {
+ if (!clasp->cOps->resolve) {
if (!JS_LinkConstructorAndPrototype(context, constructor, prototype))
goto out;
} else {
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 9106afb..568318b 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -45,9 +45,7 @@ gjs_util_error_quark (void)
return g_quark_from_static_string ("gjs-util-error-quark");
}
-static JSClass global_class = {
- "GjsGlobal",
- JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
+static const JSClassOps global_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -62,6 +60,12 @@ static JSClass global_class = {
JS_GlobalObjectTraceHook
};
+static JSClass global_class = {
+ "GjsGlobal",
+ JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
+ &global_class_ops
+};
+
/**
* gjs_init_context_standard:
* @context: a #JSContext
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index 99bb0bc..3b90b52 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -24,9 +24,7 @@ test_obj_finalize(JSFreeOp *fop,
*finalized_p = true;
}
-static JSClass test_obj_class = {
- "TestObj",
- JSCLASS_HAS_PRIVATE,
+static const JSClassOps test_obj_class_ops = {
NULL, /* addProperty */
NULL, /* deleteProperty */
NULL, /* getProperty */
@@ -37,6 +35,12 @@ static JSClass test_obj_class = {
test_obj_finalize
};
+static JSClass test_obj_class = {
+ "TestObj",
+ JSCLASS_HAS_PRIVATE,
+ &test_obj_class_ops
+};
+
static JSObject *
test_obj_new(GjsRootingFixture *fx)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]