[gjs: 2/7] object: Return false from throw_priv_is_null_error()
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 2/7] object: Return false from throw_priv_is_null_error()
- Date: Mon, 11 Jun 2018 01:10:01 +0000 (UTC)
commit e68f61cd8aa4d5aaf1bdff9c31f203488c7dc622
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Jun 3 22:10:44 2018 -0700
object: Return false from throw_priv_is_null_error()
For convenience, since in practice we always return false after throwing,
we return false from this function too.
gi/object.cpp | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index c90adf21..11c3dd42 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -229,13 +229,14 @@ GjsListLink::size(void)
return count;
}
-static void
+static bool
throw_priv_is_null_error(JSContext *context)
{
gjs_throw(context,
"This JS object wrapper isn't wrapping a GObject."
" If this is a custom subclass, are you sure you chained"
" up to the parent _init properly?");
+ return false;
}
static ObjectInstance *
@@ -1903,10 +1904,9 @@ real_connect_func(JSContext *context,
GQuark signal_detail;
gjs_debug_gsignal("connect obj %p priv %p argc %d", obj.get(), priv, argc);
- if (priv == NULL) {
- throw_priv_is_null_error(context);
- return false; /* wrong class passed in */
- }
+ if (!priv)
+ return throw_priv_is_null_error(context); /* wrong class passed in */
+
if (priv->gobj == NULL) {
/* prototype, not an instance. */
gjs_throw(context, "Can't connect to signals on %s.%s.prototype; only on instances",
@@ -1996,10 +1996,8 @@ emit_func(JSContext *context,
gjs_debug_gsignal("emit obj %p priv %p argc %d", obj.get(), priv, argc);
- if (priv == NULL) {
- throw_priv_is_null_error(context);
- return false; /* wrong class passed in */
- }
+ if (!priv)
+ return throw_priv_is_null_error(context); /* wrong class passed in */
if (priv->gobj == NULL) {
/* prototype, not an instance. */
@@ -2105,10 +2103,8 @@ to_string_func(JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, rec, obj, ObjectInstance, priv);
- if (priv == NULL) {
- throw_priv_is_null_error(context);
- return false; /* wrong class passed in */
- }
+ if (!priv)
+ return throw_priv_is_null_error(context); /* wrong class passed in */
return _gjs_proxy_to_string_func(context, obj,
(priv->g_object_finalized) ?
@@ -2433,11 +2429,8 @@ gjs_typecheck_object(JSContext *context,
priv = priv_from_js(context, object);
if (priv == NULL) {
- if (throw_error) {
- gjs_throw(context,
- "Object instance or prototype has not been properly initialized yet. "
- "Did you forget to chain-up from _init()?");
- }
+ if (throw_error)
+ return throw_priv_is_null_error(context);
return false;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]