[gjs: 5/14] js: Adapt to new JSClassOps struct layout
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 5/14] js: Adapt to new JSClassOps struct layout
- Date: Sun, 29 Jul 2018 16:54:41 +0000 (UTC)
commit e5019b79fd98d47162051f1ba3de57b4cb2943b5
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Dec 10 00:29:29 2017 -0800
js: Adapt to new JSClassOps struct layout
The getProperty and setProperty hooks are gone.
The newEnumerate hook is moved in from JSObjectOps, and so we can change
importer.cpp to use a regular old JSClass again instead of the JS Friend
API version which was required in order to use JSObjectOps.
See: #161
gi/boxed.cpp | 20 ++++++++----------
gi/function.cpp | 16 +++++++--------
gi/fundamental.cpp | 20 ++++++++----------
gi/gerror.cpp | 16 +++++++--------
gi/interface.cpp | 14 ++++++-------
gi/ns.cpp | 14 ++++++-------
gi/object.cpp | 3 +--
gi/param.cpp | 14 ++++++-------
gi/repo.cpp | 14 ++++++-------
gi/union.cpp | 14 ++++++-------
gjs/global.cpp | 24 ++++++++++------------
gjs/importer.cpp | 52 +++++++++++------------------------------------
gjs/jsapi-class.h | 46 +++++++++++++++++++++--------------------
gjs/module.cpp | 11 +++++-----
test/gjs-test-rooting.cpp | 16 +++++++--------
15 files changed, 122 insertions(+), 172 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index db30f5a2..fcc14896 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -855,19 +855,17 @@ boxed_trace(JSTracer *tracer,
* class have.
*/
static const struct JSClassOps gjs_boxed_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
boxed_resolve,
- nullptr, /* mayResolve */
+ nullptr, // mayResolve
boxed_finalize,
- NULL, /* call */
- NULL, /* hasInstance */
- NULL, /* construct */
- boxed_trace
-};
+ nullptr, // call
+ nullptr, // hasInstance
+ nullptr, // construct
+ 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
diff --git a/gi/function.cpp b/gi/function.cpp
index cbedc18b..10645c7b 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1555,16 +1555,14 @@ function_to_string (JSContext *context,
* class have.
*/
static const struct JSClassOps gjs_function_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
- NULL, /* resolve */
- nullptr, /* mayResolve */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
+ nullptr, // resolve
+ nullptr, // mayResolve
function_finalize,
- function_call
-};
+ function_call};
struct JSClass gjs_function_class = {
"GIRepositoryFunction", /* means "new GIRepositoryFunction()" works */
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index 01445f60..a5e1ce95 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -545,19 +545,17 @@ fundamental_trace(JSTracer *tracer,
* the prototype unless JSCLASS_CONSTRUCT_PROTOTYPE is in flags.
*/
static const struct JSClassOps gjs_fundamental_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
fundamental_instance_resolve,
- nullptr, /* mayResolve */
+ nullptr, // mayResolve
fundamental_finalize,
- NULL, /* call */
- NULL, /* hasInstance */
- NULL, /* construct */
- fundamental_trace
-};
+ nullptr, // call
+ nullptr, // hasInstance
+ nullptr, // construct
+ fundamental_trace};
struct JSClass gjs_fundamental_instance_class = {
"GFundamental_Object",
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index a5d2919c..3724d3aa 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -255,15 +255,13 @@ error_constructor_value_of(JSContext *context,
* class have.
*/
static const struct JSClassOps gjs_error_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
- NULL, /* resolve */
- nullptr, /* mayResolve */
- error_finalize
-};
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
+ nullptr, // resolve
+ nullptr, // mayResolve
+ error_finalize};
struct JSClass gjs_error_class = {
"GLib_Error",
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 9ce08482..88eeee63 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -187,15 +187,13 @@ interface_has_instance_func(JSContext *cx,
}
static const struct JSClassOps gjs_interface_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
interface_resolve,
- nullptr, /* mayResolve */
- interface_finalize
-};
+ nullptr, // mayResolve
+ interface_finalize};
struct JSClass gjs_interface_class = {
"GObject_Interface",
diff --git a/gi/ns.cpp b/gi/ns.cpp
index f80862f7..17d09fd2 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -155,15 +155,13 @@ ns_finalize(JSFreeOp *fop,
* class have.
*/
static const struct JSClassOps gjs_ns_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
ns_resolve,
- nullptr, /* mayResolve */
- ns_finalize
-};
+ nullptr, // mayResolve
+ ns_finalize};
struct JSClass gjs_ns_class = {
"GIRepositoryNamespace",
diff --git a/gi/object.cpp b/gi/object.cpp
index ab8d1dc9..2b2265da 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1939,9 +1939,8 @@ bool ObjectPrototype::to_string_impl(JSContext* cx, const JS::CallArgs& args) {
static const struct JSClassOps gjs_object_class_ops = {
&ObjectBase::add_property,
nullptr, // deleteProperty
- nullptr, // getProperty
- nullptr, // setProperty
nullptr, // enumerate
+ nullptr, // newEnumerate
&ObjectBase::resolve,
nullptr, // mayResolve
&ObjectBase::finalize,
diff --git a/gi/param.cpp b/gi/param.cpp
index 5cbf17cb..6a1bfaa5 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -144,15 +144,13 @@ param_finalize(JSFreeOp *fop,
* class have.
*/
static const struct JSClassOps gjs_param_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
param_resolve,
- nullptr, /* mayResolve */
- param_finalize
-};
+ nullptr, // mayResolve
+ param_finalize};
struct JSClass gjs_param_class = {
"GObject_ParamSpec",
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 378bdf51..2e67bfd7 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -222,15 +222,13 @@ repo_finalize(JSFreeOp *fop,
* class have.
*/
static const struct JSClassOps gjs_repo_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
repo_resolve,
- nullptr, /* mayResolve */
- repo_finalize
-};
+ nullptr, // mayResolve
+ repo_finalize};
struct JSClass gjs_repo_class = {
"GIRepository", /* means "new GIRepository()" works */
diff --git a/gi/union.cpp b/gi/union.cpp
index b400cc71..fd7bea20 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -286,15 +286,13 @@ to_string_func(JSContext *context,
* class have.
*/
static const struct JSClassOps gjs_union_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
union_resolve,
- nullptr, /* mayResolve */
- union_finalize
-};
+ nullptr, // mayResolve
+ union_finalize};
struct JSClass gjs_union_class = {
"GObject_Union",
diff --git a/gjs/global.cpp b/gjs/global.cpp
index 3c01f0b6..0cf6836f 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -207,19 +207,17 @@ gjs_printerr(JSContext *context,
class GjsGlobal {
static constexpr JSClassOps class_ops = {
- nullptr, /* addProperty */
- nullptr, /* deleteProperty */
- nullptr, /* getProperty */
- nullptr, /* setProperty */
- nullptr, /* enumerate */
- nullptr, /* resolve */
- nullptr, /* mayResolve */
- nullptr, /* finalize */
- nullptr, /* call */
- nullptr, /* hasInstance */
- nullptr, /* construct */
- JS_GlobalObjectTraceHook
- };
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
+ nullptr, // resolve
+ nullptr, // mayResolve
+ nullptr, // finalize
+ nullptr, // call
+ nullptr, // hasInstance
+ nullptr, // construct
+ JS_GlobalObjectTraceHook};
static constexpr JSClass klass = {
"GjsGlobal",
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 72cd2160..13dc7b15 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -56,11 +56,7 @@ typedef struct {
unsigned int index;
} ImporterIterator;
-extern const js::Class gjs_importer_real_class;
-
-/* Bizarrely, the API for safely casting const js::Class * to const JSClass *
- * is called "js::Jsvalify" */
-static const JSClass gjs_importer_class = *js::Jsvalify(&gjs_importer_real_class);
+extern const JSClass gjs_importer_class;
GJS_DEFINE_PRIV_FROM_JS(Importer, gjs_importer_class)
@@ -594,12 +590,9 @@ do_import(JSContext *context,
/* Note that in a for ... in loop, this will be called first on the object,
* then on its prototype.
*/
-static bool
-importer_enumerate(JSContext *context,
- JS::HandleObject object,
- JS::AutoIdVector& properties,
- bool enumerable_only)
-{
+static bool importer_new_enumerate(JSContext* context, JS::HandleObject object,
+ JS::AutoIdVector& properties,
+ bool enumerable_only) {
Importer *priv;
guint32 search_path_len;
guint32 i;
@@ -759,10 +752,7 @@ importer_resolve(JSContext *context,
GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(importer)
-static void
-importer_finalize(js::FreeOp *fop,
- JSObject *obj)
-{
+static void importer_finalize(JSFreeOp* fop, JSObject* obj) {
Importer *priv;
priv = (Importer*) JS_GetPrivate(obj);
@@ -779,38 +769,20 @@ importer_finalize(js::FreeOp *fop,
* instances of the object, and to the prototype that instances of the
* class have.
*/
-static const js::ClassOps gjs_importer_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate (see below) */
+static const JSClassOps gjs_importer_class_ops = {
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ importer_new_enumerate,
importer_resolve,
- nullptr, /* mayResolve */
+ nullptr, // mayResolve
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 = {
+const JSClass gjs_importer_class = {
"GjsFileImporter",
JSCLASS_HAS_PRIVATE | JSCLASS_FOREGROUND_FINALIZE,
&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 6f76704c..0473e12b 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -177,28 +177,30 @@ _GJS_DEFINE_PROTO_FULL(tn, cn, parent_cn, gjs_##cn##_constructor, \
#define GJS_DEFINE_PROTO_ABSTRACT_WITH_PARENT(tn, cn, parent_cn, flags) \
_GJS_DEFINE_PROTO_FULL(tn, cn, parent_cn, nullptr, G_TYPE_NONE, flags)
-#define _GJS_DEFINE_PROTO_FULL(type_name, cname, parent_cname, ctor, gtype, jsclass_flags) \
-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 const struct JSClassOps gjs_##cname##_class_ops = { \
- nullptr, /* addProperty */ \
- nullptr, /* deleteProperty */ \
- nullptr, /* getProperty */ \
- nullptr, /* setProperty */ \
- nullptr, /* enumerate */ \
- nullptr, /* resolve */ \
- 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)
+// clang-format off
+#define _GJS_DEFINE_PROTO_FULL(type_name, cname, parent_cname, ctor, gtype, \
+ jsclass_flags) \
+ 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 const struct JSClassOps gjs_##cname##_class_ops = { \
+ nullptr, /* addProperty */ \
+ nullptr, /* deleteProperty */ \
+ nullptr, /* enumerate */ \
+ nullptr, /* newEnumerate */ \
+ nullptr, /* resolve */ \
+ 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)
+// clang-format on
#define GJS_DEFINE_PROTO_FUNCS_WITH_PARENT(cname, parent_cname) \
G_GNUC_UNUSED static \
diff --git a/gjs/module.cpp b/gjs/module.cpp
index 474bba40..ad6fb68f 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -194,13 +194,12 @@ class GjsModule {
}
static constexpr JSClassOps class_ops = {
- nullptr, /* addProperty */
- nullptr, /* deleteProperty */
- nullptr, /* getProperty */
- nullptr, /* setProperty */
- nullptr, /* enumerate */
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
&GjsModule::resolve,
- nullptr, /* mayResolve */
+ nullptr, // mayResolve
&GjsModule::finalize,
};
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index 4e51f4a6..b750f757 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -27,15 +27,13 @@ test_obj_finalize(JSFreeOp *fop,
}
static const JSClassOps test_obj_class_ops = {
- NULL, /* addProperty */
- NULL, /* deleteProperty */
- NULL, /* getProperty */
- NULL, /* setProperty */
- NULL, /* enumerate */
- NULL, /* resolve */
- nullptr, /* mayResolve */
- test_obj_finalize
-};
+ nullptr, // addProperty
+ nullptr, // deleteProperty
+ nullptr, // enumerate
+ nullptr, // newEnumerate
+ nullptr, // resolve
+ nullptr, // mayResolve
+ test_obj_finalize};
static JSClass test_obj_class = {
"TestObj",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]