[gjs: 5/10] js: Don't throw extra exception if JS_HasPropertyById() fails
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 5/10] js: Don't throw extra exception if JS_HasPropertyById() fails
- Date: Sun, 6 Mar 2022 00:46:42 +0000 (UTC)
commit 109a10e1ea5a3c123b8a53ef7249d0ee19afeed9
Author: Philip Chimento <philip chimento gmail com>
Date: Tue Feb 15 22:22:00 2022 -0800
js: Don't throw extra exception if JS_HasPropertyById() fails
If JS_HasPropertyById fails, then it's likely because of an exception
thrown in a proxy trap or something weird like that. Don't try to throw
another exception over top of that; it would be confusing if the user
received an exception that seemed to suggest the property wasn't there.
gi/arg.cpp | 17 +++++++++--------
gi/value.cpp | 7 ++++---
2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 34e7c1a73..87eeebcea 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -263,11 +263,8 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_array_to_g_list(
const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
JS::RootedObject array_obj(cx, &value.toObject());
- if (!JS_HasPropertyById(cx, array_obj, atoms.length(), &found_length)) {
- throw_invalid_argument(cx, value, type_info, arg_name, arg_type);
+ if (!JS_HasPropertyById(cx, array_obj, atoms.length(), &found_length))
return false;
- }
-
if (!found_length) {
throw_invalid_argument(cx, value, type_info, arg_name, arg_type);
return false;
@@ -1124,15 +1121,19 @@ bool gjs_array_to_explicit_array(JSContext* context, JS::HandleValue value,
return false;
} else {
JS::RootedObject array_obj(context, &value.toObject());
- const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
GITypeTag element_type = g_type_info_get_tag(param_info);
if (JS_IsUint8Array(array_obj) && (element_type == GI_TYPE_TAG_INT8 ||
element_type == GI_TYPE_TAG_UINT8)) {
GBytes* bytes = gjs_byte_array_get_bytes(array_obj);
*contents = g_bytes_unref_to_data(bytes, length_p);
- } else if (JS_HasPropertyById(context, array_obj, atoms.length(),
- &found_length) &&
- found_length) {
+ return true;
+ }
+
+ const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+ if (!JS_HasPropertyById(context, array_obj, atoms.length(),
+ &found_length))
+ return false;
+ if (found_length) {
guint32 length;
if (!gjs_object_require_converted_property(
diff --git a/gi/value.cpp b/gi/value.cpp
index ecc65ad7f..a524cce95 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -551,9 +551,10 @@ gjs_value_to_g_value_internal(JSContext *context,
const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
JS::RootedObject array_obj(context, &value.toObject());
- if (JS_HasPropertyById(context, array_obj, atoms.length(),
- &found_length) &&
- found_length) {
+ if (!JS_HasPropertyById(context, array_obj, atoms.length(),
+ &found_length))
+ return false;
+ if (found_length) {
guint32 length;
if (!gjs_object_require_converted_property(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]