Feature Request #612590 - permit initialization using an existing JSGlobalContext
authorAlexandre Mazari <scaroo@gmail.com>
Fri, 12 Mar 2010 04:17:24 +0000 (12:17 +0800)
committerAlan Knowles <alan@akbkhome.com>
Fri, 12 Mar 2010 04:17:24 +0000 (12:17 +0800)
Usage example:

SeedEngine *eng;
void window_object_cleared (WebKitWebView  *web_view,
                            WebKitWebFrame *frame,
                            gpointer        context,
                            gpointer        arg3,
                            gpointer        user_data) {
eng = seed_init_with_context(NULL, NULL, context);
}
....
  g_signal_connect(G_OBJECT(web_view), "window-object-cleared",
       G_CALLBACK(window_object_cleared), NULL);

libseed/seed-engine.c
libseed/seed.h

index 5caa79f..bc89f8a 100644 (file)
@@ -1448,24 +1448,10 @@ seed_engine_destroy (SeedEngine *eng)
   g_free (eng);
 }
 
-/**
- * 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 (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.
- *
- * Return value: The newly created and initialized #SeedEngine.
- *
- */
+
 SeedEngine *
-seed_init_with_context_group (gint * argc,
-                             gchar *** argv, JSContextGroupRef group)
+seed_init_with_context_and_group (gint * argc,
+                             gchar *** argv, JSGlobalContextRef context, JSContextGroupRef group)
 {
 
   g_type_init ();
@@ -1491,7 +1477,7 @@ seed_init_with_context_group (gint * argc,
 
   context_group = group;
 
-  eng->context = JSGlobalContextCreateInGroup (context_group, NULL);
+  eng->context = context;
   eng->global = JSContextGetGlobalObject (eng->context);
   eng->group = context_group;
   eng->search_path = NULL;
@@ -1548,6 +1534,30 @@ seed_init_with_context_group (gint * argc,
   return eng;
 }
 
+
+
+/**
+ * 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 (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.
+ *
+ * Return value: The newly created and initialized #SeedEngine.
+ *
+ */
+SeedEngine *
+seed_init_with_context_group (gint * argc,
+                             gchar *** argv, JSContextGroupRef group)
+{
+  return seed_init_with_context_and_group (argc, argv, JSGlobalContextCreateInGroup (group, NULL), group);
+}
+
 /**
  * seed_init:
  * @argc: A reference to the number of arguments remaining to parse.
@@ -1571,3 +1581,13 @@ seed_init (gint * argc, gchar *** argv)
   return seed_init_with_context_group (argc, argv, context_group);
 }
 
+SeedEngine *
+seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
+{
+  context_group = JSContextGroupCreate ();
+  pthread_key_create(&seed_next_gobject_wrapper_key, NULL);
+
+  return seed_init_with_context_and_group (argc, argv, context, context_group);
+}
+
+
index 11c3473..a5824df 100644 (file)
@@ -73,9 +73,13 @@ typedef struct _SeedEngine
  * seed-engine.c
  */
 SeedEngine *seed_init (gint *argc, gchar ***argv);
+SeedEngine *
+seed_init_with_context (gint * argc, gchar *** argv, SeedGlobalContext context);
+
 SeedEngine *seed_init_with_context_group (gint *argc, gchar ***argv,
                                          SeedContextGroup group);
-
+SeedEngine *seed_init_with_context_and_group (gint * argc,gchar *** argv,
+                                         SeedGlobalContext context, SeedContextGroup group);
 void seed_engine_destroy (SeedEngine *eng);
 
 SeedValue seed_simple_evaluate (SeedContext ctx,