[gjs: 6/15] object: Add null check for debug assertion




commit c79fed207d44972d0f77086d1a76b7c23cbb7bc9
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Nov 27 18:37:48 2021 -0800

    object: Add null check for debug assertion
    
    Without this, we may get a sudden crash when debug is enabled, if we are
    typechecking an ObjectInstance with a null GObject pointer. This may occur
    for example if you forget to do super._init() in your class's _init()
    method, or it may be valid in some cases.
    
    If it's a bug in your JS code, continuing on will give a better diagnostic
    message than failing the assertion here.

 gi/object.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index d1880966b..9196984d8 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2797,7 +2797,8 @@ bool ObjectBase::transfer_to_gi_argument(JSContext* cx, JS::HandleObject obj,
 // Overrides GIWrapperInstance::typecheck_impl()
 bool ObjectInstance::typecheck_impl(JSContext* cx, GIBaseInfo* expected_info,
                                     GType expected_type) const {
-    g_assert(m_gobj_disposed || gtype() == G_OBJECT_TYPE(m_ptr.as<GObject*>()));
+    g_assert(m_gobj_disposed || !m_ptr ||
+             gtype() == G_OBJECT_TYPE(m_ptr.as<GObject*>()));
     return GIWrapperInstance::typecheck_impl(cx, expected_info, expected_type);
 }
 


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