[seed] Reimplement Seed.import_namespace in terms of the new system, it's still deprecated, but at least it



commit ee8be847da0105a447de678d3e0f1c53051d7e43
Author: Robert Carr <racarr svn gnome org>
Date:   Fri Apr 17 19:55:46 2009 -0400

    Reimplement Seed.import_namespace in terms of the new system, it's still deprecated, but at least it works now
---
 libseed/seed-engine.c |  261 +-----------------------------------------------
 1 files changed, 6 insertions(+), 255 deletions(-)

diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 2ef73f3..28c9c10 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -893,14 +893,10 @@ seed_gi_import_namespace (JSContextRef ctx,
 			  const JSValueRef arguments[],
 			  JSValueRef * exception)
 {
-  GIBaseInfo *info;
-  GError *e = 0;
   gchar *namespace;
   const gchar *version = 0;
   gchar *jsextension;
-  JSObjectRef namespace_ref;
   JSStringRef extension_script;
-  gint n, i;
   GModule *extension;
 
   ctx = eng->context;
@@ -920,257 +916,12 @@ seed_gi_import_namespace (JSContextRef ctx,
       version = seed_value_to_string (ctx, arguments[1], exception);
     }
 
-  extension = seed_try_load_extension (namespace);
-  if (extension)
-    {
-      JSObjectRef module_object;
-      SeedModuleInitCallback init;
-
-      g_module_symbol (extension, "seed_module_init", (gpointer *) & init);
-
-      module_object = (*init) (eng);
-      
-      seed_object_set_property (ctx, eng->global, namespace, module_object);
-
-      g_free (namespace);
-      return JSValueMakeNull (ctx);
-    }
-
-  if (!g_irepository_require (g_irepository_get_default (), namespace,
-			      version, 0, &e))
-    {
-      seed_make_exception_from_gerror (ctx, exception, e);
-      return JSValueMakeNull (ctx);
-    }
-
-  n = g_irepository_get_n_infos (g_irepository_get_default (), namespace);
-
-  namespace_ref = JSObjectMake (ctx, NULL, NULL);
-  JSValueProtect (ctx, namespace_ref);
-  seed_object_set_property (ctx, eng->global, namespace, namespace_ref);
-
-  for (i = 0; i < n; i++)
-    {
-      info = g_irepository_get_info (g_irepository_get_default (),
-				     namespace, i);
-      if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION))
-	{
-	  seed_gobject_define_property_from_function_info (ctx,
-							   (GIFunctionInfo *)
-							   info,
-							   namespace_ref,
-							   FALSE);
-	}
-      else if (info
-	       && (g_base_info_get_type (info) == GI_INFO_TYPE_ENUM
-		   || g_base_info_get_type (info) == GI_INFO_TYPE_FLAGS))
-	{
-	  gint num_vals = g_enum_info_get_n_values ((GIEnumInfo *) info);
-	  gint j;
-	  JSObjectRef enum_class = JSObjectMake (ctx,
-						 0, 0);
-	  JSValueProtect (ctx, (JSValueRef) enum_class);
-	  seed_object_set_property (ctx, namespace_ref,
-				    g_base_info_get_name (info), enum_class);
-
-	  for (j = 0; j < num_vals; j++)
-	    {
-	      GIValueInfo *val =
-		g_enum_info_get_value ((GIEnumInfo *) info, j);
-	      gint value = g_value_info_get_value (val);
-	      gchar *name =
-		g_strdup (g_base_info_get_name ((GIBaseInfo *) val));
-	      gint name_len = strlen (name);
-	      gint j;
-	      JSValueRef value_ref;
-
-	      value_ref = JSValueMakeNumber (ctx, value);
-	      JSValueProtect (ctx, (JSValueRef) value_ref);
-
-	      for (j = 0; j < name_len; j++)
-		{
-		  if (name[j] == '-')
-		    name[j] = '_';
-		  name[j] = g_ascii_toupper (name[j]);
-		}
-
-	      seed_object_set_property (ctx, enum_class, name, value_ref);
-
-	      g_free (name);
-	      g_base_info_unref ((GIBaseInfo *) val);
-
-	    }
-	}
-      else if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_OBJECT))
-	{
-	  GType type;
-	  JSClassRef class_ref;
-
-	  type =
-	    g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
-
-	  if (type != 0)
-	    {
-	      JSObjectRef constructor_ref;
-	      gint i, n_methods;
-	      GIFunctionInfo *finfo;
-	      GIFunctionInfoFlags flags;
-
-	      class_ref = seed_gobject_get_class_for_gtype (ctx, type);
-
-	      constructor_ref =
-		JSObjectMake (ctx,
-			      gobject_constructor_class, (gpointer) type);
-
-	      seed_object_set_property (ctx, constructor_ref,
-					"type",
-					seed_value_from_int (ctx, type,
-							     exception));
-
-	      n_methods = g_object_info_get_n_methods ((GIObjectInfo *) info);
-	      for (i = 0; i < n_methods; i++)
-		{
-		  finfo = g_object_info_get_method ((GIObjectInfo *) info, i);
-		  flags = g_function_info_get_flags (finfo);
-		  if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
-		    {
-		      JSObjectRef constructor = JSObjectMake (ctx,
-							      gobject_named_constructor_class,
-							      finfo);
-		      const gchar *fname =
-			g_base_info_get_name ((GIBaseInfo *) finfo);
-		      if (strstr (fname, "new_") == fname)
-			fname += 4;
-		      else if (!strcmp (fname, "new"))
-			fname = "c_new";
-
-		      seed_object_set_property (ctx,
-						constructor_ref,
-						fname, constructor);
-		    }
-		  else if (!(flags & GI_FUNCTION_IS_METHOD))
-		    {
-		      seed_gobject_define_property_from_function_info
-			(ctx, finfo, constructor_ref, FALSE);
-		    }
-		  else
-		    {
-		      g_base_info_unref ((GIBaseInfo *) finfo);
-		    }
-		}
-
-	      seed_object_set_property (ctx, namespace_ref,
-					g_base_info_get_name
-					(info), constructor_ref);
-	      seed_object_set_property (ctx, constructor_ref,
-					"prototype",
-					seed_gobject_get_prototype_for_gtype
-					(type));
-	      JSValueProtect (ctx, (JSValueRef) constructor_ref);
-	    }
-	}
-      else if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_STRUCT))
-	{
-	  JSObjectRef struct_ref;
-	  JSObjectRef proto;
-	  gint i, n_methods;
-	  GIFunctionInfo *finfo;
-
-	  struct_ref =
-	    JSObjectMake (ctx, seed_struct_constructor_class, info);
-
-	  n_methods = g_struct_info_get_n_methods ((GIStructInfo *) info);
-
-	  for (i = 0; i < n_methods; i++)
-	    {
-	      GIFunctionInfoFlags flags;
-	      finfo = g_struct_info_get_method ((GIStructInfo *) info, i);
-
-	      flags = g_function_info_get_flags (finfo);
-
-	      if (flags & GI_FUNCTION_IS_METHOD)
-		g_base_info_unref ((GIBaseInfo *) finfo);
-	      else
-		seed_gobject_define_property_from_function_info
-		  (ctx, finfo, struct_ref, FALSE);
-
-	    }
-
-	  proto = seed_struct_prototype (ctx, info);
-	  seed_object_set_property (ctx, struct_ref, "prototype", proto);
-
-	  seed_object_set_property (ctx, namespace_ref,
-				    g_base_info_get_name (info), struct_ref);
-
-	  JSValueProtect (ctx, (JSValueRef) struct_ref);
-	}
-      else if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_UNION))
-	{
-	  JSObjectRef struct_ref;
-	  JSObjectRef proto;
-	  gint i, n_methods;
-	  GIFunctionInfo *finfo;
-
-	  struct_ref =
-	    JSObjectMake (ctx, seed_struct_constructor_class, info);
-
-	  n_methods = g_union_info_get_n_methods ((GIUnionInfo *) info);
-
-	  for (i = 0; i < n_methods; i++)
-	    {
-	      GIFunctionInfoFlags flags;
-
-	      finfo = g_union_info_get_method ((GIUnionInfo *) info, i);
-	      flags = g_function_info_get_flags (finfo);
-
-	      if (flags & GI_FUNCTION_IS_METHOD)
-		g_base_info_unref ((GIBaseInfo *) finfo);
-	      else
-		seed_gobject_define_property_from_function_info
-		  (ctx, finfo, struct_ref, FALSE);
-
-	    }
-
-	  proto = seed_union_prototype (ctx, info);
-	  seed_object_set_property (ctx, struct_ref, "prototype", proto);
-
-	  seed_object_set_property (ctx, namespace_ref,
-				    g_base_info_get_name (info), struct_ref);
-
-	  JSValueProtect (ctx, (JSValueRef) struct_ref);
-	}
-      else if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_CALLBACK))
-	{
-	  JSObjectRef callback_ref = JSObjectMake (ctx,
-						   seed_callback_class,
-						   info);
-	  seed_object_set_property (ctx, namespace_ref,
-				    g_base_info_get_name (info),
-				    (JSValueRef) callback_ref);
-	}
-      else if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_CONSTANT))
-	{
-	  GArgument argument;
-	  GITypeInfo *constant_type =
-	    g_constant_info_get_type ((GIConstantInfo *) info);
-	  JSValueRef constant_value;
-
-	  g_constant_info_get_value ((GIConstantInfo *) info, &argument);
-	  constant_value =
-	    seed_gi_argument_make_js (ctx, &argument,
-				      constant_type, exception);
-	  seed_object_set_property (ctx, namespace_ref,
-				    g_base_info_get_name (info),
-				    constant_value);
-
-	  g_base_info_unref ((GIBaseInfo *) constant_type);
-
-	}
-      g_base_info_unref (info);
-    }
-
-  jsextension =
-	  g_strdup_printf("imports.extensions.%s", namespace);
+  if (version)
+    jsextension = g_strdup_printf("imports.gi.versions.%s = %s; %s = imports.gi.%s;",
+				  namespace, version, namespace, namespace);
+  else
+    jsextension =
+      g_strdup_printf("%s = imports.gi.%s;", namespace, namespace);
   extension_script = JSStringCreateWithUTF8CString (jsextension);
   JSEvaluateScript (ctx, extension_script, NULL, NULL, 0, NULL);
   JSStringRelease (extension_script);



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