seed r112 - trunk/libseed



Author: racarr
Date: Wed Nov  5 01:40:01 2008
New Revision: 112
URL: http://svn.gnome.org/viewvc/seed?rev=112&view=rev

Log:
Finish biggiantexceptionrework. There are fewer ways to crash seed now.


Modified:
   trunk/libseed/seed-engine.c
   trunk/libseed/seed-types.c

Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c	(original)
+++ trunk/libseed/seed-engine.c	Wed Nov  5 01:40:01 2008
@@ -38,6 +38,9 @@
 	JSValueRef js_name_ref = 0, js_message_ref = 0;
 	JSObjectRef exception_obj;
 
+	if (!exception)
+		return;
+
 	if (name) {
 		js_name = JSStringCreateWithUTF8CString(name);
 		js_name_ref = JSValueMakeString(eng->context, js_name);
@@ -196,11 +199,15 @@
 	GError *error = 0;
 
 	info = JSObjectGetPrivate(function);
+	// We just want to check if there IS an object, not actually throw an exception if we don't
+	// get it.
 	if (!
-	    ((object = seed_value_to_object(this_object, exception)) ||
+	    ((object = seed_value_to_object(this_object, 0)) ||
 	     (object = seed_struct_get_pointer(this_object))))
 		instance_method = FALSE;
 
+
+
 	n_args = g_callable_info_get_n_args((GICallableInfo *) info);
 
 	in_args = g_new0(GArgument, n_args + 1);
@@ -480,9 +487,7 @@
 	if (JSValueIsNull(eng->context, value))
 		return 0;
 
-	obj = seed_value_to_object(object, exception);
-	if (!obj || !G_IS_OBJECT(obj))
-		return FALSE;
+	obj = seed_value_to_object(object, 0);
 
 	length = JSStringGetMaximumUTF8CStringSize(property_name);
 	cproperty_name = malloc(length * sizeof(gchar));
@@ -511,17 +516,11 @@
 	else
 		type = spec->value_type;
 
-	if (!seed_gvalue_from_seed_value(value, type, &gval, exception)) {
-		gchar *mes = g_strdup_printf("Not able to set property %s"
-					     "on object of type %s."
-					     " Expected type: %s. \n",
-					     cproperty_name,
-					     g_type_name(G_OBJECT_TYPE(obj)),
-					     g_type_name(spec->value_type));
-		seed_make_exception(exception, "InvalidPropertyValue", mes);
-		g_free(mes);
-		g_free(cproperty_name);
-		return 0;
+	seed_gvalue_from_seed_value(value, type, &gval, exception);
+	if (*exception)
+	{
+			g_free(cproperty_name);
+			return 0;
 	}
 
 	g_object_set_property(obj, cproperty_name, &gval);

Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c	(original)
+++ trunk/libseed/seed-types.c	Wed Nov  5 01:40:01 2008
@@ -80,8 +80,8 @@
 			for (k = 0; k < n_functions; k++) {
 				function =
 				    g_interface_info_get_method((GIInterfaceInfo
-								 *) interface,
-								k);
+												 *) interface, k);
+
 				seed_gobject_define_property_from_function_info
 				    (function, (JSObjectRef) js_ref, TRUE);
 			}
@@ -699,17 +699,15 @@
 	return TRUE;
 }
 
-static void seed_value_wrong_type()
-{
-	printf("Wrong type in type conversion!\n");
-	abort();
-}
-
 gboolean seed_value_to_boolean(JSValueRef val, JSValueRef * exception)
 {
 	if (!JSValueIsBoolean(eng->context, val)) {
-		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+		if (!JSValueIsNull(eng->context, val)) {
+			seed_make_exception(exception, "ConversionError",
+								"Can not convert Javascript value to boolean");
+			return 0;
+		}
+			
 
 		seed_value_wrong_type();
 		return 0;
@@ -727,7 +725,11 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+		{
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " boolean");
+		}
 		return 0;
 	}
 
@@ -743,7 +745,9 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " int");
 		return 0;
 	}
 
@@ -761,15 +765,18 @@
 
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " gchar");
 		return 0;
 	}
 
 	cv = JSValueToNumber(eng->context, val, NULL);
 
 	if (cv < G_MININT8 || cv > G_MAXINT8) {
-		seed_value_wrong_type();
-		return 0;
+		seed_make_exception(exception, "ConversionError",
+								  "Javascript number out of range of gchar");
+					return 0;
 	}
 
 	return (char)cv;
@@ -786,14 +793,17 @@
 
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " guchar");
 		return 0;
 	}
 
 	cv = JSValueToNumber(eng->context, val, NULL);
 
 	if (cv > G_MAXUINT8) {
-		seed_value_wrong_type();
+		seed_make_exception(exception, "ConversionError",
+								  "Javascript number out of range of guchar");
 		return 0;
 	}
 
@@ -809,7 +819,9 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " long");
 		return 0;
 	}
 
@@ -825,7 +837,10 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+			seed_make_exception(exception, "ConversionError",
+									  "Can not convert Javascript value to"
+									  " ulong");
+
 		return 0;
 	}
 
@@ -841,7 +856,10 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+			seed_make_exception(exception, "ConversionError",
+									  "Can not convert Javascript value to"
+									  " gint64");
+
 		return 0;
 	}
 
@@ -857,13 +875,17 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+			seed_make_exception(exception, "ConversionError",
+									  "Can not convert Javascript value to"
+									  " guint64");
+
 		return 0;
 	}
 
 	return (guint64) JSValueToNumber(eng->context, val, NULL);
 }
 
+
 JSValueRef seed_value_from_uint64(guint64 val, JSValueRef * exception)
 {
 	return JSValueMakeNumber(eng->context, (gdouble) val);
@@ -873,7 +895,9 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " gfloat");
 		return 0;
 	}
 
@@ -889,7 +913,9 @@
 {
 	if (!JSValueIsNumber(eng->context, val)) {
 		if (!JSValueIsNull(eng->context, val))
-			seed_value_wrong_type();
+				seed_make_exception(exception, "ConversionError",
+										  "Can not convert Javascript value to"
+										  " double");
 		return 0;
 	}
 
@@ -958,10 +984,7 @@
 		return NULL;
 	}
 
-	if (JSValueIsObjectOfClass(eng->context, val, gobject_class))
-		gobject = (GObject *) JSObjectGetPrivate((JSObjectRef) val);
-	else
-		gobject = NULL;
+	gobject = (GObject *) JSObjectGetPrivate((JSObjectRef) val);
 
 	return gobject;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]