[gjs/burninate-macros: 1/13] repo: Remove JSClass macros



commit 9fdeb95eeb154339ec89bc09bdcc3850279592b9
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Apr 6 14:08:01 2020 -0700

    repo: Remove JSClass macros
    
    The macros in jsapi-class.h are not needed here. Instead of using
    JS_InitClass() which requires a constructor and prototype object, we can
    just use JS_NewObject() which will use a plain object as the prototype,
    and we don't need to store private data in the instances since there is
    none.

 gi/repo.cpp       | 80 +++++--------------------------------------------------
 gjs/global.h      |  1 -
 gjs/mem-private.h |  1 -
 3 files changed, 6 insertions(+), 76 deletions(-)
---
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 08df95e1..b66ddae2 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -55,23 +55,9 @@
 #include "gjs/atoms.h"
 #include "gjs/context-private.h"
 #include "gjs/global.h"
-#include "gjs/jsapi-class.h"
 #include "gjs/jsapi-util.h"
-#include "gjs/mem-private.h"
 #include "util/log.h"
 
-struct JSFunctionSpec;
-struct JSPropertySpec;
-
-typedef struct {
-    void *dummy;
-
-} Repo;
-
-extern struct JSClass gjs_repo_class;
-
-GJS_DEFINE_PRIV_FROM_JS(Repo, gjs_repo_class)
-
 GJS_JSAPI_RETURN_CONVENTION
 static bool lookup_override_function(JSContext *, JS::HandleId,
                                      JS::MutableHandleValue);
@@ -180,8 +166,6 @@ repo_resolve(JSContext       *context,
              JS::HandleId     id,
              bool            *resolved)
 {
-    Repo *priv;
-
     if (!JSID_IS_STRING(id)) {
         *resolved = false;
         return true; /* not resolved, but no error */
@@ -194,20 +178,8 @@ repo_resolve(JSContext       *context,
         return true;
     }
 
-    priv = priv_from_js(context, obj);
-    gjs_debug_jsprop(GJS_DEBUG_GREPO, "Resolve prop '%s' hook, obj %s, priv %p",
-                     gjs_debug_id(id).c_str(), gjs_debug_object(obj).c_str(), priv);
-
-    if (priv == NULL) {
-        /* we are the prototype, or have the wrong class */
-        *resolved = false;
-        return true;
-    }
-
-    if (!JSID_IS_STRING(id)) {
-        *resolved = false;
-        return true;
-    }
+    gjs_debug_jsprop(GJS_DEBUG_GREPO, "Resolve prop '%s' hook, obj %s",
+                     gjs_debug_id(id).c_str(), gjs_debug_object(obj).c_str());
 
     if (!resolve_namespace_object(context, obj, id))
         return false;
@@ -216,68 +188,28 @@ repo_resolve(JSContext       *context,
     return true;
 }
 
-GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(repo)
-
-static void repo_finalize(JSFreeOp*, JSObject* obj) {
-    Repo *priv;
-
-    priv = (Repo*) JS_GetPrivate(obj);
-    gjs_debug_lifecycle(GJS_DEBUG_GREPO,
-                        "finalize, obj %p priv %p", obj, priv);
-    if (priv == NULL)
-        return; /* we are the prototype, not a real instance */
-
-    GJS_DEC_COUNTER(repo);
-    g_slice_free(Repo, priv);
-}
-
-/* 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.
- */
 static const struct JSClassOps gjs_repo_class_ops = {
     nullptr,  // addProperty
     nullptr,  // deleteProperty
     nullptr,  // enumerate
     nullptr,  // newEnumerate
     repo_resolve,
-    nullptr,  // mayResolve
-    repo_finalize};
+};
 
 struct JSClass gjs_repo_class = {
-    "GIRepository", /* means "new GIRepository()" works */
-    JSCLASS_HAS_PRIVATE | JSCLASS_FOREGROUND_FINALIZE,
+    "GIRepository",
+    0,
     &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;
-
-GJS_DEFINE_PROTO_FUNCS(repo)
-
 GJS_JSAPI_RETURN_CONVENTION
 static JSObject*
 repo_new(JSContext *context)
 {
-    Repo *priv;
-
-    JS::RootedObject proto(context);
-    if (!gjs_repo_define_proto(context, nullptr, &proto))
-        return nullptr;
-
-    JS::RootedObject repo(context,
-        JS_NewObjectWithGivenProto(context, &gjs_repo_class, proto));
+    JS::RootedObject repo(context, JS_NewObject(context, &gjs_repo_class));
     if (repo == nullptr)
         return nullptr;
 
-    priv = g_slice_new0(Repo);
-
-    GJS_INC_COUNTER(repo);
-
-    g_assert(priv_from_js(context, repo) == NULL);
-    JS_SetPrivate(repo, priv);
-
     gjs_debug_lifecycle(GJS_DEBUG_GREPO,
                         "repo constructor, obj %p priv %p", repo.get(), priv);
 
diff --git a/gjs/global.h b/gjs/global.h
index 649ee3dc..3fcf23f4 100644
--- a/gjs/global.h
+++ b/gjs/global.h
@@ -36,7 +36,6 @@ typedef enum {
     GJS_GLOBAL_SLOT_PROTOTYPE_gtype,
     GJS_GLOBAL_SLOT_PROTOTYPE_function,
     GJS_GLOBAL_SLOT_PROTOTYPE_ns,
-    GJS_GLOBAL_SLOT_PROTOTYPE_repo,
     GJS_GLOBAL_SLOT_PROTOTYPE_importer,
     GJS_GLOBAL_SLOT_PROTOTYPE_cairo_context,
     GJS_GLOBAL_SLOT_PROTOTYPE_cairo_gradient,
diff --git a/gjs/mem-private.h b/gjs/mem-private.h
index 14b739ac..f46d4025 100644
--- a/gjs/mem-private.h
+++ b/gjs/mem-private.h
@@ -48,7 +48,6 @@ typedef struct {
     macro(object_instance)          \
     macro(object_prototype)         \
     macro(param)                    \
-    macro(repo)                     \
     macro(union_instance)           \
     macro(union_prototype)
 // clang-format on


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]