Top |
SeedGlobalContext | seed_context_create () |
SeedGlobalContext | seed_context_ref () |
void | seed_context_unref () |
void | seed_context_collect () |
SeedObject | seed_context_get_global_object () |
void | seed_prepare_global_context () |
void | seed_importer_add_global () |
void | seed_importer_set_search_path () |
A SeedContext provides a complete "universe" for the execution of JavaScript. You can use seed_context_create()
to create a sandboxed context that lacks the import system, so it can be used to execute somewhat untrusted JavaScript (as it has no way to access the rest of your system). You can also expose the default set of globals (including "print", "imports", and "Seed") to create more powerful but still self-contained environments within which to execute code.
Example 6. Using a Seed context as a form of sandboxing
1 2 3 4 5 |
... ctx = seed_context_create(NULL, NULL); script = seed_make_script(ctx, "print(imports)", NULL, 0); // nothing is printed, because imports is undefined, because we're in a sandbox ... |
The sandbox module provides access to this system from the JavaScript side of Seed.
SeedGlobalContext seed_context_create (SeedContextGroup group
,SeedClass global_class
);
Create a new SeedContext. By default, this creates a new context
which has no global objects; you can add the default set using
seed_prepare_global_context()
.
group |
A SeedContextGroup in which to create the new context, or |
|
global_class |
The SeedClass to use to create the global object, or |
SeedGlobalContext
seed_context_ref (SeedGlobalContext ctx
);
Increments the reference count of ctx
.
void
seed_context_unref (SeedGlobalContext ctx
);
Decrements the reference count of ctx
.
void
seed_context_collect (SeedGlobalContext ctx
);
Instructs JavaScriptCore to make a garbage collection pass. The context parameter is currently unused, and a pass is made through all contexts.
void
seed_prepare_global_context (SeedContext ctx
);
Adds the default set of global objects (imports, GType, Seed, and print) to a fresh SeedContext.
void seed_importer_set_search_path (SeedContext ctx
,gchar **search_path
);