[gjs: 5/16] js: Fix various error handling mistakes
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 5/16] js: Fix various error handling mistakes
- Date: Sat, 3 Nov 2018 02:41:39 +0000 (UTC)
commit 8a29daa5f01c48a32a94392c9a60189f470c2199
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Oct 28 16:48:51 2018 -0400
js: Fix various error handling mistakes
These weren't caught by the compiler warnings, just by inspection as I
was making the other edits.
gi/enumeration.cpp | 5 ++---
gi/function.cpp | 5 +----
gi/fundamental.cpp | 6 +++++-
gi/interface.cpp | 5 ++---
gi/union.cpp | 9 ++++++---
modules/cairo-region.cpp | 14 ++++++++++----
6 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp
index ade2295b..2a1a2f95 100644
--- a/gi/enumeration.cpp
+++ b/gi/enumeration.cpp
@@ -109,9 +109,8 @@ gjs_define_enum_values(JSContext *context,
if (!gtype_obj)
return false;
- JS_DefineProperty(context, in_object, "$gtype", gtype_obj, JSPROP_PERMANENT);
-
- return true;
+ return JS_DefineProperty(context, in_object, "$gtype", gtype_obj,
+ JSPROP_PERMANENT);
}
bool
diff --git a/gi/function.cpp b/gi/function.cpp
index 49f14eef..ebe74142 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -501,10 +501,7 @@ gjs_callback_trampoline_new(JSContext *context,
GjsCallbackTrampoline *trampoline;
int n_args, i;
- if (function.isNull()) {
- return NULL;
- }
-
+ g_assert(function.isObject());
g_assert(JS_TypeOfValue(context, function) == JSTYPE_FUNCTION);
trampoline = g_slice_new(GjsCallbackTrampoline);
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index c661d0d0..01b949f6 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -577,8 +577,12 @@ gjs_lookup_fundamental_prototype(JSContext *context,
&constructor, &ignored))
return nullptr;
} else {
- if (G_UNLIKELY (!value.isObject()))
+ if (G_UNLIKELY(!value.isObject())) {
+ gjs_throw(context,
+ "Fundamental constructor was not an object, it was a %s",
+ JS::InformalValueTypeName(value));
return NULL;
+ }
constructor = &value.toObject();
}
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 266689bf..e8235c0b 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -256,9 +256,8 @@ gjs_define_interface_class(JSContext *context,
if (!gtype_obj)
return false;
- JS_DefineProperty(context, constructor, "$gtype", gtype_obj, JSPROP_PERMANENT);
-
- return true;
+ return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
+ JSPROP_PERMANENT);
}
bool
diff --git a/gi/union.cpp b/gi/union.cpp
index 13f1a80e..d120ce2a 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -150,6 +150,10 @@ union_new(JSContext *context,
* discard.
*/
if (rval.isNull()) {
+ gjs_throw(context,
+ "Unable to construct union type %s as its"
+ "constructor function returned NULL",
+ g_base_info_get_name(info));
return NULL;
} else {
JS::RootedObject rval_obj(context, &rval.toObject());
@@ -355,9 +359,8 @@ gjs_define_union_class(JSContext *context,
if (!gtype_obj)
return false;
- JS_DefineProperty(context, constructor, "$gtype", gtype_obj, JSPROP_PERMANENT);
-
- return true;
+ return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
+ JSPROP_PERMANENT);
}
JSObject*
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index f30453b3..aaf65154 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -153,19 +153,25 @@ make_rectangle(JSContext *context,
cairo_rectangle_int_t *rect)
{
JS::RootedObject rect_obj(context, JS_NewPlainObject(context));
+ if (!rect_obj)
+ return nullptr;
JS::RootedValue val(context);
val = JS::Int32Value(rect->x);
- JS_SetProperty(context, rect_obj, "x", val);
+ if (!JS_SetProperty(context, rect_obj, "x", val))
+ return nullptr;
val = JS::Int32Value(rect->y);
- JS_SetProperty(context, rect_obj, "y", val);
+ if (!JS_SetProperty(context, rect_obj, "y", val))
+ return nullptr;
val = JS::Int32Value(rect->width);
- JS_SetProperty(context, rect_obj, "width", val);
+ if (!JS_SetProperty(context, rect_obj, "width", val))
+ return nullptr;
val = JS::Int32Value(rect->height);
- JS_SetProperty(context, rect_obj, "height", val);
+ if (!JS_SetProperty(context, rect_obj, "height", val))
+ return nullptr;
return rect_obj;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]