[seed] seed_prepare_global_context: don't include Seed.js if not needed



commit c4ee2c531c577622b61d4bb4b8908d186f69be83
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Fri Mar 29 20:59:45 2013 +0800

    seed_prepare_global_context: don't include Seed.js if not needed
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696547

 libseed/seed-engine.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 8a924f2..3870fb0 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -99,6 +99,7 @@ void
 seed_prepare_global_context (JSContextRef ctx)
 {
   JSObjectRef global = JSContextGetGlobalObject (ctx);
+  JSStringRef check_sprintf =  JSStringCreateWithUTF8CString ("sprintf");
 
   seed_object_set_property (ctx, global, "imports", importer);
   seed_object_set_property (ctx, global, "GType", seed_gtype_constructor);
@@ -106,8 +107,11 @@ seed_prepare_global_context (JSContextRef ctx)
   seed_object_set_property (ctx, global, "print", seed_print_ref);
   seed_object_set_property (ctx, global, "printerr", seed_printerr_ref);
 
-
-  JSEvaluateScript (ctx, defaults_script, NULL, NULL, 0, NULL);
+  /* No need to re-import Seed.js if not needed. */
+  if (!JSObjectHasProperty( ctx, seed_obj_ref,  check_sprintf)) {
+    JSEvaluateScript (ctx, defaults_script, NULL, NULL, 0, NULL);
+  }
+  JSStringRelease (check_sprintf);
 }
 
 static JSObjectRef


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