[gjs: 2/4] boxed: Define properties on error created from C struct
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 2/4] boxed: Define properties on error created from C struct
- Date: Sat, 3 Nov 2018 21:35:42 +0000 (UTC)
commit 63382c665e94803814ebf3ec9667cd9ecd75f018
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Nov 2 23:57:18 2018 -0400
boxed: Define properties on error created from C struct
The stack, filename, and location properties were not getting defined on
GErrors created directly from C structs. This was also a regression since
commit 8da83b72.
gi/boxed.cpp | 25 +++++++++++++------------
installed-tests/js/testExceptions.js | 18 +++++++++++-------
2 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 1b053117..bb05e0c8 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -1187,13 +1187,8 @@ bool gjs_define_boxed_class(JSContext* context, JS::HandleObject in_object,
JSPROP_PERMANENT);
}
-JSObject*
-gjs_boxed_from_c_struct(JSContext *context,
- GIStructInfo *info,
- void *gboxed,
- GjsBoxedCreationFlags flags)
-{
- JSObject *obj;
+JSObject* gjs_boxed_from_c_struct(JSContext* cx, GIStructInfo* info,
+ void* gboxed, GjsBoxedCreationFlags flags) {
Boxed *priv;
Boxed *proto_priv;
@@ -1204,12 +1199,15 @@ gjs_boxed_from_c_struct(JSContext *context,
"Wrapping struct %s %p with JSObject",
g_base_info_get_name((GIBaseInfo *)info), gboxed);
- JS::RootedObject proto(context, gjs_lookup_generic_prototype(context, info));
+ JS::RootedObject proto(cx, gjs_lookup_generic_prototype(cx, info));
if (!proto)
return nullptr;
- proto_priv = priv_from_js(context, proto);
+ proto_priv = priv_from_js(cx, proto);
- obj = JS_NewObjectWithGivenProto(context, JS_GetClass(proto), proto);
+ JS::RootedObject obj(
+ cx, JS_NewObjectWithGivenProto(cx, JS_GetClass(proto), proto));
+ if (!obj)
+ return nullptr;
GJS_INC_COUNTER(boxed);
priv = g_slice_new0(Boxed);
@@ -1236,12 +1234,15 @@ gjs_boxed_from_c_struct(JSContext *context,
boxed_new_direct(priv);
memcpy(priv->gboxed, gboxed, g_struct_info_get_size (priv->info));
} else {
- gjs_throw(context,
+ gjs_throw(cx,
"Can't create a Javascript object for %s; no way to copy",
- g_base_info_get_name( (GIBaseInfo*) priv->info));
+ g_base_info_get_name(priv->info));
}
}
+ if (priv->gtype == G_TYPE_ERROR && !gjs_define_error_properties(cx, obj))
+ return nullptr;
+
return obj;
}
diff --git a/installed-tests/js/testExceptions.js b/installed-tests/js/testExceptions.js
index 4fa5a55a..988f8785 100644
--- a/installed-tests/js/testExceptions.js
+++ b/installed-tests/js/testExceptions.js
@@ -1,6 +1,4 @@
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const GObject = imports.gi.GObject;
+const {GIMarshallingTests, Gio, GLib, GObject} = imports.gi;
const Foo = GObject.registerClass({
Properties: {
@@ -114,18 +112,24 @@ describe('logError', function () {
logError(new Gio.IOErrorEnum({ message: 'a message', code: 0 }));
});
- it('logs an error with no stack trace for an error created with the GLib.Error constructor', function ()
{
+ it('logs an error created with the GLib.Error constructor', function marker() {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
- 'JS ERROR: Gio.IOErrorEnum: a message\n*');
+ 'JS ERROR: Gio.IOErrorEnum: a message\nmarker@*');
logError(new GLib.Error(Gio.IOErrorEnum, 0, 'a message'));
});
- it('logs the quark for a JS-created GError type', function () {
+ it('logs the quark for a JS-created GError type', function marker() {
GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
- 'JS ERROR: GLib.Error my-error: a message\n*');
+ 'JS ERROR: GLib.Error my-error: a message\nmarker@*');
logError(new GLib.Error(GLib.quark_from_string('my-error'), 0, 'a message'));
});
+ it('logs with stack for a GError created from a C struct', function marker() {
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ 'JS ERROR: GLib.Error gi-marshalling-tests-gerror-domain:
gi-marshalling-tests-gerror-message\nmarker@*');
+ logError(GIMarshallingTests.gerror_return());
+ });
+
// Now with prefix
it('logs an error with a prefix if given', function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]