[seed] Allow access to global object of sandbox



commit a7d0f88b19e1142b9dafbe184bcb1d97a636dbf6
Author: Alan Knowles <alan alanfast akbkhome com>
Date:   Thu Mar 11 15:09:19 2010 +0800

    Allow access to global object of sandbox
    
    x = new imports.sandbox.Context();
    x.add_globals();
    x.get_global_object().a = "hello world";
    x.eval("Seed.print(a);");
    
    Very usefull to implement a Console...

 modules/sandbox/seed-sandbox.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/modules/sandbox/seed-sandbox.c b/modules/sandbox/seed-sandbox.c
index b33e57d..6c5b46c 100644
--- a/modules/sandbox/seed-sandbox.c
+++ b/modules/sandbox/seed-sandbox.c
@@ -87,6 +87,25 @@ seed_sandbox_context_add_globals (SeedContext ctx,
   return seed_make_null (ctx);
 }
 
+static SeedValue
+seed_sandbox_context_get_global_object (SeedContext ctx,
+				  SeedObject function,
+				  SeedObject this_object,
+				  size_t argument_count,
+				  const SeedValue arguments[],
+				  SeedException * exception)
+{
+  SeedContext c = seed_object_get_private (this_object);
+  if (!c)
+    {
+      seed_make_exception (ctx, exception,
+			   "ArgumentError", "Context is destroyed");
+      return seed_make_undefined (ctx);
+    }
+   
+
+   return seed_context_get_global_object  (c);
+}
 
 static SeedValue
 seed_sandbox_context_destroy (SeedContext ctx,
@@ -107,6 +126,7 @@ seed_static_function context_funcs[] = {
   {"eval", seed_context_eval, 0},
   {"add_globals", seed_sandbox_context_add_globals, 0},
   {"destroy", seed_sandbox_context_destroy, 0},
+  {"get_global_object", seed_sandbox_context_get_global_object },
   {NULL, NULL, 0}
 };
 



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