Re: libseed-list __script_path__ in sandbox contexts



This seems to work, now a script can do

c = new imports.sandbox.Context;
c.add_globals();
c.eval("foo = imports.foo");

and it will find 'foo' in same dir as above script.

/Jonatan

Jonatan Liljedahl wrote:
I think ctx.add_globals() should copy the __script_path__ so that doing imports in the new context does the '.' replacement trick. (Otherwise '.' will be interpreted as current directory)

Something like this:

diff --git a/modules/sandbox/seed-sandbox.c b/modules/sandbox/seed-sandbox.c
index b33e57d..a1c80a6 100644
--- a/modules/sandbox/seed-sandbox.c
+++ b/modules/sandbox/seed-sandbox.c
@@ -84,6 +84,10 @@ seed_sandbox_context_add_globals (SeedContext ctx,
     }
   seed_prepare_global_context (c);

+  SeedObject g = seed_context_get_global_object (c);
+  SeedObject global = seed_context_get_global_object (ctx);
+ seed_object_set_property (c, g, "__script_path__", seed_object_get_property (ctx, global, "__script_path__"));
+
   return seed_make_null (ctx);
 }

/Jonatan
_______________________________________________
libseed-list mailing list
libseed-list gnome org
http://mail.gnome.org/mailman/listinfo/libseed-list

>From e253b146fe5214a493a2a049e4eb4a7fe6e86d32 Mon Sep 17 00:00:00 2001
From: Jonatan Liljedahl <lijon kymatica com>
Date: Tue, 29 Jun 2010 19:51:21 +0200
Subject: [PATCH] Copy the __script_path__ in sandbox context.add_globals()

---
 modules/sandbox/seed-sandbox.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/modules/sandbox/seed-sandbox.c b/modules/sandbox/seed-sandbox.c
index b33e57d..a1c80a6 100644
--- a/modules/sandbox/seed-sandbox.c
+++ b/modules/sandbox/seed-sandbox.c
@@ -84,6 +84,10 @@ seed_sandbox_context_add_globals (SeedContext ctx,
     }
   seed_prepare_global_context (c);
 
+  SeedObject g = seed_context_get_global_object (c);
+  SeedObject global = seed_context_get_global_object (ctx);
+  seed_object_set_property (c, g, "__script_path__", seed_object_get_property (ctx, global, "__script_path__"));
+    
   return seed_make_null (ctx);
 }
 
-- 
1.6.3.3



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