[gjs/gnome-3-34] private: Don't pass argv to for_js_typecheck and use result for later



commit e8d44fd8bf31a238ea51832061799418306a1dda
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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/gi/private.cpp b/gi/private.cpp
index dea49100..d537b617 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -264,7 +264,13 @@ 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;
+
+    /* Don't pass the argv to it, as otherwise we will log about the callee
+     * while we only care about the parent object type. */
+    auto* parent_priv = ObjectBase::for_js_typecheck(cx, parent);
+    if (!parent_priv)
         return false;
 
     uint32_t n_interfaces, n_properties;
@@ -285,7 +291,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]