[seed] Fix shadowed variable declaration causing the Seed global object to be wrong sometimes with the new



commit 85fcd4d3a8e49ddfec3a0318825c9ea824f0558d
Author: Robert Carr <racarr mireia (none)>
Date:   Mon Apr 13 16:04:10 2009 -0400

    Fix shadowed variable declaration causing the Seed global object to be wrong sometimes with the new importer
---
 examples/browser/BrowserView.js |    2 ++
 libseed/seed-builtins.c         |    4 +++-
 libseed/seed-closure.c          |    2 ++
 libseed/seed-engine.c           |   11 ++++++++++-
 libseed/seed-engine.h           |    2 ++
 libseed/seed-gtype.c            |    8 ++++++++
 libseed/seed-importer.c         |   11 ++---------
 libseed/seed-importer.h         |    2 ++
 libseed/seed-signals.c          |    4 +++-
 libseed/seed-types.c            |    3 ++-
 10 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/examples/browser/BrowserView.js b/examples/browser/BrowserView.js
index c7b3d9b..0e9e705 100644
--- a/examples/browser/BrowserView.js
+++ b/examples/browser/BrowserView.js
@@ -1,6 +1,8 @@
 Gtk = imports.gi.Gtk;
 WebKit = imports.gi.WebKit;
 
