summaryrefslogtreecommitdiff
path: root/gi/object.cpp
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2021-11-27 18:37:48 -0800
committerPhilip Chimento <philip.chimento@gmail.com>2022-01-15 16:58:19 -0800
commitc79fed207d44972d0f77086d1a76b7c23cbb7bc9 (patch)
tree94f8192ab89ea43e0c10a9b66f2d5cf6e24d584b /gi/object.cpp
parentee46d3c18f8a1aa86573d94189184ec2a65c55b1 (diff)
downloadgjs-c79fed207d44972d0f77086d1a76b7c23cbb7bc9.tar.gz
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.
Diffstat (limited to 'gi/object.cpp')
-rw-r--r--gi/object.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/gi/object.cpp b/gi/object.cpp
index d1880966..9196984d 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);
}