[gjs] object: Make define_static_methods infallible
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] object: Make define_static_methods infallible
- Date: Tue, 3 Jan 2017 04:34:09 +0000 (UTC)
commit 177c8f080bc078dac32d922dd2a2c9b52c42268c
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Dec 30 22:11:37 2016 -0700
object: Make define_static_methods infallible
Previously, gjs_object_define_static_methods() always returned true even
if an exception was thrown, causing the exception to be swallowed. Since
it never returned anything but true, we get rid of the return type.
Exceptions thrown by fallible functions called within
gjs_object_define_static_methods() are logged immediately and cleared.
(Allowing the exceptions to propagate and be caught would potentially
result in a GI namespace with only half its methods defined, and that
seems undesirable.)
https://bugzilla.gnome.org/show_bug.cgi?id=737607
gi/object.cpp | 15 ++++++++-------
gi/object.h | 2 +-
2 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index c16ff31..37c6f93 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1955,7 +1955,7 @@ JSFunctionSpec gjs_object_instance_proto_funcs[] = {
JS_FS_END
};
-bool
+void
gjs_object_define_static_methods(JSContext *context,
JS::HandleObject constructor,
GType gtype,
@@ -1982,8 +1982,9 @@ gjs_object_define_static_methods(JSContext *context,
* like in the near future.
*/
if (!(flags & GI_FUNCTION_IS_METHOD)) {
- gjs_define_function(context, constructor, gtype,
- (GICallableInfo *)meth_info);
+ if (!gjs_define_function(context, constructor, gtype,
+ (GICallableInfo *) meth_info))
+ gjs_log_exception(context);
}
g_base_info_unref((GIBaseInfo*) meth_info);
@@ -1992,7 +1993,7 @@ gjs_object_define_static_methods(JSContext *context,
gtype_struct = g_object_info_get_class_struct(object_info);
if (gtype_struct == NULL)
- return true;
+ return;
n_methods = g_struct_info_get_n_methods(gtype_struct);
@@ -2001,14 +2002,14 @@ gjs_object_define_static_methods(JSContext *context,
meth_info = g_struct_info_get_method(gtype_struct, i);
- gjs_define_function(context, constructor, gtype,
- (GICallableInfo*)meth_info);
+ if (!gjs_define_function(context, constructor, gtype,
+ (GICallableInfo *) meth_info))
+ gjs_log_exception(context);
g_base_info_unref((GIBaseInfo*) meth_info);
}
g_base_info_unref((GIBaseInfo*) gtype_struct);
- return true;
}
void
diff --git a/gi/object.h b/gi/object.h
index 2e7e538..6b22fb9 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -58,7 +58,7 @@ bool gjs_typecheck_is_object(JSContext *context,
void gjs_object_prepare_shutdown (JSContext *context);
-bool gjs_object_define_static_methods(JSContext *context,
+void gjs_object_define_static_methods(JSContext *context,
JS::HandleObject constructor,
GType gtype,
GIObjectInfo *object_info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]