[seed] [libseed] Fix the code duplication in init/init_with_context_group. init_with_context_group was out



commit 343c99ffe3db1d9cdec89216e3aeae17c2e68985
Author: Robert Carr <racarr gnome org>
Date:   Wed Jul 29 04:40:58 2009 -0400

    [libseed] Fix the code duplication in init/init_with_context_group. init_with_context_group was out of sync anyway

 libseed/seed-engine.c |  101 ++++++++-----------------------------------------
 1 files changed, 16 insertions(+), 85 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index dc365a3..9fac9e5 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -1285,13 +1285,14 @@ seed_parse_args (int *argc, char ***argv)
 }
 
 /**
- * seed_init:
+ * seed_init_with_context_group:
  * @argc: A reference to the number of arguments remaining to parse.
  * @argv: A reference to an array of string arguments remaining to parse.
+ * @group: A #SeedContextGroup within which to create the initial context.
  *
  * Initializes a new #SeedEngine. This involves initializing GLib, creating
- * an initial context with all of the default globals, and initializing
- * various internal parts of Seed.
+ * an initial context (in #group) with all of the default globals, and
+ * initializing various internal parts of Seed.
  *
  * This function should only be called once within a single Seed application.
  *
@@ -1299,8 +1300,11 @@ seed_parse_args (int *argc, char ***argv)
  *
  */
 SeedEngine *
-seed_init (gint * argc, gchar *** argv)
+seed_init_with_context_group (gint * argc,
+			      gchar *** argv,
+			      JSContextGroupRef group)
 {
+
   g_type_init ();
   g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler,
 		     0);
@@ -1317,7 +1321,7 @@ seed_init (gint * argc, gchar *** argv)
 
   eng = (SeedEngine *) g_malloc (sizeof (SeedEngine));
 
-  context_group = JSContextGroupCreate ();
+  context_group = group;
 
   eng->context = JSGlobalContextCreateInGroup (context_group, NULL);
   eng->global = JSContextGetGlobalObject (eng->context);
@@ -1375,16 +1379,14 @@ seed_init (gint * argc, gchar *** argv)
   return eng;
 }
 
-
 /**
- * seed_init_with_context_group:
+ * seed_init:
  * @argc: A reference to the number of arguments remaining to parse.
  * @argv: A reference to an array of string arguments remaining to parse.
- * @group: A #SeedContextGroup within which to create the initial context.
  *
  * Initializes a new #SeedEngine. This involves initializing GLib, creating
- * an initial context (in #group) with all of the default globals, and
- * initializing various internal parts of Seed.
+ * an initial context with all of the default globals, and initializing
+ * various internal parts of Seed.
  *
  * This function should only be called once within a single Seed application.
  *
@@ -1392,82 +1394,11 @@ seed_init (gint * argc, gchar *** argv)
  *
  */
 SeedEngine *
-seed_init_with_context_group (gint * argc,
-			      gchar *** argv,
-			      JSContextGroupRef group)
+seed_init (gint * argc, gchar *** argv)
 {
-  // FIXME: this seems like unnecessary code duplication
-
-  g_type_init ();
-  g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler,
-		     0);
-
-  if ((argc != 0) && seed_parse_args (argc, argv) == FALSE)
-    {
-      SEED_NOTE (MISC, "failed to parse arguments.");
-      return false;
-    }
-
-  qname = g_quark_from_static_string ("js-type");
-  qprototype = g_quark_from_static_string ("js-prototype");
-  js_ref_quark = g_quark_from_static_string ("js-ref");
-
-  eng = (SeedEngine *) g_malloc (sizeof (SeedEngine));
-
-  context_group = group;
-
-  eng->context = JSGlobalContextCreateInGroup (context_group, NULL);
-  eng->global = JSContextGetGlobalObject (eng->context);
-  eng->group = context_group;
-  eng->search_path = NULL;
-  
-  function_proto = (JSObjectRef)
-	  seed_simple_evaluate (eng->context, "Function.prototype", NULL);
-
-  gobject_class = JSClassCreate (&gobject_def);
-  JSClassRetain (gobject_class);
-  gobject_method_class = JSClassCreate (&gobject_method_def);
-  JSClassRetain (gobject_method_class);
-  gobject_constructor_class = JSClassCreate (&gobject_constructor_def);
-  JSClassRetain (gobject_constructor_class);
-  gobject_named_constructor_class =
-    JSClassCreate (&gobject_named_constructor_def);
-  JSClassRetain (gobject_named_constructor_class);
-  gobject_signal_class = JSClassCreate (seed_get_signal_class ());
-  JSClassRetain (gobject_signal_class);
-  seed_callback_class = JSClassCreate (&seed_callback_def);
-  JSClassRetain (seed_callback_class);
-  seed_struct_constructor_class = JSClassCreate (&struct_constructor_def);
-  JSClassRetain (seed_struct_constructor_class);
-  gobject_init_method_class = JSClassCreate (&gobject_init_method_def);
-  JSClassRetain (gobject_init_method_class);
-
-  g_type_set_qdata (G_TYPE_OBJECT, qname, gobject_class);
-
-  seed_obj_ref = JSObjectMake (eng->context, NULL, NULL);
-  seed_object_set_property (eng->context, eng->global, "Seed", seed_obj_ref);
-  JSValueProtect (eng->context, seed_obj_ref);
-
-  g_irepository_require (g_irepository_get_default (), "GObject", NULL, 0, 0);
-  g_irepository_require (g_irepository_get_default (), "GIRepository",
-			 NULL, 0, 0);
-
-  seed_initialize_importer (eng->context, eng->global);
-
-  seed_init_builtins (eng, argc, argv);
-  seed_closures_init ();
-  seed_structs_init ();
-
-  seed_gtype_init (eng);
-
-  defaults_script =
-	  JSStringCreateWithUTF8CString ("Seed.include(\""SEED_PREFIX_PATH"extensions/Seed.js\");");
-  JSEvaluateScript (eng->context, defaults_script, NULL, NULL, 0, NULL);
-  JSStringRelease (defaults_script);
-
-  base_info_info =
-    g_irepository_find_by_name (0, "GIRepository", "IBaseInfo");
+  context_group = JSContextGroupCreate ();
 
-  return eng;
+  return seed_init_with_context_group (argc, argv, context_group);
 }
 
+



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