[seed] libseed: Properly bubble exceptions raised during class init
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed] libseed: Properly bubble exceptions raised during class init
- Date: Fri, 15 Jan 2010 04:37:51 +0000 (UTC)
commit 5efce55da01646afdf1c46edefa27d62f04292da
Author: Tim Horton <hortont424 gmail com>
Date: Thu Jan 14 23:36:17 2010 -0500
libseed: Properly bubble exceptions raised during class init
Before, we were simply catching the exception, printing it, and continuing
on happily. This completely defeats the point of exceptions. Now, we pop
the exception into the class's qdata (a little ugly) and bubble it up and
clear it the first time we encounter it (when the class is created, the
first time it's instantiated).
libseed/seed-engine.c | 15 +++++++++++++++
libseed/seed-gtype.c | 11 ++++-------
.../gtypes/gtype-class-init-exception.js | 9 +--------
3 files changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 9fbdf72..6e02230 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -161,6 +161,21 @@ seed_gobject_constructor_invoked (JSContextRef ctx,
oclass = g_type_class_ref (type);
+ // Check for an exception in class init (which may have just been called
+ // by g_type_class_ref, if this is the first construction of this class).
+ // Bubble up the exception, and clear it from the class's qdata so that
+ // this doesn't happen on subsequent construction.
+ GQuark class_init_exception_q =
+ g_quark_from_static_string("type-class-init-exception");
+ JSValueRef class_init_exception =
+ (JSValueRef)g_type_get_qdata(type, class_init_exception_q);
+ if(class_init_exception)
+ {
+ *exception = class_init_exception;
+ g_type_set_qdata(type, class_init_exception_q, NULL);
+ return (JSObjectRef) JSValueMakeNull (ctx);
+ }
+
if (argumentCount > 1)
{
seed_make_exception (ctx, exception, "ArgumentError",
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index 4812cb8..73465b6 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -782,9 +782,10 @@ seed_gtype_class_init (gpointer g_class, gpointer class_data)
JSContextRef ctx;
JSValueRef jsargs[2];
GType type;
- gchar *mes;
JSValueRef exception = NULL;
int initial_prop_count = 1;
+ GQuark class_init_exception_q =
+ g_quark_from_static_string("type-class-init-exception");
priv = (SeedGClassPrivates *) class_data;
@@ -807,9 +808,7 @@ seed_gtype_class_init (gpointer g_class, gpointer class_data)
JSGlobalContextRelease ((JSGlobalContextRef) ctx);
if (exception)
{
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in class init closure. %s \n", mes);
- g_free (mes);
+ g_type_set_qdata(type, class_init_exception_q, (gpointer)exception);
}
return;
}
@@ -839,9 +838,7 @@ seed_gtype_class_init (gpointer g_class, gpointer class_data)
JSObjectCallAsFunction (ctx, priv->func, 0, 2, jsargs, &exception);
if (exception)
{
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in class init closure. %s \n", mes);
- g_free (mes);
+ g_type_set_qdata(type, class_init_exception_q, (gpointer)exception);
}
JSGlobalContextRelease ((JSGlobalContextRef) ctx);
diff --git a/tests/javascript/gtypes/gtype-class-init-exception.js b/tests/javascript/gtypes/gtype-class-init-exception.js
index e537c6e..86760d2 100755
--- a/tests/javascript/gtypes/gtype-class-init-exception.js
+++ b/tests/javascript/gtypes/gtype-class-init-exception.js
@@ -1,8 +1,4 @@
#!/usr/bin/env seed
-// Returns: 0
-// STDIN:
-// STDOUT:
-// STDERR:\n\*\* \(seed:[0-9]+\): WARNING \*\*: Exception in class init closure\. Line 14 in .*\/gtype-class-init-exception\.js: ReferenceError Can't find variable: notAVariable
testsuite = imports.testsuite
Gtk = imports.gi.Gtk
@@ -28,10 +24,7 @@ try
catch(e)
{
testsuite.assert(e instanceof ReferenceError)
- // TODO: THIS TEST DOESN'T WORK EITHER!
- // what's going on with chained exception stuff
}
-//testsuite.checkAsserts(1)
+testsuite.checkAsserts(1)
-print("This test doesn't work yet...")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]