[gjs/wip/inheritance-warning: 11/12] private: Don't pass argv to for_js_typecheck and use result for later



commit ebb48ac0b9b3a9e4a5ce0919e518b02a8a2d6ddf
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Sun Sep 1 05:30:43 2019 +0200

    private: Don't pass argv to for_js_typecheck and use result for later
    
    When using GObject.registerClass to register a class that doesn't inherit
    a GObject type gjs was throwing a too generic error that wasn't much clear.
    
    I.e.:
     JS ERROR: TypeError: GObject_Object.prototype.register_type called on
                          incompatible Object
    
    Since we don't care about the callee here but more the object types,
    use the simpler version of for_js_typecheck() that relies on
    gjs_typecheck_instance() to get a typed error message.

 gi/private.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gi/private.cpp b/gi/private.cpp
index dea49100..f57d6588 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -264,7 +264,11 @@ static bool gjs_register_type(JSContext* cx, unsigned argc, JS::Value* vp) {
                              "properties", &properties))
         return false;
 
-    if (!parent || !ObjectBase::for_js_typecheck(cx, parent, argv))
+    if (!parent)
+        return false;
+
+    auto* parent_priv = ObjectBase::for_js_typecheck(cx, parent);
+    if (!parent_priv)
         return false;
 
     uint32_t n_interfaces, n_properties;
@@ -285,7 +289,6 @@ static bool gjs_register_type(JSContext* cx, unsigned argc, JS::Value* vp) {
         return false;
     }
 
-    auto* parent_priv = ObjectPrototype::for_js(cx, parent);
     /* We checked parent above, in ObjectBase::for_js_typecheck() */
     g_assert(parent_priv);
 


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