[gjs: 14/15] repo: Fix error handling in lookup functions
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 14/15] repo: Fix error handling in lookup functions
- Date: Mon, 24 Dec 2018 00:42:51 +0000 (UTC)
commit 6635a418de4a00a41a5251cdd8db7e22080ed61d
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Dec 22 15:38:08 2018 -0700
repo: Fix error handling in lookup functions
In gjs_lookup_generic_constructor() and gjs_lookup_generic_prototype(),
the case where the constructor or prototype existed, but was not an
object, was not handled properly. An exception needed to be thrown.
gi/repo.cpp | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 7b0c9fd4..9c2e848c 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -747,8 +747,12 @@ gjs_lookup_generic_constructor(JSContext *context,
if (!JS_GetProperty(context, in_object, constructor_name, &value))
return NULL;
- if (G_UNLIKELY (!value.isObject()))
+ if (G_UNLIKELY(!value.isObject())) {
+ gjs_throw(context,
+ "Constructor of %s.%s was the wrong type, expected an object",
+ g_base_info_get_namespace(info), constructor_name);
return NULL;
+ }
return &value.toObject();
}
@@ -767,8 +771,12 @@ gjs_lookup_generic_prototype(JSContext *context,
if (!JS_GetPropertyById(context, constructor, atoms.prototype(), &value))
return NULL;
- if (G_UNLIKELY (!value.isObjectOrNull()))
+ if (G_UNLIKELY(!value.isObject())) {
+ gjs_throw(context,
+ "Prototype of %s.%s was the wrong type, expected an object",
+ g_base_info_get_namespace(info), g_base_info_get_name(info));
return NULL;
+ }
- return value.toObjectOrNull();
+ return &value.toObject();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]