+Seed.print("In BrowserView.js imports: " + imports);
+
 BrowserView = new GType({
     parent: WebKit.WebView.type,
     name: "BrowserView",
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 1883360..6a9925a 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -141,7 +141,7 @@ seed_scoped_include (JSContextRef ctx,
   /* just try current dir if no path set, or use the absolute path */
   if (!eng->search_path || g_path_is_absolute (import_file))
     g_file_get_contents (import_file, &buffer, 0, NULL);
-  else				/* A search path is set and path given is not absolute.  */
+  else	/* A search path is set and path given is not absolute.  */
     {
       for (i = 0; i < g_strv_length (eng->search_path); ++i)
 	{
@@ -192,6 +192,8 @@ seed_scoped_include (JSContextRef ctx,
 
   
   nctx = JSGlobalContextCreateInGroup (context_group, 0);
+  seed_prepare_global_context (nctx);
+
   JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
   
   global = JSContextGetGlobalObject(nctx);
diff --git a/libseed/seed-closure.c b/libseed/seed-closure.c
index 6883b81..825c153 100644
--- a/libseed/seed-closure.c
+++ b/libseed/seed-closure.c
@@ -50,6 +50,8 @@ seed_handle_closure (ffi_cif * cif, void *result, void **args, void *userdata)
   GArgument rarg;
   GArgument return_arg;
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
+  
+  seed_prepare_global_context (ctx);
 
   SEED_NOTE (INVOCATION, "Invoking closure of type: %s \n",
 	     g_base_info_get_name ((GIBaseInfo *) privates->info));
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 09494f0..d320922 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -55,6 +55,16 @@ static const GDebugKey seed_debug_keys[] = {
 };
 #endif /* SEED_ENABLE_DEBUG */
 
+void
+seed_prepare_global_context (JSContextRef ctx)
+{
+  JSObjectRef global = JSContextGetGlobalObject (ctx);
+  
+  seed_object_set_property (ctx, global, "imports", importer);
+  seed_object_set_property (ctx, global, "GType", seed_gtype_constructor);
+  seed_object_set_property (ctx, global, "Seed", seed_obj_ref);
+}
+
 static JSObjectRef
 seed_struct_constructor_invoked (JSContextRef ctx,
 				 JSObjectRef constructor,
@@ -1450,7 +1460,6 @@ seed_parse_args (int *argc, char ***argv)
 SeedEngine *
 seed_init (gint * argc, gchar *** argv)
 {
-  JSObjectRef seed_obj_ref;
   JSStringRef defaults_script;
 
   g_type_init ();
diff --git a/libseed/seed-engine.h b/libseed/seed-engine.h
index 03d3285..a9417dc 100644
--- a/libseed/seed-engine.h
+++ b/libseed/seed-engine.h
@@ -61,4 +61,6 @@ void seed_repl_expose (JSContextRef ctx, ...);
 
 typedef JSObjectRef (*SeedModuleInitCallback) (SeedEngine * eng);
 
+void seed_prepare_global_context (JSContextRef ctx);
+
 #endif
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index d79257e..fef10ed 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -193,6 +193,8 @@ seed_gtype_builtin_set_property (GObject * object,
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
   gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
   JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
+  
+  seed_prepare_global_context (ctx);
 
   seed_object_set_property (ctx,
 			    jsobj,
@@ -216,6 +218,8 @@ seed_gtype_builtin_get_property (GObject * object,
   JSValueRef jsval = seed_object_get_property (ctx, jsobj,
 					       name);
 
+  seed_prepare_global_context (ctx);
+
   seed_gvalue_from_seed_value (ctx, jsval, spec->value_type, value, 0);
 
   g_free (name);
@@ -261,6 +265,8 @@ seed_handle_class_init_closure (ffi_cif * cif,
 						   0);
   GObjectClass *klass = *(GObjectClass **) args[0];
 
+  seed_prepare_global_context (ctx);
+
   klass->get_property = seed_gtype_get_property;
   klass->set_property = seed_gtype_set_property;
 
@@ -300,6 +306,8 @@ seed_handle_instance_init_closure (ffi_cif * cif,
 
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
 
+  seed_prepare_global_context (ctx);
+
   jsargs = seed_make_pointer (ctx, *(gpointer *) args[1]);
   this_object =
     (JSObjectRef) seed_value_from_object (ctx, *(GObject **) args[0], 0);
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index d85db77..7f2b40c 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -540,19 +540,12 @@ seed_importer_handle_file (JSContextRef ctx,
 
   file_contents = JSStringCreateWithUTF8CString (walk);
   file_name = JSStringCreateWithUTF8CString (file);
-
   
   nctx = JSGlobalContextCreateInGroup (context_group, 0);
-  global = JSContextGetGlobalObject (nctx);
-  // Set some objects that need to be available globally.
-  // Needs to be elsewhere...so that there can be some consistency
-  seed_object_set_property (nctx, global, "imports", importer);
-  seed_object_set_property (nctx, global, "GType", seed_gtype_constructor);
-  seed_object_set_property (nctx, global, "Seed", seed_obj_ref);
-
+  seed_prepare_global_context (nctx);
+  
   JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
 
-
   g_hash_table_insert (file_imports, file_path, global);
   // Does leak...but it's a debug statement.
   SEED_NOTE (IMPORTER, "Evaluated file, exception: %s", 
diff --git a/libseed/seed-importer.h b/libseed/seed-importer.h
index 1cf7d8b..174f801 100644
--- a/libseed/seed-importer.h
+++ b/libseed/seed-importer.h
@@ -3,6 +3,8 @@
 
 #include "seed-private.h"
 
+extern JSObjectRef importer;
+
 void seed_initialize_importer (JSContextRef ctx, JSObjectRef global);
 
 #endif
diff --git a/libseed/seed-signals.c b/libseed/seed-signals.c
index e37e177..1127bec 100644
--- a/libseed/seed-signals.c
+++ b/libseed/seed-signals.c
@@ -43,7 +43,7 @@ closure_invalidated (gpointer data, GClosure * c)
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group,
 						   0);
   SeedClosure *closure = (SeedClosure *) c;
-
+  
   SEED_NOTE (FINALIZATION, "Finalizing closure.");
 /*
   WebKit bug?
@@ -183,6 +183,8 @@ seed_signal_marshal_func (GClosure * closure,
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group,
 						   0);
 
+  seed_prepare_global_context (ctx);
+
   args = g_newa (JSValueRef, n_param_values + 1);
 
   for (i = 0; i < n_param_values; i++)
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index d4fcf28..4dc0ad2 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -1233,10 +1233,11 @@ seed_object_set_property (JSContextRef ctx, JSObjectRef object,
 			  const gchar * name, JSValueRef value)
 {
   JSStringRef jname = JSStringCreateWithUTF8CString (name);
+  JSValueRef exception = NULL;
 
   if (value)
     {
-      JSObjectSetProperty (ctx, (JSObjectRef) object, jname, value, 0, 0);
+      JSObjectSetProperty (ctx, (JSObjectRef) object, jname, value, 0, &exception);
     }
 
   JSStringRelease (jname);



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