[gjs: 1/3] gi/object: Check property before access




commit 999e4f940f0d73a2e8ba5c8fd5e6c1ef1c599ca2
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Oct 29 13:05:23 2020 +0100

    gi/object: Check property before access
    
    ... to avoid a harmless but annoying "access to undefined property"
    warning in case the property doesn't exist (namely the first time
    a non-introspected gtype is accessed).

 gi/object.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index f13decdf..c1d4b7b1 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1708,8 +1708,12 @@ JSObject* gjs_lookup_object_constructor_from_info(JSContext* context,
     if (G_UNLIKELY (!in_object))
         return NULL;
 
+    bool found;
+    if (!JS_HasProperty(context, in_object, constructor_name, &found))
+        return NULL;
+
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, constructor_name, &value))
+    if (found && !JS_GetProperty(context, in_object, constructor_name, &value))
         return NULL;
 
     JS::RootedObject constructor(context);


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