Re: libseed-list __script_path__ in sandbox contexts
- From: Jonatan Liljedahl <lijon kymatica com>
- To: Seed - Gnome Javascript <libseed-list gnome org>
- Subject: Re: libseed-list __script_path__ in sandbox contexts
- Date: Wed, 30 Jun 2010 03:44:13 +0200
It needed some tweaking in case __script_path__ wasn't set. Updated patch:
diff --git a/modules/sandbox/seed-sandbox.c b/modules/sandbox/seed-sandbox.c
index b33e57d..967fc8d 100644
--- a/modules/sandbox/seed-sandbox.c
+++ b/modules/sandbox/seed-sandbox.c
@@ -84,6 +84,14 @@ 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);
+ SeedValue script_path = seed_object_get_property (ctx, global,
"__script_path__");
+ if(script_path && seed_value_is_object(ctx, script_path))
+ seed_object_set_property (c, g, "__script_path__", script_path);
+ else
+ seed_object_set_property (c, g, "__script_path__",
seed_make_undefined(ctx));
+
return seed_make_null (ctx);
}
Jonatan Liljedahl wrote:
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]