[gjs/burninate-macros: 3/13] param: Remove JSClass macros



commit 265caa9759a761e3086f207d76664fbeec69843f
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat May 2 15:50:19 2020 -0700

    param: Remove JSClass macros
    
    FIXME: Need commit message

 gi/param.cpp | 70 +++++++++++++++++++++++++++++-------------------------------
 1 file changed, 34 insertions(+), 36 deletions(-)
---
diff --git a/gi/param.cpp b/gi/param.cpp
index 157717e1..627243d3 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -26,8 +26,8 @@
 #include <girepository.h>
 #include <glib.h>
 
+#include <js/CallArgs.h>
 #include <js/Class.h>
-#include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
@@ -47,7 +47,12 @@
 
 extern struct JSClass gjs_param_class;
 
-GJS_DEFINE_PRIV_FROM_JS(GParamSpec, gjs_param_class)
+GJS_JSAPI_RETURN_CONVENTION
+static GParamSpec* param_value(JSContext* cx, JS::HandleObject obj,
+                               JS::CallArgs* args = nullptr) {
+    return static_cast<GParamSpec*>(
+        JS_GetInstancePrivate(cx, obj, &gjs_param_class, args));
+}
 
 /*
  * The *resolved out parameter, on success, should be false to indicate that id
@@ -60,7 +65,7 @@ param_resolve(JSContext       *context,
               JS::HandleId     id,
               bool            *resolved)
 {
-    if (!priv_from_js(context, obj)) {
+    if (!param_value(context, obj)) {
         /* instance, not prototype */
         *resolved = false;
         return true;
@@ -100,12 +105,23 @@ param_resolve(JSContext       *context,
     return true;
 }
 
-GJS_NATIVE_CONSTRUCTOR_DECLARE(param)
-{
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES(param)
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE(param);
+GJS_JSAPI_RETURN_CONVENTION
+static bool gjs_param_constructor(JSContext* cx, unsigned argc, JS::Value* vp) {
+    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+
+    if (!args.isConstructing()) {
+        gjs_throw_constructor_error(cx);
+        return false;
+    }
+
+    JS::RootedObject new_object(
+        cx, JS_NewObjectForConstructor(cx, &gjs_param_class, args));
+    if (!new_object)
+        return false;
+
     GJS_INC_COUNTER(param);
-    GJS_NATIVE_CONSTRUCTOR_FINISH(param);
+
+    args.rval().setObject(*new_object);
     return true;
 }
 
@@ -120,7 +136,6 @@ static void param_finalize(JSFreeOp*, JSObject* obj) {
     JS_SetPrivate(obj, nullptr);
 }
 
-
 /* 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.
@@ -140,18 +155,6 @@ struct JSClass gjs_param_class = {
     &gjs_param_class_ops
 };
 
-JSPropertySpec gjs_param_proto_props[] = {
-    JS_PS_END
-};
-
-JSFunctionSpec gjs_param_proto_funcs[] = {
-    JS_FS_END
-};
-
-static JSFunctionSpec gjs_param_constructor_funcs[] = {
-    JS_FS_END
-};
-
 GJS_JSAPI_RETURN_CONVENTION
 static JSObject*
 gjs_lookup_param_prototype(JSContext    *context)
@@ -182,18 +185,14 @@ bool
 gjs_define_param_class(JSContext       *context,
                        JS::HandleObject in_object)
 {
-    const char *constructor_name;
     JS::RootedObject prototype(context), constructor(context);
-
-    constructor_name = "ParamSpec";
-
     if (!gjs_init_class_dynamic(
-            context, in_object, nullptr, "GObject", constructor_name,
+            context, in_object, nullptr, "GObject", "ParamSpec",
             &gjs_param_class, gjs_param_constructor, 0,
-            gjs_param_proto_props,  // props of prototype
-            gjs_param_proto_funcs,  // funcs of prototype
+            nullptr,  // props of prototype
+            nullptr,  // funcs of prototype
             nullptr,  // props of constructor, MyConstructor.myprop
-            gjs_param_constructor_funcs,  // funcs of constructor
+            nullptr,  // funcs of constructor
             &prototype, &constructor))
         return false;
 
@@ -205,9 +204,9 @@ gjs_define_param_class(JSContext       *context,
                                                      G_TYPE_PARAM, info))
         return false;
 
-    gjs_debug(GJS_DEBUG_GPARAM, "Defined class %s prototype is %p class %p in object %p",
-              constructor_name, prototype.get(), JS_GetClass(prototype),
-              in_object.get());
+    gjs_debug(GJS_DEBUG_GPARAM,
+              "Defined class ParamSpec prototype is %p class %p in object %p",
+              prototype.get(), &gjs_param_class, in_object.get());
     return true;
 }
 
@@ -248,7 +247,7 @@ gjs_g_param_from_param(JSContext       *context,
     if (!obj)
         return nullptr;
 
-    return priv_from_js(context, obj);
+    return param_value(context, obj);
 }
 
 bool
@@ -259,11 +258,10 @@ gjs_typecheck_param(JSContext       *context,
 {
     bool result;
 
-    if (!do_base_typecheck(context, object, throw_error))
+    if (!gjs_typecheck_instance(context, object, &gjs_param_class, throw_error))
         return false;
 
-    GParamSpec* param = priv_from_js(context, object);
-
+    GParamSpec* param = param_value(context, object);
     if (!param) {
         if (throw_error) {
             gjs_throw_custom(context, JSProto_TypeError, nullptr,


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