[gjs/wip/xulrunner-1.9.3-rebase7: 13/13] Replace "load context" with a "default global"



commit 1fbf4ec6b213d43945f99ebd66c9a9087835effa
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Sep 28 14:30:00 2010 -0400

    Replace "load context" with a "default global"
    
    The idea of the load context was to have a single context where modules
    and native were defined and shared between different JSContexts in the
    same runtime.
    
    But this caused context switching when loading modules, which isn't very
    tested in Spidermonkey and caused lots of use of gjs_move_exception()
    and other complications.
    
    Instead, switch to the idea of a default global object; this is the global
    object that is used in the scope chain for modules, and is also where the
    constructors for our native classes are stored, allowing native classes
    to be shared between different contexts.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622896

 Makefile.am            |    1 -
 gi/closure.c           |   15 +++--
 gi/enumeration.c       |    5 ++
 gi/function.c          |   18 +++---
 gi/keep-alive.c        |   69 +++++++++++-----------
 gi/keep-alive.h        |    5 +-
 gi/ns.c                |   33 ++++-------
 gi/object.c            |    8 +-
 gi/repo.c              |   56 ++++++++----------
 gjs/byteArray.c        |   15 ++---
 gjs/context.c          |   70 ++++++----------------
 gjs/importer.c         |   50 +++++++--------
 gjs/importer.h         |    2 +-
 gjs/jsapi-private.cpp  |    1 -
 gjs/jsapi-util.c       |  154 ++++++++++++++++++------------------------------
 gjs/jsapi-util.h       |   15 ++---
 gjs/stack.c            |    1 -
 modules/dbus-exports.c |   14 ++---
 18 files changed, 214 insertions(+), 318 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index f12fd70..c0d0e71 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,7 +29,6 @@ nobase_gjsinclude_HEADERS =	\
 
 noinst_HEADERS +=		\
 	gjs/compat.h		\
-	gjs/context-jsapi.h	\
 	gjs/jsapi-private.h	\
 	gjs/profiler.h		\
 	gjs/unit-test-utils.h	\
