[seed] Calling any JSCore method requiring a context from within an object finalization handler is invalid.
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Calling any JSCore method requiring a context from within an object finalization handler is invalid.
- Date: Mon, 11 May 2009 16:49:41 -0400 (EDT)
commit 608572c7ceb778338d5ddca736a344636cbcc283
Author: Robert Carr <racarr svn gnome org>
Date: Mon May 11 16:49:32 2009 -0400
Calling any JSCore method requiring a context from within an object finalization handler is invalid. As a result the sandbox module needs to be manually memory managed (with a destroy method). Closes BGO #582120
---
modules/sandbox/sandbox.c | 41 +++++++++++++++++++++++++++++++----------
1 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/modules/sandbox/sandbox.c b/modules/sandbox/sandbox.c
index 3125010..966ec91 100644
--- a/modules/sandbox/sandbox.c
+++ b/modules/sandbox/sandbox.c
@@ -33,6 +33,13 @@ seed_context_eval (SeedContext ctx,
SeedContext c = seed_object_get_private (this_object);
SeedValue ret;
gchar *s;
+
+ if (!c)
+ {
+ seed_make_exception (ctx, exception,
+ "ArgumentError", "Context is destroyed");
+ return seed_make_undefined (ctx);
+ }
s = seed_value_to_string (ctx, arguments[0], exception);
ret = seed_simple_evaluate (c, s, exception);
@@ -50,25 +57,40 @@ seed_sandbox_context_add_globals (SeedContext ctx,
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);
+ }
seed_prepare_global_context (c);
-
+
+ return seed_make_null (ctx);
+}
+
+
+static SeedValue
+seed_sandbox_context_destroy (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException * exception)
+{
+ SeedContext c = seed_object_get_private (this_object);
+
+ seed_context_unref (c);
+ seed_object_set_private (this_object, NULL);
return seed_make_null (ctx);
}
seed_static_function context_funcs[] = {
{"eval", seed_context_eval, 0},
{"add_globals", seed_sandbox_context_add_globals, 0},
+ {"destroy", seed_sandbox_context_destroy, 0},
{0, 0, 0}
};
-static void
-context_finalize (SeedObject object)
-{
- SeedContext *c = seed_object_get_private (object);
-
- seed_context_unref (c);
-}
-
SeedObject
seed_module_init(SeedEngine * eng)
{
@@ -81,7 +103,6 @@ seed_module_init(SeedEngine * eng)
context_class_def.class_name = "Context";
context_class_def.static_functions = context_funcs;
- context_class_def.finalize = context_finalize;
context_class = seed_create_class (&context_class_def);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]