[gjs/wip/xulrunner-1.9.3-rebase5: 17/26] Drop load and call contexts
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/xulrunner-1.9.3-rebase5: 17/26] Drop load and call contexts
- Date: Thu, 23 Sep 2010 00:05:28 +0000 (UTC)
commit 68a10b030f458f37677d214bd48bf1ec6bba18f7
Author: Colin Walters <walters verbum org>
Date: Wed Sep 22 18:25:09 2010 -0400
Drop load and call contexts
Apparently for XULRunner embedding reasons, multiple different
contexts were added to gjs. We're using these in a way not really
intended by Spidermonkey. The default intended design is that there's
one JSContext * per thread.
In particular, stacking contexts is "dubious" in current Spidermonkey.
The stated rationale for the load and call contexts is unconvincing.
For the load context: If we want to e.g. avoid having modules loaded
multiple times even if run from a non-default context (and thus a
non-default global object), the obvious implementation technique is to
just hook them off the GjsRuntime default global object.
For the callback context: The rationale is just busted; we should
always use the default thread context, end of story.
gi/closure.c | 2 +-
gi/function.c | 2 +-
gi/keep-alive.c | 5 +--
gi/keep-alive.h | 2 +-
gi/ns.c | 2 +-
gi/object.c | 9 +++-
gi/repo.c | 6 +-
gjs/byteArray.c | 2 +-
gjs/context.c | 7 +--
gjs/importer.c | 12 +++--
gjs/importer.h | 4 +-
gjs/jsapi-util.c | 115 +++++-------------------------------------------
gjs/jsapi-util.h | 9 +---
modules/dbus-exports.c | 2 +-
14 files changed, 41 insertions(+), 138 deletions(-)
---
diff --git a/gi/closure.c b/gi/closure.c
index 3eb5a33..531b97b 100644
--- a/gi/closure.c
+++ b/gi/closure.c
@@ -360,7 +360,7 @@ gjs_closure_new(JSContext *context,
* This ensures that the context is still alive when the closure
* is invoked (as long as the runtime lives)
*/
- c->context = gjs_runtime_get_load_context(c->runtime);
+ c->context = gjs_runtime_get_load_context(context);
JS_BeginRequest(c->context);
c->obj = callable;
diff --git a/gi/function.c b/gi/function.c
index b8aa2a0..3b29a73 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -1038,7 +1038,7 @@ gjs_define_function(JSContext *context,
JSObject *function;
JSContext *load_context;
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
function = function_new(load_context, info);
diff --git a/gi/keep-alive.c b/gi/keep-alive.c
index 8e2c4ab..30e84d5 100644
--- a/gi/keep-alive.c
+++ b/gi/keep-alive.c
@@ -446,13 +446,10 @@ gjs_keep_alive_remove_global_child(JSContext *context,
}
JSObject*
-gjs_keep_alive_get_for_load_context(JSRuntime *runtime)
+gjs_keep_alive_get_for_load_context(JSContext *context)
{
- JSContext *context;
JSObject *keep_alive;
- context = gjs_runtime_get_load_context(runtime);
-
g_assert(context != NULL);
JS_BeginRequest(context);
diff --git a/gi/keep-alive.h b/gi/keep-alive.h
index 7c4d0c2..c337573 100644
--- a/gi/keep-alive.h
+++ b/gi/keep-alive.h
@@ -73,7 +73,7 @@ void gjs_keep_alive_remove_global_child (JSContext *context,
GjsUnrootedFunc notify,
JSObject *child,
void *data);
-JSObject* gjs_keep_alive_get_for_load_context (JSRuntime *runtime);
+JSObject* gjs_keep_alive_get_for_load_context (JSContext *context);
diff --git a/gi/ns.c b/gi/ns.c
index 85652dd..d89ce23 100644
--- a/gi/ns.c
+++ b/gi/ns.c
@@ -88,7 +88,7 @@ ns_new_resolve(JSContext *context,
if (priv == NULL)
return JS_TRUE; /* we are the prototype, or have the wrong class */
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
repo = g_irepository_get_default();
diff --git a/gi/object.c b/gi/object.c
index caacce5..4226f21 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -566,7 +566,10 @@ wrapped_gobj_toggle_notify(gpointer data,
* Or if !is_last_ref, we do not want to convert to a strong
* ref since we want everything collected on runtime destroy.
*/
- context = gjs_runtime_peek_load_context(runtime);
+ {
+ context = NULL;
+ JS_ContextIterator(runtime, &context);
+ }
if (!context)
return;
@@ -598,7 +601,7 @@ wrapped_gobj_toggle_notify(gpointer data,
*/
if (priv->keep_alive == NULL) {
gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "Adding object to keep alive");
- priv->keep_alive = gjs_keep_alive_get_for_load_context(runtime);
+ priv->keep_alive = gjs_keep_alive_get_for_load_context(context);
gjs_keep_alive_add_child(context, priv->keep_alive,
gobj_no_longer_kept_alive_func,
obj,
@@ -746,7 +749,7 @@ object_instance_constructor(JSContext *context,
* the wrapper to be garbage collected (and thus unref the
* wrappee).
*/
- priv->keep_alive = gjs_keep_alive_get_for_load_context(JS_GetRuntime(context));
+ priv->keep_alive = gjs_keep_alive_get_for_load_context(context);
gjs_keep_alive_add_child(context,
priv->keep_alive,
gobj_no_longer_kept_alive_func,
diff --git a/gi/repo.c b/gi/repo.c
index cff1b24..daa256d 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -66,7 +66,7 @@ resolve_namespace_object(JSContext *context,
const char *version;
JSObject *result;
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
if (!gjs_object_require_property(load_context, repo_obj, "GI repository object", "versions", &versions_val) ||
@@ -147,7 +147,7 @@ repo_new_resolve(JSContext *context,
if (priv == NULL)
return JS_TRUE; /* we are the prototype, or have the wrong class */
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
resolve_namespace_object(load_context, obj, name);
if (gjs_move_exception(load_context, context)) {
@@ -517,7 +517,7 @@ gjs_lookup_namespace_object_by_name(JSContext *context,
* in the load context.
*/
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
global = JS_GetGlobalObject(load_context);
diff --git a/gjs/byteArray.c b/gjs/byteArray.c
index 13ef2f3..7397ff1 100644
--- a/gjs/byteArray.c
+++ b/gjs/byteArray.c
@@ -843,7 +843,7 @@ JSBool
gjs_define_byte_array_stuff(JSContext *context,
JSObject *in_object)
{
- JSContext *load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ JSContext *load_context = gjs_runtime_get_load_context(context);
JSObject *global = JS_GetGlobalObject(context);
gjs_byte_array_prototype = JS_InitClass(load_context, global,
NULL,
diff --git a/gjs/context.c b/gjs/context.c
index fa23ad5..eecbe99 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -372,9 +372,6 @@ gjs_context_dispose(GObject *object)
/* Avoid keeping JSContext with a dangling pointer to the
* runtime.
*/
- gjs_runtime_clear_call_context(js_context->runtime);
- gjs_runtime_clear_load_context(js_context->runtime);
-
gjs_debug(GJS_DEBUG_CONTEXT,
"Destroying JS runtime");
@@ -657,7 +654,7 @@ gjs_context_constructor (GType type,
* passed-in search path. If someone else already created
* the root importer, this is a no-op.
*/
- if (!gjs_create_root_importer(js_context->runtime,
+ if (!gjs_create_root_importer(js_context,
js_context->search_path ?
(const char**) js_context->search_path :
NULL,
@@ -667,7 +664,7 @@ gjs_context_constructor (GType type,
/* Now copy the global root importer (which we just created,
* if it didn't exist) to our global object
*/
- if (!gjs_define_root_importer(js_context->context,
+ if (!gjs_define_root_importer(js_context,
js_context->global,
"imports"))
gjs_fatal("Failed to point 'imports' property at root importer");
diff --git a/gjs/importer.c b/gjs/importer.c
index 90972dd..5b9e53b 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -935,7 +935,7 @@ importer_new_resolve(JSContext *context,
return JS_TRUE; /* we are the prototype, or have the wrong class */
/* We always import in the special load context. */
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
if (do_import(load_context, obj, priv, name)) {
*objp = obj;
@@ -1188,13 +1188,13 @@ gjs_define_importer(JSContext *context,
* we just ignore all calls after the first and hope the args are the same.
*/
JSBool
-gjs_create_root_importer(JSRuntime *runtime,
+gjs_create_root_importer(GjsContext *gjs_context,
const char **initial_search_path,
gboolean add_standard_search_path)
{
JSContext *context;
- context = gjs_runtime_get_load_context(runtime);
+ context = gjs_context_get_native_context(gjs_context);
JS_BeginRequest(context);
@@ -1219,16 +1219,18 @@ gjs_create_root_importer(JSRuntime *runtime,
}
JSBool
-gjs_define_root_importer(JSContext *context,
+gjs_define_root_importer(GjsContext *gjs_context,
JSObject *in_object,
const char *importer_name)
{
JSContext *load_context;
+ JSContext *context;
jsval value;
JSBool success;
success = JS_FALSE;
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_context_get_native_context(gjs_context);
+ context = load_context;
JS_BeginRequest(load_context);
if (!gjs_object_require_property(load_context,
diff --git a/gjs/importer.h b/gjs/importer.h
index 2bd99e0..50e7753 100644
--- a/gjs/importer.h
+++ b/gjs/importer.h
@@ -34,10 +34,10 @@
G_BEGIN_DECLS
-JSBool gjs_create_root_importer (JSRuntime *runtime,
+JSBool gjs_create_root_importer (GjsContext *context,
const char **initial_search_path,
gboolean add_standard_search_path);
-JSBool gjs_define_root_importer (JSContext *context,
+JSBool gjs_define_root_importer (GjsContext *context,
JSObject *in_object,
const char *importer_name);
JSObject* gjs_define_importer (JSContext *context,
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index b2c53e6..ab69e9f 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -65,110 +65,18 @@ gjs_runtime_set_data(JSRuntime *runtime,
g_dataset_set_data_full(runtime, name, data, dnotify);
}
-/* The "load context" is the one we use for loading
- * modules and initializing classes.
- */
-JSContext*
-gjs_runtime_get_load_context(JSRuntime *runtime)
-{
- GjsContext *context;
-
- context = gjs_runtime_get_data(runtime, "gjs-load-context");
- if (context == NULL) {
- gjs_debug(GJS_DEBUG_CONTEXT,
- "Creating load context for runtime %p",
- runtime);
- context = g_object_new(GJS_TYPE_CONTEXT,
- "runtime", runtime,
- "is-load-context", TRUE,
- NULL);
- gjs_runtime_set_data(runtime,
- "gjs-load-context",
- context,
- g_object_unref);
- }
-
- return (JSContext*)gjs_context_get_native_context(context);
-}
-
+/* Historical note: There is no separate load context anymore. */
JSContext*
-gjs_runtime_peek_load_context(JSRuntime *runtime)
-{
- GjsContext *context;
-
- context = gjs_runtime_get_data(runtime, "gjs-load-context");
- if (context == NULL) {
- return NULL;
- } else {
- return (JSContext*)gjs_context_get_native_context(context);
- }
-}
-
-void
-gjs_runtime_clear_load_context(JSRuntime *runtime)
+gjs_runtime_get_load_context(JSContext *context)
{
- gjs_debug(GJS_DEBUG_CONTEXT, "Clearing load context");
- gjs_runtime_set_data(runtime,
- "gjs-load-context",
- NULL,
- NULL);
- gjs_debug(GJS_DEBUG_CONTEXT, "Load context cleared");
+ return context;
}
-/* The call context exists because when we call a closure, the scope
- * chain on the context is set to the original scope chain of the
- * closure. We want to avoid using any existing context (especially
- * the load context) because the closure "messes up" the scope chain
- * on the context.
- *
- * Unlike the load context, which is expected to be an eternal
- * singleton, we only cache the call context for efficiency. It would
- * be just as workable to recreate it for each call.
- */
+/* Historical note: There is no separate call context anymore. */
JSContext*
-gjs_runtime_get_call_context(JSRuntime *runtime)
-{
- GjsContext *context;
-
- context = gjs_runtime_get_data(runtime, "gjs-call-context");
- if (context == NULL) {
- gjs_debug(GJS_DEBUG_CONTEXT,
- "Creating call context for runtime %p",
- runtime);
- context = g_object_new(GJS_TYPE_CONTEXT,
- "runtime", runtime,
- NULL);
- gjs_runtime_set_data(runtime,
- "gjs-call-context",
- context,
- g_object_unref);
- }
-
- return (JSContext*)gjs_context_get_native_context(context);
-}
-
-static JSContext*
-gjs_runtime_peek_call_context(JSRuntime *runtime)
-{
- GjsContext *context;
-
- context = gjs_runtime_get_data(runtime, "gjs-call-context");
- if (context == NULL) {
- return NULL;
- } else {
- return (JSContext*)gjs_context_get_native_context(context);
- }
-}
-
-void
-gjs_runtime_clear_call_context(JSRuntime *runtime)
+gjs_runtime_get_call_context(JSContext *context)
{
- gjs_debug(GJS_DEBUG_CONTEXT, "Clearing call context");
- gjs_runtime_set_data(runtime,
- "gjs-call-context",
- NULL,
- NULL);
- gjs_debug(GJS_DEBUG_CONTEXT, "Call context cleared");
+ return context;
}
static void
@@ -335,7 +243,7 @@ gjs_init_class_dynamic(JSContext *context,
* the class in whatever global object initialized the
* class first, which is not desirable.
*/
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
/* JS_InitClass() wants to define the constructor in the global object, so
@@ -542,7 +450,7 @@ gjs_construct_object_dynamic(JSContext *context,
* can't find the constructor in whatever random global object is set
* on the passed-in context.
*/
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
proto_class = JS_GET_CLASS(load_context, proto);
@@ -743,8 +651,8 @@ gjs_explain_scope(JSContext *context,
"=== %s ===",
title);
- load_context = gjs_runtime_peek_load_context(JS_GetRuntime(context));
- call_context = gjs_runtime_peek_call_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
+ call_context = gjs_runtime_get_call_context(context);
JS_BeginRequest(context);
JS_BeginRequest(load_context);
@@ -960,7 +868,6 @@ JSBool
gjs_move_exception(JSContext *src_context,
JSContext *dest_context)
{
- JSBool success;
jsval exc;
JS_BeginRequest(src_context);
@@ -1007,7 +914,7 @@ gjs_call_function_value(JSContext *context,
JSContext *call_context;
JS_BeginRequest(context);
- call_context = gjs_runtime_get_call_context(JS_GetRuntime(context));
+ call_context = gjs_runtime_get_call_context(context);
JS_EndRequest(context);
JS_BeginRequest(call_context);
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 9921805..2cf98de 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -164,7 +164,7 @@ static struct JSClass cname##_class = { \
jsval cname##_create_proto(JSContext *context, JSObject *module, const char *proto_name, JSObject *parent) \
{ \
jsval rval; \
- JSContext *load_context = gjs_runtime_get_load_context(JS_GetRuntime(context)); \
+ JSContext *load_context = gjs_runtime_get_load_context(context); \
JSObject *global = JS_GetGlobalObject(context); \
if (!gjs_object_has_property(load_context, global, \
cname##_class.name)) { \
@@ -201,11 +201,8 @@ void gjs_runtime_set_data (JSRuntime *runtime,
const char *name,
void *data,
GDestroyNotify dnotify);
-JSContext* gjs_runtime_get_load_context (JSRuntime *runtime);
-JSContext* gjs_runtime_peek_load_context (JSRuntime *runtime);
-void gjs_runtime_clear_load_context (JSRuntime *runtime);
-JSContext* gjs_runtime_get_call_context (JSRuntime *runtime);
-void gjs_runtime_clear_call_context (JSRuntime *runtime);
+JSContext* gjs_runtime_get_load_context (JSContext *origin);
+JSContext* gjs_runtime_get_call_context (JSContext *origin);
gboolean gjs_object_has_property (JSContext *context,
JSObject *obj,
const char *property_name);
diff --git a/modules/dbus-exports.c b/modules/dbus-exports.c
index 99259a0..3a3abee 100644
--- a/modules/dbus-exports.c
+++ b/modules/dbus-exports.c
@@ -1864,7 +1864,7 @@ gjs_js_define_dbus_exports(JSContext *context,
JSBool success;
success = JS_FALSE;
- load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ load_context = gjs_runtime_get_load_context(context);
JS_BeginRequest(load_context);
exports = exports_new(load_context, which_bus);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]