diff --git a/gi/closure.c b/gi/closure.c
index d88348b..f694cc7 100644
--- a/gi/closure.c
+++ b/gi/closure.c
@@ -326,12 +326,13 @@ gjs_closure_new(JSContext  *context,
 
     c = (Closure*) g_closure_new_simple(sizeof(Closure), NULL);
     c->runtime = JS_GetRuntime(context);
-    /* Closure are executed in our special "load-context" (one per runtime).
-     * This ensures that the context is still alive when the closure
-     * is invoked (as long as the runtime lives)
+    /* The saved context is used for lifetime management, so that the closure will
+     * be torn down with the context that created it. The context could be attached to
+     * the default context of the runtime using if we wanted the closure to survive
+     * the context that created it.
      */
-    c->context = gjs_runtime_get_load_context(c->runtime);
-    JS_BeginRequest(c->context);
+    c->context = context;
+    JS_BeginRequest(context);
 
     c->obj = callable;
     c->unref_on_global_object_finalized = FALSE;
@@ -342,7 +343,7 @@ gjs_closure_new(JSContext  *context,
      */
     g_closure_add_finalize_notifier(&c->base, NULL, closure_finalized);
 
-    gjs_keep_alive_add_global_child(c->context,
+    gjs_keep_alive_add_global_child(context,
                                     global_context_finalized,
                                     c->obj,
                                     c);
@@ -352,7 +353,7 @@ gjs_closure_new(JSContext  *context,
     gjs_debug_closure("Create closure %p which calls object %p '%s'",
                       c, c->obj, description);
 
-    JS_EndRequest(c->context);
+    JS_EndRequest(context);
 
     return &c->base;
 }
diff --git a/gi/enumeration.c b/gi/enumeration.c
index 9bdc8a2..3736031 100644
--- a/gi/enumeration.c
+++ b/gi/enumeration.c
@@ -141,6 +141,11 @@ gjs_define_enumeration(JSContext    *context,
     if (enum_obj == NULL)
         return JS_FALSE;
 
+    /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we
+     * can't just pass in the global as the parent */
+    JS_SetParent(context, enum_obj,
+                 gjs_get_default_global (context));
+
     /* Fill in enum values first, so we don't define the enum itself until we're
      * sure we can finish successfully.
      */
diff --git a/gi/function.c b/gi/function.c
index b56deb6..8517383 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -993,7 +993,7 @@ function_new(JSContext      *context,
     Function *priv;
 
     /* put constructor for GIRepositoryFunction() in the global namespace */
-    global = JS_GetGlobalObject(context);
+    global = gjs_get_default_global(context);
 
     if (!gjs_object_has_property(context, global, gjs_function_class.name)) {
         JSObject *prototype;
@@ -1032,7 +1032,7 @@ function_new(JSContext      *context,
                   gjs_function_class.name, prototype);
     }
 
-    function = JS_ConstructObject(context, &gjs_function_class, NULL, NULL);
+    function = JS_ConstructObject(context, &gjs_function_class, NULL, global);
     if (function == NULL) {
         gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to construct function");
         return NULL;
@@ -1051,16 +1051,14 @@ gjs_define_function(JSContext      *context,
                     GIFunctionInfo *info)
 {
     JSObject *function;
-    JSContext *load_context;
 
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
+    JS_BeginRequest(context);
 
-    function = function_new(load_context, info);
+    function = function_new(context, info);
     if (function == NULL) {
-        gjs_move_exception(load_context, context);
+        gjs_move_exception(context, context);
 
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return NULL;
     }
 
@@ -1071,11 +1069,11 @@ gjs_define_function(JSContext      *context,
                            GJS_MODULE_PROP_FLAGS)) {
         gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to define function");
 
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return NULL;
     }
 
-    JS_EndRequest(load_context);
+    JS_EndRequest(context);
     return function;
 }
 
diff --git a/gi/keep-alive.c b/gi/keep-alive.c
index fce6513..ab9e181 100644
--- a/gi/keep-alive.c
+++ b/gi/keep-alive.c
@@ -216,12 +216,17 @@ gjs_keep_alive_new(JSContext *context)
     JSObject *keep_alive;
     JSObject *global;
 
+    /* This function creates an unattached KeepAlive object; following our
+     * general strategy, we have a single KeepAlive class with a constructor
+     * stored on our single "load global" pseudo-global object, and we create
+     * instances with the load global as parent.
+     */
+
     g_assert(context != NULL);
 
     JS_BeginRequest(context);
 
-    /* put constructor in the global namespace */
-    global = JS_GetGlobalObject(context);
+    global = gjs_get_default_global(context);
 
     g_assert(global != NULL);
 
@@ -267,13 +272,6 @@ gjs_keep_alive_new(JSContext *context)
               "Creating new keep-alive object for context %p global %p",
               context, global);
 
-    /* Without the "global" parent object, this craters inside of
-     * xulrunner because in jsobj.c:js_ConstructObject it looks up
-     * VOID as the constructor.  Exploring in gdb, it is walking up
-     * the scope chain in a way that involves scary xpconnect-looking
-     * stuff. Having "global" as parent seems to fix it. But, it would
-     * not hurt to understand this better.
-     */
     keep_alive = JS_ConstructObject(context, &gjs_keep_alive_class, NULL, global);
     if (keep_alive == NULL) {
         gjs_log_exception(context, NULL);
@@ -349,42 +347,38 @@ gjs_keep_alive_remove_child(JSContext         *context,
 
 #define GLOBAL_KEEP_ALIVE_NAME "__gc_this_on_context_destroy"
 
-JSObject*
-gjs_keep_alive_get_global(JSContext *context)
+static JSObject*
+gjs_keep_alive_get_from_parent(JSContext *context,
+                               JSObject  *parent)
 {
     jsval value;
-    JSObject *global;
-    JSObject *result;
 
-    JS_BeginRequest(context);
-
-    global = JS_GetGlobalObject(context);
-
-    gjs_object_get_property(context, global, GLOBAL_KEEP_ALIVE_NAME, &value);
+    gjs_object_get_property(context, parent, GLOBAL_KEEP_ALIVE_NAME, &value);
 
     if (JSVAL_IS_OBJECT(value))
-        result = JSVAL_TO_OBJECT(value);
+        return JSVAL_TO_OBJECT(value);
     else
-        result = NULL;
-
-    JS_EndRequest(context);
+        return NULL;
+}
 
-    return result;
+JSObject*
+gjs_keep_alive_get_global(JSContext *context)
+{
+    return gjs_keep_alive_get_from_parent(context,
+                                          JS_GetGlobalObject(context));
 }
 
 static JSObject*
-gjs_keep_alive_create_in_global(JSContext *context)
+gjs_keep_alive_create_in_parent(JSContext *context,
+                                JSObject  *parent)
 {
     JSObject *keep_alive;
-    JSObject *global;
 
     JS_BeginRequest(context);
 
-    global = JS_GetGlobalObject(context);
-
     keep_alive = gjs_keep_alive_new(context);
 
-    if (!JS_DefineProperty(context, global,
+    if (!JS_DefineProperty(context, parent,
                            GLOBAL_KEEP_ALIVE_NAME,
                            OBJECT_TO_JSVAL(keep_alive),
                            NULL, NULL,
@@ -398,6 +392,13 @@ gjs_keep_alive_create_in_global(JSContext *context)
     return keep_alive;
 }
 
+static JSObject*
+gjs_keep_alive_create_in_global(JSContext *context)
+{
+    return gjs_keep_alive_create_in_parent(context,
+                                           JS_GetGlobalObject(context));
+}
+
 void
 gjs_keep_alive_add_global_child(JSContext         *context,
                                 GjsUnrootedFunc  notify,
@@ -447,21 +448,21 @@ gjs_keep_alive_remove_global_child(JSContext         *context,
 }
 
 JSObject*
-gjs_keep_alive_get_for_load_context(JSRuntime *runtime)
+gjs_keep_alive_get_for_default_global(JSContext *context)
 {
-    JSContext *context;
+    JSObject *global;
     JSObject *keep_alive;
 
-    context = gjs_runtime_get_load_context(runtime);
+    global = gjs_get_default_global(context);
 
-    g_assert(context != NULL);
+    g_assert(global != NULL);
 
     JS_BeginRequest(context);
 
-    keep_alive = gjs_keep_alive_get_global(context);
+    keep_alive = gjs_keep_alive_get_from_parent(context, global);
 
     if (!keep_alive)
-        keep_alive = gjs_keep_alive_create_in_global(context);
+        keep_alive = gjs_keep_alive_create_in_parent(context, global);
 
     if (!keep_alive)
         gjs_fatal("could not create keep_alive on global object, no memory?");
diff --git a/gi/keep-alive.h b/gi/keep-alive.h
index 7c4d0c2..82bc727 100644
--- a/gi/keep-alive.h
+++ b/gi/keep-alive.h
@@ -73,10 +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_default_global    (JSContext         *context);
 
 G_END_DECLS
 
diff --git a/gi/ns.c b/gi/ns.c
index df2e4b2..10c380e 100644
--- a/gi/ns.c
+++ b/gi/ns.c
@@ -71,7 +71,6 @@ ns_new_resolve(JSContext *context,
     const char *name;
     GIRepository *repo;
     GIBaseInfo *info;
-    JSContext *load_context;
 
     *objp = NULL;
 
@@ -89,8 +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));
-    JS_BeginRequest(load_context);
+    JS_BeginRequest(context);
 
     repo = g_irepository_get_default();
 
@@ -99,22 +97,21 @@ ns_new_resolve(JSContext *context,
         /* Special-case fallback hack for GParamSpec */
         if (strcmp(name, "ParamSpec") == 0 &&
             strcmp(priv->namespace, "GLib") == 0) {
-            gjs_define_param_class(load_context,
-                                   obj,
-                                   NULL);
-            if (gjs_move_exception(load_context, context)) {
-                JS_EndRequest(load_context);
+            if (!gjs_define_param_class(context,
+                                        obj,
+                                        NULL)) {
+                JS_EndRequest(context);
                 return JS_FALSE;
             } else {
                 *objp = obj; /* we defined the property in this object */
-                JS_EndRequest(load_context);
+                JS_EndRequest(context);
                 return JS_TRUE;
             }
         } else {
             gjs_throw(context,
                       "No symbol '%s' in namespace '%s'",
                       name, priv->namespace);
-            JS_EndRequest(load_context);
+            JS_EndRequest(context);
             return JS_FALSE;
         }
     }
@@ -125,10 +122,10 @@ ns_new_resolve(JSContext *context,
               g_base_info_get_name(info),
               g_base_info_get_namespace(info));
 
-    if (gjs_define_info(load_context, obj, info)) {
+    if (gjs_define_info(context, obj, info)) {
         g_base_info_unref(info);
         *objp = obj; /* we defined the property in this object */
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return JS_TRUE;
     } else {
         gjs_debug(GJS_DEBUG_GNAMESPACE,
@@ -137,13 +134,7 @@ ns_new_resolve(JSContext *context,
 
         g_base_info_unref(info);
 
-        if (!gjs_move_exception(load_context, context)) {
-            /* set an exception if none was set */
-            gjs_throw(context,
-                         "Defining info failed but no exception set");
-        }
-
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return JS_FALSE;
     }
 }
@@ -241,7 +232,7 @@ ns_new(JSContext    *context,
     Ns *priv;
 
     /* put constructor in the global namespace */
-    global = JS_GetGlobalObject(context);
+    global = gjs_get_default_global(context);
 
     if (!gjs_object_has_property(context, global, gjs_ns_class.name)) {
         JSObject *prototype;
@@ -276,7 +267,7 @@ ns_new(JSContext    *context,
                   gjs_ns_class.name, prototype);
     }
 
-    ns = JS_ConstructObject(context, &gjs_ns_class, NULL, NULL);
+    ns = JS_ConstructObject(context, &gjs_ns_class, NULL, global);
     if (ns == NULL)
         gjs_fatal("No memory to create ns object");
 
diff --git a/gi/object.c b/gi/object.c
index e5a3d0c..3850f62 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -557,13 +557,13 @@ wrapped_gobj_toggle_notify(gpointer      data,
 
     runtime = data;
 
-    /* The JSContext will be gone if runtime is being destroyed.
+    /* During teardown, this can return NULL if runtime is being destroyed.
      * In that case we effectively already converted to a weak ref without
      * doing anything since the keep alive will be collected.
      * 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 = gjs_runtime_get_current_context(runtime);
     if (!context)
         return;
 
@@ -595,7 +595,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_default_global(context);
             gjs_keep_alive_add_child(context, priv->keep_alive,
                                      gobj_no_longer_kept_alive_func,
                                      obj,
@@ -743,7 +743,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_default_global(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 adecae9..a68b2a9 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -60,28 +60,26 @@ resolve_namespace_object(JSContext  *context,
 {
     GIRepository *repo;
     GError *error;
-    JSContext *load_context;
     jsval versions_val;
     JSObject *versions;
     jsval version_val;
     const char *version;
     JSObject *result;
 
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
+    JS_BeginRequest(context);
 
-    if (!gjs_object_require_property(load_context, repo_obj, "GI repository object", "versions", &versions_val) ||
+    if (!gjs_object_require_property(context, repo_obj, "GI repository object", "versions", &versions_val) ||
         !JSVAL_IS_OBJECT(versions_val)) {
         gjs_throw(context, "No 'versions' property in GI repository object");
 
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return NULL;
     }
 
     versions = JSVAL_TO_OBJECT(versions_val);
 
     version = NULL;
-    if (JS_GetProperty(load_context, versions, ns_name, &version_val) &&
+    if (JS_GetProperty(context, versions, ns_name, &version_val) &&
         JSVAL_IS_STRING(version_val)) {
         version = gjs_string_get_ascii(version_val);
     }
@@ -95,8 +93,8 @@ resolve_namespace_object(JSContext  *context,
                   "Requiring %s, version %s: %s",
                   ns_name, version?version:"none", error->message);
         g_error_free(error);
-        JS_EndRequest(load_context);
-        return JS_FALSE;
+        JS_EndRequest(context);
+        return NULL;
     }
 
     /* Defines a property on "obj" (the javascript repo object)
@@ -104,7 +102,7 @@ resolve_namespace_object(JSContext  *context,
      * in the repo.
      */
     result = gjs_define_ns(context, repo_obj, ns_name, repo);
-    JS_EndRequest(load_context);
+    JS_EndRequest(context);
     return result;
 }
 
@@ -130,7 +128,6 @@ repo_new_resolve(JSContext *context,
 {
     Repo *priv;
     const char *name;
-    JSContext *load_context;
 
     *objp = NULL;
 
@@ -148,15 +145,13 @@ 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));
-    JS_BeginRequest(load_context);
-    resolve_namespace_object(load_context, obj, name);
-    if (gjs_move_exception(load_context, context)) {
-        JS_EndRequest(load_context);
+    JS_BeginRequest(context);
+    if (resolve_namespace_object(context, obj, name) == NULL) {
+        JS_EndRequest(context);
         return JS_FALSE;
     } else {
         *objp = obj; /* store the object we defined the prop in */
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return JS_TRUE;
     }
 }
@@ -247,9 +242,7 @@ repo_new(JSContext *context)
     JSObject *global;
     JSObject *versions;
 
-    /* We have to define the class in the global object so we can JS_ConstructObject */
-
-    global = JS_GetGlobalObject(context);
+    global = gjs_get_default_global(context);
 
     if (!gjs_object_has_property(context, global, gjs_repo_class.name)) {
         JSObject *prototype;
@@ -284,13 +277,16 @@ repo_new(JSContext *context)
                   gjs_repo_class.name, prototype);
     }
 
-    repo = JS_ConstructObject(context, &gjs_repo_class, NULL, NULL);
+    repo = JS_ConstructObject(context, &gjs_repo_class, NULL, global);
     if (repo == NULL) {
         gjs_throw(context, "No memory to create repo object");
         return JS_FALSE;
     }
 
     versions = JS_ConstructObject(context, NULL, NULL, NULL);
+    /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we
+     * can't just pass in the global as the parent */
+    JS_SetParent(context, versions, global);
 
     JS_DefineProperty(context, repo,
                       "versions",
@@ -506,7 +502,6 @@ JSObject*
 gjs_lookup_namespace_object_by_name(JSContext      *context,
                                     const char     *ns)
 {
-    JSContext *load_context;
     JSObject *global;
     JSObject *repo_obj;
     jsval importer;
@@ -515,26 +510,25 @@ gjs_lookup_namespace_object_by_name(JSContext      *context,
 
     /* This is a little bit of a hack, we hardcode an assumption that
      * the only repo object that exists is called "imports.gi" and is
-     * in the load context.
+     * is stored in the default global object.
      */
 
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
-    global = JS_GetGlobalObject(load_context);
+    JS_BeginRequest(context);
+    global = gjs_get_default_global(context);
 
     importer = JSVAL_VOID;
-    if (!gjs_object_require_property(load_context, global, "global object", "imports", &importer) ||
+    if (!gjs_object_require_property(context, global, "global object", "imports", &importer) ||
         !JSVAL_IS_OBJECT(importer)) {
-        gjs_log_exception(load_context, NULL);
+        gjs_log_exception(context, NULL);
         gjs_throw(context, "No imports property in global object");
         goto fail;
     }
 
     girepository = JSVAL_VOID;
-    if (!gjs_object_require_property(load_context, JSVAL_TO_OBJECT(importer), "importer",
+    if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(importer), "importer",
                                         "gi", &girepository) ||
         !JSVAL_IS_OBJECT(girepository)) {
-        gjs_log_exception(load_context, NULL);
+        gjs_log_exception(context, NULL);
         gjs_throw(context, "No gi property in importer");
         goto fail;
     }
@@ -550,11 +544,11 @@ gjs_lookup_namespace_object_by_name(JSContext      *context,
         goto fail;
     }
 
-    JS_EndRequest(load_context);
+    JS_EndRequest(context);
     return JSVAL_TO_OBJECT(ns_obj);
 
  fail:
-    JS_EndRequest(load_context);
+    JS_EndRequest(context);
     return NULL;
 }
 
diff --git a/gjs/byteArray.c b/gjs/byteArray.c
index 7924233..1200feb 100644
--- a/gjs/byteArray.c
+++ b/gjs/byteArray.c
@@ -856,9 +856,8 @@ JSBool
 gjs_define_byte_array_stuff(JSContext      *context,
                             JSObject       *in_object)
 {
-    JSContext *load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JSObject *global = JS_GetGlobalObject(context);
-    gjs_byte_array_prototype = JS_InitClass(load_context, global,
+    JSObject *global = gjs_get_default_global(context);
+    gjs_byte_array_prototype = JS_InitClass(context, global,
                              NULL,
                              &gjs_byte_array_class,
                              byte_array_constructor,
@@ -869,17 +868,13 @@ gjs_define_byte_array_stuff(JSContext      *context,
                              NULL);
     jsval rval;
 
-    if (gjs_byte_array_prototype == NULL) {
-        gjs_move_exception(load_context, context);
+    if (gjs_byte_array_prototype == NULL)
         return JS_FALSE;
-    }
 
     if (!gjs_object_require_property(
-            load_context, global, NULL,
-            "ByteArray", &rval)) {
-        gjs_move_exception(load_context, context);
+            context, global, NULL,
+            "ByteArray", &rval))
         return JS_FALSE;
-    }
 
     if (!JS_DefineProperty(context, in_object, "ByteArray",
                            rval, NULL, NULL, GJS_MODULE_PROP_FLAGS))
diff --git a/gjs/context.c b/gjs/context.c
index ef866e3..4079f6f 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -24,7 +24,6 @@
 #include <config.h>
 
 #include "context.h"
-#include "context-jsapi.h"
 #include "importer.h"
 #include "jsapi-util.h"
 #include "profiler.h"
@@ -65,7 +64,6 @@ struct _GjsContext {
     char **search_path;
 
     unsigned int we_own_runtime : 1;
-    unsigned int is_load_context : 1;
 };
 
 struct _GjsContextClass {
@@ -85,8 +83,7 @@ static int signals[LAST_SIGNAL];
 enum {
     PROP_0,
     PROP_SEARCH_PATH,
-    PROP_RUNTIME,
-    PROP_IS_LOAD_CONTEXT
+    PROP_RUNTIME
 };
 
 
@@ -325,10 +322,6 @@ gjs_context_class_init(GjsContextClass *klass)
                                  FALSE,
                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
-    g_object_class_install_property(object_class,
-                                    PROP_IS_LOAD_CONTEXT,
-                                    pspec);
-
     gjs_register_native_module("byteArray", gjs_define_byte_array_stuff, 0);
 }
 
@@ -351,8 +344,7 @@ gjs_context_dispose(GObject *object)
     if (js_context->context != NULL) {
 
         gjs_debug(GJS_DEBUG_CONTEXT,
-                  "Destroying JS context%s",
-                  js_context->is_load_context ? " (load context)" : "");
+                  "Destroying JS context");
 
         if (js_context->we_own_runtime)
             gjs_runtime_set_default_context(js_context->runtime, NULL);
@@ -362,11 +354,6 @@ gjs_context_dispose(GObject *object)
 
     if (js_context->runtime != NULL) {
         if (js_context->we_own_runtime) {
-            /* Avoid keeping JSContext with a dangling pointer to the
-             * runtime.
-             */
-            gjs_runtime_clear_load_context(js_context->runtime);
-
             gjs_debug(GJS_DEBUG_CONTEXT,
                       "Destroying JS runtime");
 
@@ -641,30 +628,24 @@ gjs_context_constructor (GType                  type,
             gjs_fatal("GjsContext created for a runtime not owned by GJS");
     }
 
-    /* If we created the root importer in the load context,
-     * there would be infinite recursion since the load context
-     * is a GjsContext
+    /* We create the global-to-runtime root importer with the
+     * passed-in search path. If someone else already created
+     * the root importer, this is a no-op.
      */
-    if (!js_context->is_load_context) {
-        /* We create the global-to-runtime root importer with the
-         * 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,
-                                      js_context->search_path ?
-                                      (const char**) js_context->search_path :
-                                      NULL,
-                                      TRUE))
-            gjs_fatal("Failed to create root importer");
-
-        /* 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,
-                                      js_context->global,
-                                      "imports"))
-            gjs_fatal("Failed to point 'imports' property at root importer");
-    }
+    if (!gjs_create_root_importer(js_context->context,
+                                  js_context->search_path ?
+                                  (const char**) js_context->search_path :
+                                  NULL,
+                                  TRUE))
+        gjs_fatal("Failed to create root importer");
+
+    /* 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,
+                                  js_context->global,
+                                  "imports"))
+        gjs_fatal("Failed to point 'imports' property at root importer");
 
     if (js_context->we_own_runtime) {
         js_context->profiler = gjs_profiler_new(js_context->runtime);
@@ -690,10 +671,6 @@ gjs_context_get_property (GObject     *object,
     js_context = GJS_CONTEXT (object);
 
     switch (prop_id) {
-    case PROP_IS_LOAD_CONTEXT:
-        g_value_set_boolean(value, js_context->is_load_context);
-        break;
-
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -717,9 +694,6 @@ gjs_context_set_property (GObject      *object,
     case PROP_RUNTIME:
         js_context->runtime = g_value_get_pointer(value);
         break;
-    case PROP_IS_LOAD_CONTEXT:
-        js_context->is_load_context = g_value_get_boolean(value);
-        break;
 
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -777,12 +751,6 @@ gjs_context_get_native_context (GjsContext *js_context)
 }
 
 gboolean
-gjs_context_is_load_context(GjsContext *js_context)
-{
-    return js_context->is_load_context;
-}
-
-gboolean
 gjs_context_eval(GjsContext *js_context,
                  const char   *script,
                  gssize        script_len,
diff --git a/gjs/importer.c b/gjs/importer.c
index 96050ff..78337f1 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -285,11 +285,16 @@ load_module_init(JSContext  *context,
         }
     }
 
-    module_obj = JS_ConstructObject(context, NULL, NULL, NULL);
+    module_obj = JS_NewObject(context, NULL, NULL, NULL);
     if (module_obj == NULL) {
         return JS_FALSE;
     }
 
+    /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we
+     * can't just pass in the global as the parent */
+    JS_SetParent(context, module_obj,
+                 gjs_get_default_global (context));
+
     /* Define module in importer for future use and to avoid module_obj
      * object to be garbage collected during the evaluation of the script */
     JS_DefineProperty(context, in_object,
@@ -915,7 +920,6 @@ importer_new_resolve(JSContext *context,
 {
     Importer *priv;
     const char *name;
-    JSContext *load_context;
 
     *objp = NULL;
 
@@ -934,21 +938,13 @@ importer_new_resolve(JSContext *context,
     if (priv == NULL)
         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));
-    JS_BeginRequest(load_context);
-    if (do_import(load_context, obj, priv, name)) {
+    JS_BeginRequest(context);
+    if (do_import(context, obj, priv, name)) {
         *objp = obj;
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return JS_TRUE;
     } else {
-        /* Move the exception to the calling context from load context.
-         */
-        if (!gjs_move_exception(load_context, context)) {
-            /* set an exception since none was set */
-            gjs_throw(context, "No exception was set, but import failed somehow");
-        }
-        JS_EndRequest(load_context);
+        JS_EndRequest(context);
         return JS_FALSE;
     }
 }
@@ -1040,7 +1036,7 @@ importer_new(JSContext    *context)
     Importer *priv;
     JSObject *global;
 
-    global = JS_GetGlobalObject(context);
+    global = gjs_get_default_global(context);
 
     if (!gjs_object_has_property(context, global, gjs_importer_class.name)) {
         JSObject *prototype;
@@ -1075,7 +1071,7 @@ importer_new(JSContext    *context)
                   gjs_importer_class.name, prototype);
     }
 
-    importer = JS_ConstructObject(context, &gjs_importer_class, NULL, NULL);
+    importer = JS_ConstructObject(context, &gjs_importer_class, NULL, global);
     if (importer == NULL)
         gjs_fatal("No memory to create ns object");
 
@@ -1188,20 +1184,20 @@ 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(JSContext   *context,
                          const char **initial_search_path,
                          gboolean     add_standard_search_path)
 {
-    JSContext *context;
+    JSObject *global;
 
-    context = gjs_runtime_get_load_context(runtime);
+    global = gjs_get_default_global(context);
 
     JS_BeginRequest(context);
 
     if (!gjs_object_has_property(context,
-                                 JS_GetGlobalObject(context),
+                                 global,
                                  "imports")) {
-        if (gjs_define_importer(context, JS_GetGlobalObject(context),
+        if (gjs_define_importer(context, global,
                                 "imports",
                                 initial_search_path, add_standard_search_path) == NULL) {
             JS_EndRequest(context);
@@ -1223,16 +1219,16 @@ gjs_define_root_importer(JSContext   *context,
                          JSObject    *in_object,
                          const char  *importer_name)
 {
-    JSContext *load_context;
+    JSObject *global;
     jsval value;
     JSBool success;
 
     success = JS_FALSE;
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
+    global = gjs_get_default_global(context);
+    JS_BeginRequest(context);
 
-    if (!gjs_object_require_property(load_context,
-                                     JS_GetGlobalObject(load_context), "global object",
+    if (!gjs_object_require_property(context,
+                                     global, "global object",
                                      "imports", &value) ||
         !JSVAL_IS_OBJECT(value)) {
         gjs_debug(GJS_DEBUG_IMPORTER, "Root importer did not exist, couldn't get from load context; must create it");
@@ -1250,6 +1246,6 @@ gjs_define_root_importer(JSContext   *context,
 
     success = JS_TRUE;
  fail:
-    JS_EndRequest(load_context);
+    JS_EndRequest(context);
     return success;
 }
diff --git a/gjs/importer.h b/gjs/importer.h
index 2bd99e0..0f3c964 100644
--- a/gjs/importer.h
+++ b/gjs/importer.h
@@ -34,7 +34,7 @@
 
 G_BEGIN_DECLS
 
-JSBool    gjs_create_root_importer (JSRuntime   *runtime,
+JSBool    gjs_create_root_importer (JSContext   *context,
                                     const char **initial_search_path,
                                     gboolean     add_standard_search_path);
 JSBool    gjs_define_root_importer (JSContext   *context,
diff --git a/gjs/jsapi-private.cpp b/gjs/jsapi-private.cpp
index 072ea6b..f1ac44e 100644
--- a/gjs/jsapi-private.cpp
+++ b/gjs/jsapi-private.cpp
@@ -29,7 +29,6 @@
 
 #include "jsapi-util.h"
 #include "jsapi-private.h"
-#include "context-jsapi.h"
 #include "compat.h"
 
 #include <string.h>
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index 47b26c8..33a8812 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -29,7 +29,6 @@
 #include <util/misc.h>
 
 #include "jsapi-util.h"
-#include "context-jsapi.h"
 #include "compat.h"
 #include "jsapi-private.h"
 
@@ -44,7 +43,7 @@ gjs_util_error_quark (void)
 typedef struct {
     GHashTable *dynamic_classes;
 
-    JSContext *default_context;
+    JSObject *default_global;
 
     JSContext *default_context;
 
@@ -76,54 +75,34 @@ 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.
+/**
+ * gjs_get_default_global:
+ * @context: a #JSContext
+ *
+ * Gets the default global object for the context's runtime. The default
+ * global object is the global object for the default context. It is used
+ * as the root object for the scope of modules loaded by GJS in this
+ * runtime, and should also be used as the globals 'obj' argument passed
+ * to JS_InitClass() and the parent argument passed to JS_ConstructObject()
+ * when creating a native classes that are shared between all contexts using
+ * the runtime. (The standard JS classes are not shared, but we share
+ * classes such as GObject proxy classes since objects of these classes can
+ * easily migrate between contexts and having different classes depending
+ * on the context where they were first accessed would be confusing.)
+ *
+ * Return value: the default global object GJS uses for the context's
+ *  runtime. Will never return %NULL while GJS has an active context
+ *  for the runtime.
  */
-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);
-}
-
-JSContext*
-gjs_runtime_peek_load_context(JSRuntime *runtime)
+JSObject*
+gjs_get_default_global(JSContext *context)
 {
-    GjsContext *context;
+    JSRuntime *runtime = JS_GetRuntime(context);
+    RuntimeData *rd;
 
-    context = gjs_runtime_get_data(runtime, "gjs-load-context");
-    if (context == NULL) {
-        return NULL;
-    } else {
-        return (JSContext*)gjs_context_get_native_context(context);
-    }
-}
+    rd = get_data_from_runtime(runtime);
 
-void
-gjs_runtime_clear_load_context(JSRuntime *runtime)
-{
-    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 rd->default_global;
 }
 
 /**
@@ -195,8 +174,10 @@ gjs_runtime_set_default_context(JSRuntime *runtime,
         if (rd->default_context != NULL)
             gjs_fatal("gjs_runtime_set_default_context() called twice on the same JSRuntime");
         rd->default_context = context;
+        rd->default_global = JS_GetGlobalObject(rd->default_context);
     } else {
         rd->default_context = NULL;
+        rd->default_global = NULL;
     }
 }
 
@@ -428,8 +409,8 @@ gjs_init_class_dynamic(JSContext      *context,
 {
     jsval value;
     char *private_name;
+    JSObject *global;
     JSObject *prototype;
-    JSContext *load_context;
 
     if (clasp->name != NULL) {
         g_warning("Dynamic class should not have a name in the JSClass struct");
@@ -438,14 +419,13 @@ gjs_init_class_dynamic(JSContext      *context,
 
     JS_BeginRequest(context);
 
-    /* We replace the passed-in context and global object with our
-     * runtime-global permanent load context. Otherwise, in a
-     * process with multiple contexts, we'd arbitrarily define
-     * the class in whatever global object initialized the
-     * class first, which is not desirable.
+    /* We use a special "fake" global object to store our constructors
+     * in for future use. Using the actual global object of the context would
+     * result in different contexts having different class definitions for
+     * the same GObject class; since the proxies are shared between all
+     * contexts, this would produce confusing results.
      */
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
+    global = gjs_get_default_global(context);
 
     /* JS_InitClass() wants to define the constructor in the global object, so
      * we give it a private and namespaced name... passing in the namespace
@@ -456,17 +436,17 @@ gjs_init_class_dynamic(JSContext      *context,
     private_name = g_strdup_printf("_private_%s_%s", ns_name, class_name);
 
     prototype = NULL;
-    if (gjs_object_get_property(load_context, JS_GetGlobalObject(load_context),
+    if (gjs_object_get_property(context, global,
                                 private_name, &value) &&
         JSVAL_IS_OBJECT(value)) {
         jsval proto_val;
 
         g_free(private_name); /* don't need it anymore */
 
-        if (!gjs_object_require_property(load_context, JSVAL_TO_OBJECT(value), NULL,
+        if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(value), NULL,
                                          "prototype", &proto_val) ||
             !JSVAL_IS_OBJECT(proto_val)) {
-            gjs_throw(load_context, "prototype was not defined or not an object?");
+            gjs_throw(context, "prototype was not defined or not an object?");
             goto error;
         }
         prototype = JSVAL_TO_OBJECT(proto_val);
@@ -474,7 +454,7 @@ gjs_init_class_dynamic(JSContext      *context,
         DynamicJSClass *class_copy;
         RuntimeData *rd;
 
-        rd = get_data_from_context(load_context);
+        rd = get_data_from_context(context);
 
         class_copy = g_slice_new0(DynamicJSClass);
         class_copy->base = *clasp;
@@ -492,7 +472,7 @@ gjs_init_class_dynamic(JSContext      *context,
                   "Initializing dynamic class %s %p",
                   class_name, class_copy);
 
-        prototype = JS_InitClass(load_context, JS_GetGlobalObject(load_context),
+        prototype = JS_InitClass(context, global,
                                  parent_proto, &class_copy->base,
                                  constructor, nargs,
                                  ps, fs,
@@ -501,7 +481,7 @@ gjs_init_class_dynamic(JSContext      *context,
         /* Retrieve the property again so we can define it in
          * in_object
          */
-        if (!gjs_object_require_property(load_context, JS_GetGlobalObject(load_context), NULL,
+        if (!gjs_object_require_property(context, global, NULL,
                                          class_copy->base.name, &value))
             goto error;
     }
@@ -511,26 +491,17 @@ gjs_init_class_dynamic(JSContext      *context,
     /* Now manually define our constructor with a sane name, in the
      * namespace object.
      */
-    if (!JS_DefineProperty(load_context, in_object,
+    if (!JS_DefineProperty(context, in_object,
                            class_name,
                            value,
                            NULL, NULL,
                            GJS_MODULE_PROP_FLAGS))
         goto error;
 
-    JS_EndRequest(load_context);
     JS_EndRequest(context);
     return prototype;
 
  error:
-    /* Move the exception to the calling context from load context.
-     */
-    if (!gjs_move_exception(load_context, context)) {
-        /* set an exception since none was set */
-        gjs_throw(context, "No exception was set, but class initialize failed somehow");
-    }
-
-    JS_EndRequest(load_context);
     JS_EndRequest(context);
     return NULL;
 }
@@ -641,26 +612,24 @@ gjs_construct_object_dynamic(JSContext      *context,
 {
     RuntimeData *rd;
     JSClass *proto_class;
-    JSContext *load_context;
+    JSObject *global;
     JSObject *result;
 
     JS_BeginRequest(context);
 
-    /* We replace the passed-in context and global object with our
-     * runtime-global permanent load context. Otherwise, JS_ConstructObject
-     * can't find the constructor in whatever random global object is set
-     * on the passed-in context.
+    /* We use the "default global" rather than the global object for the current
+     * object so that we fine the constructors we stored there in
+     * js_init_class_dynamic.
      */
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
+    global = gjs_get_default_global(context);
 
-    proto_class = JS_GET_CLASS(load_context, proto);
+    proto_class = JS_GET_CLASS(context, proto);
 
-    rd = get_data_from_context(load_context);
+    rd = get_data_from_context(context);
 
     /* Check that it's safe to cast to DynamicJSClass */
     if (g_hash_table_lookup(rd->dynamic_classes, proto_class) == NULL) {
-        gjs_throw(load_context, "Prototype is not for a dynamically-registered class");
+        gjs_throw(context, "Prototype is not for a dynamically-registered class");
         goto error;
     }
 
@@ -668,27 +637,24 @@ gjs_construct_object_dynamic(JSContext      *context,
                         "Constructing instance of dynamic class %s %p from proto %p",
                         proto_class->name, proto_class, proto);
 
+    /* Passing in the default global as 'parent' results in it being the global object
+     * used for looking up the constructor for the object. It also results in
+     * it being stored as the parent object of the newly constructed object.
+     * (Not necessarily sensible, but for something like creating the proxy object
+     * for a GObject more sensible than using the global object of the current context.)
+     */
     if (argc > 0)
-        result = JS_ConstructObjectWithArguments(load_context, proto_class, proto, NULL, argc, argv);
+        result = JS_ConstructObjectWithArguments(context, proto_class, proto, global, argc, argv);
     else
-        result = JS_ConstructObject(load_context, proto_class, proto, NULL);
+        result = JS_ConstructObject(context, proto_class, proto, global);
 
     if (!result)
         goto error;
 
-    JS_EndRequest(load_context);
     JS_EndRequest(context);
     return result;
 
  error:
-    /* Move the exception to the calling context from load context.
-     */
-    if (!gjs_move_exception(load_context, context)) {
-        /* set an exception since none was set */
-        gjs_throw(context, "No exception was set, but object construction failed somehow");
-    }
-
-    JS_EndRequest(load_context);
     JS_EndRequest(context);
     return NULL;
 }
@@ -838,7 +804,6 @@ void
 gjs_explain_scope(JSContext  *context,
                   const char *title)
 {
-    JSContext *load_context;
     JSObject *global;
     JSObject *parent;
     GString *chain;
@@ -847,17 +812,13 @@ gjs_explain_scope(JSContext  *context,
               "=== %s ===",
               title);
 
-    load_context = gjs_runtime_peek_load_context(JS_GetRuntime(context));
-
     JS_BeginRequest(context);
-    JS_BeginRequest(load_context);
 
     (void)JS_EnterLocalRootScope(context);
 
     gjs_debug(GJS_DEBUG_SCOPE,
               "  Context: %p %s",
               context,
-              context == load_context ? "(LOAD CONTEXT)" :
               "");
 
     global = JS_GetGlobalObject(context);
@@ -885,7 +846,6 @@ gjs_explain_scope(JSContext  *context,
 
     JS_LeaveLocalRootScope(context);
 
-    JS_EndRequest(load_context);
     JS_EndRequest(context);
 }
 
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 6796b53..7763e7c 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -164,11 +164,10 @@ 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)); \
-    JSObject *global = JS_GetGlobalObject(context); \
-    if (!gjs_object_has_property(load_context, global, \
+    JSObject *global = gjs_get_default_global(context); \
+    if (!gjs_object_has_property(context, global, \
                                  cname##_class.name)) { \
-        JSObject *prototype = JS_InitClass(load_context, global, \
+        JSObject *prototype = JS_InitClass(context, global, \
                                  parent, \
                                  &cname##_class, \
                                  ctor, \
@@ -178,13 +177,11 @@ jsval cname##_create_proto(JSContext *context, JSObject *module, const char *pro
                                  NULL, \
                                  NULL); \
         if (prototype == NULL) { \
-            gjs_move_exception(load_context, context); \
             return JSVAL_NULL; \
         } \
         if (!gjs_object_require_property( \
-                load_context, global, NULL, \
+                context, global, NULL, \
                 cname##_class.name, &rval)) { \
-            gjs_move_exception(load_context, context); \
             return JSVAL_NULL; \
         } \
     } \
@@ -209,9 +206,7 @@ JSContext*  gjs_runtime_get_default_context  (JSRuntime       *runtime);
 void        gjs_runtime_push_context         (JSRuntime       *runtime,
                                               JSContext       *context);
 void        gjs_runtime_pop_context          (JSRuntime       *runtime);
-JSContext*  gjs_runtime_get_load_context     (JSRuntime       *runtime);
-JSContext*  gjs_runtime_peek_load_context    (JSRuntime       *runtime);
-void        gjs_runtime_clear_load_context   (JSRuntime       *runtime);
+JSObject*   gjs_get_default_global           (JSContext       *context);
 gboolean    gjs_object_has_property          (JSContext       *context,
                                               JSObject        *obj,
                                               const char      *property_name);
diff --git a/gjs/stack.c b/gjs/stack.c
index 1254f92..5ae3b02 100644
--- a/gjs/stack.c
+++ b/gjs/stack.c
@@ -41,7 +41,6 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include <config.h>
-#include "context-jsapi.h"
 #include <glib.h>
 #include <string.h>
 #include <jsdbgapi.h>
diff --git a/modules/dbus-exports.c b/modules/dbus-exports.c
index 535bb9c..fca1851 100644
--- a/modules/dbus-exports.c
+++ b/modules/dbus-exports.c
@@ -1809,7 +1809,7 @@ exports_new(JSContext  *context,
     JSObject *global;
 
     /* put constructor for DBusExports() in the global namespace */
-    global = JS_GetGlobalObject(context);
+    global = gjs_get_default_global(context);
 
     if (!gjs_object_has_property(context, global, gjs_js_exports_class.name)) {
         JSObject *prototype;
@@ -1845,7 +1845,7 @@ exports_new(JSContext  *context,
                   gjs_js_exports_class.name, prototype);
     }
 
-    exports = JS_ConstructObject(context, &gjs_js_exports_class, NULL, NULL);
+    exports = JS_ConstructObject(context, &gjs_js_exports_class, NULL, global);
     /* may be NULL */
 
     return exports;
@@ -1857,16 +1857,14 @@ gjs_js_define_dbus_exports(JSContext      *context,
                            DBusBusType     which_bus)
 {
     JSObject *exports;
-    JSContext *load_context;
     JSBool success;
 
     success = JS_FALSE;
-    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
-    JS_BeginRequest(load_context);
+    JS_BeginRequest(context);
 
-    exports = exports_new(load_context, which_bus);
+    exports = exports_new(context, which_bus);
     if (exports == NULL) {
-        gjs_move_exception(load_context, context);
+        gjs_move_exception(context, context);
         goto fail;
     }
 
@@ -1882,6 +1880,6 @@ gjs_js_define_dbus_exports(JSContext      *context,
 
     success = JS_TRUE;
  fail:
-    JS_EndRequest(load_context);
+    JS_EndRequest(context);
     return success;
 }



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