[gjs/gnome-3-36] Check if STRV value is an object before toObject.
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/gnome-3-36] Check if STRV value is an object before toObject.
- Date: Mon, 20 Apr 2020 21:49:42 +0000 (UTC)
commit ec441b814529afe6729de6b294606f6577ac1a78
Author: Evan Welsh <noreply evanwelsh com>
Date: Mon Apr 20 14:01:37 2020 -0500
Check if STRV value is an object before toObject.
Fixes #315
Add regression test for STRV conversion.
gi/value.cpp | 8 +++++---
installed-tests/js/testRegress.js | 4 ++++
2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/gi/value.cpp b/gi/value.cpp
index 8059d0b6..1b7cbbdb 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -488,11 +488,11 @@ gjs_value_to_g_value_internal(JSContext *context,
g_value_set_object(gvalue, gobj);
} else if (gtype == G_TYPE_STRV) {
- bool found_length;
-
if (value.isNull()) {
/* do nothing */
- } else {
+ } else if (value.isObject()) {
+ bool found_length;
+
const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
JS::RootedObject array_obj(context, &value.toObject());
if (JS_HasPropertyById(context, array_obj, atoms.length(),
@@ -519,6 +519,8 @@ gjs_value_to_g_value_internal(JSContext *context,
} else {
return throw_expect_type(context, value, "strv");
}
+ } else {
+ return throw_expect_type(context, value, "strv");
}
} else if (g_type_is_a(gtype, G_TYPE_BOXED)) {
void *gboxed;
diff --git a/installed-tests/js/testRegress.js b/installed-tests/js/testRegress.js
index 654a419b..32ca5bba 100644
--- a/installed-tests/js/testRegress.js
+++ b/installed-tests/js/testRegress.js
@@ -226,6 +226,10 @@ describe('Life, the Universe and Everything', function () {
it('marshalling in', function () {
expect(Regress.test_strv_in(['1', '2', '3'])).toBeTruthy();
expect(Regress.test_strv_in(['4', '5', '6'])).toBeFalsy();
+ // Ensure that primitives throw without SEGFAULT
+ expect(() => Regress.test_strv_in(1)).toThrow();
+ expect(() => Regress.test_strv_in('')).toThrow();
+ expect(() => Regress.test_strv_in(false)).toThrow();
// Second two are deliberately not strings
expect(() => Regress.test_strv_in(['1', 2, 3])).toThrow();
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]