[gjs/wip/xulrunner-1.9.3-rebase5: 16/26] jsapi-util: Avoid nesting contexts
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/xulrunner-1.9.3-rebase5: 16/26] jsapi-util: Avoid nesting contexts
- Date: Thu, 23 Sep 2010 00:05:23 +0000 (UTC)
commit 39021913f84d024d8a9b946eafb005299cad5b66
Author: Colin Walters <walters verbum org>
Date: Wed Sep 22 16:11:23 2010 -0400
jsapi-util: Avoid nesting contexts
From what I can tell, it's actually not valid to do so, invalidating
gjs' use of a "load" and "closure" context. Avoid nesting in
this one case anyways.
gjs/jsapi-util.c | 43 +++++++++++++++++++++++++------------------
1 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index e2f7f14..b2c53e6 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -961,30 +961,38 @@ gjs_move_exception(JSContext *src_context,
JSContext *dest_context)
{
JSBool success;
+ jsval exc;
JS_BeginRequest(src_context);
+
+ if (!JS_GetPendingException(src_context, &exc)) {
+ JS_EndRequest(src_context);
+ return JS_FALSE;
+ }
+ if (src_context == dest_context) {
+ JS_EndRequest(src_context);
+ return JS_TRUE;
+ }
+
+ JS_AddValueRoot(src_context, &exc);
+
+ JS_ClearPendingException(src_context);
+
JS_BeginRequest(dest_context);
/* NOTE: src and dest could be the same. */
- jsval exc;
- if (JS_GetPendingException(src_context, &exc)) {
- if (src_context != dest_context) {
- /* try to add the current stack of dest_context to the
- * stack trace of exc */
- try_to_chain_stack_trace(src_context, dest_context, exc);
- /* move the exception to dest_context */
- JS_SetPendingException(dest_context, exc);
- JS_ClearPendingException(src_context);
- }
- success = JS_TRUE;
- } else {
- success = JS_FALSE;
- }
+ /* try to add the current stack of dest_context to the
+ * stack trace of exc */
+ try_to_chain_stack_trace(src_context, dest_context, exc);
+ /* move the exception to dest_context */
+ JS_SetPendingException(dest_context, exc);
+
+ JS_RemoveValueRoot(src_context, &exc);
JS_EndRequest(dest_context);
JS_EndRequest(src_context);
- return success;
+ return JS_TRUE;
}
JSBool
@@ -999,16 +1007,15 @@ gjs_call_function_value(JSContext *context,
JSContext *call_context;
JS_BeginRequest(context);
-
call_context = gjs_runtime_get_call_context(JS_GetRuntime(context));
- JS_BeginRequest(call_context);
+ JS_EndRequest(context);
+ JS_BeginRequest(call_context);
result = JS_CallFunctionValue(call_context, obj, fval,
argc, argv, rval);
gjs_move_exception(call_context, context);
JS_EndRequest(call_context);
- JS_EndRequest(context);
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]