[gjs: 2/3] gi/fundamental: Check property before access




commit 8bdbc175513459521fbc9a9b2fd11657a71b8e31
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Oct 29 15:29:59 2020 +0100

    gi/fundamental: 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/fundamental.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index 8e690a46..152500e7 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -277,8 +277,12 @@ gjs_lookup_fundamental_prototype(JSContext    *context,
     if (G_UNLIKELY (!in_object))
         return nullptr;
 
+    bool found;
+    if (!JS_HasProperty(context, in_object, constructor_name, &found))
+        return nullptr;
+
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, constructor_name, &value))
+    if (found && !JS_GetProperty(context, in_object, constructor_name, &value))
         return nullptr;
 
     JS::RootedObject constructor(context);


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