[gjs: 3/25] js: Remove requests



commit e9a802d171129aac2ac06570848710ce61ada033
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat May 18 20:05:37 2019 -0700

    js: Remove requests
    
    JSAutoRequest, JS_BeginRequest(), and JS_EndRequest() are no longer
    necessary in SpiderMonkey 68. We can just remove them wherever they
    appear.

 gi/closure.cpp              |  4 ----
 gi/function.cpp             |  5 -----
 gi/gerror.cpp               |  2 --
 gi/gobject.cpp              |  3 ---
 gi/gtype.cpp                |  3 ---
 gi/ns.cpp                   |  2 --
 gi/object.cpp               |  4 ++--
 gi/private.cpp              |  4 ----
 gi/repo.cpp                 |  7 +------
 gi/value.cpp                |  1 -
 gi/wrapperutils.h           |  2 --
 gjs/context.cpp             | 15 ---------------
 gjs/coverage.cpp            |  2 --
 gjs/debugger.cpp            |  4 +---
 gjs/global.cpp              |  6 ------
 gjs/importer.cpp            |  2 --
 gjs/jsapi-class.h           |  1 -
 gjs/jsapi-dynamic-class.cpp |  4 ----
 gjs/jsapi-util-args.h       |  3 ---
 gjs/jsapi-util-error.cpp    |  5 -----
 gjs/jsapi-util-root.h       |  2 --
 gjs/jsapi-util-string.cpp   | 12 ------------
 gjs/jsapi-util.cpp          | 34 +++-------------------------------
 modules/system.cpp          |  8 +-------
 test/gjs-test-utils.cpp     |  3 ---
 25 files changed, 8 insertions(+), 130 deletions(-)
---
diff --git a/gi/closure.cpp b/gi/closure.cpp
index 860ca678..4e9ec3c8 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -195,7 +195,6 @@ gjs_closure_invoke(GClosure                   *closure,
     }
 
     context = c->context;
-    JSAutoRequest ar(context);
     JSAutoCompartment ac(context, JS_GetFunctionObject(c->func));
 
     if (JS_IsExceptionPending(context)) {
@@ -295,7 +294,6 @@ GClosure* gjs_closure_new(JSContext* context, JSFunction* callable,
      * the context that created it.
      */
     c->context = context;
-    JS_BeginRequest(context);
 
     GJS_INC_COUNTER(closure);
 
@@ -318,7 +316,5 @@ GClosure* gjs_closure_new(JSContext* context, JSFunction* callable,
     gjs_debug_closure("Create closure %p which calls function %p '%s'", gc,
                       c->func.debug_addr(), description);
 
-    JS_EndRequest(context);
-
     return &gc->base;
 }
diff --git a/gi/function.cpp b/gi/function.cpp
index 49681ac3..cc3df9b4 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -229,7 +229,6 @@ static void gjs_callback_closure(ffi_cif* cif G_GNUC_UNUSED, void* result,
         return;
     }
 
-    JS_BeginRequest(context);
     JSAutoCompartment ac(context, JS_GetFunctionObject(gjs_closure_get_callable(
                                       trampoline->js_function)));
 
@@ -474,8 +473,6 @@ out:
 
     gjs_callback_trampoline_unref(trampoline);
     gjs->schedule_gc_if_needed();
-
-    JS_EndRequest(context);
 }
 
 /* The global entry point for any invocations of GDestroyNotify;
@@ -1809,8 +1806,6 @@ gjs_define_function(JSContext       *context,
 
     info_type = g_base_info_get_type((GIBaseInfo *)info);
 
-    JSAutoRequest ar(context);
-
     JS::RootedObject function(context, function_new(context, gtype, info));
     if (!function)
         return NULL;
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index a1b1a546..7015683b 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -500,8 +500,6 @@ bool gjs_throw_gerror(JSContext* cx, GError* error) {
     // in the calling code, and the caller expects to throw.
     g_return_val_if_fail(error, false);
 
-    JSAutoRequest ar(cx);
-
     JS::RootedObject err_obj(cx, ErrorInstance::object_for_c_ptr(cx, error));
     if (!err_obj || !gjs_define_error_properties(cx, err_obj))
         return false;
diff --git a/gi/gobject.cpp b/gi/gobject.cpp
index 7a430255..d72f7ad6 100644
--- a/gi/gobject.cpp
+++ b/gi/gobject.cpp
@@ -106,7 +106,6 @@ static GObject* gjs_object_constructor(
      * Construct the JS object from the constructor, then use the GObject
      * that was associated in gjs_object_custom_init()
      */
-    JSAutoRequest ar(cx);
     JSAutoCompartment ac(cx, gjs_get_import_global(cx));
 
     JS::RootedObject constructor(
@@ -151,7 +150,6 @@ static void gjs_object_set_gproperty(GObject* object,
     JSContext *cx = current_context();
 
     JS::RootedObject js_obj(cx, priv->wrapper());
-    JSAutoRequest ar(cx);
     JSAutoCompartment ac(cx, js_obj);
 
     if (!jsobj_set_gproperty(cx, js_obj, value, pspec))
@@ -166,7 +164,6 @@ static void gjs_object_get_gproperty(GObject* object,
 
     JS::RootedObject js_obj(cx, priv->wrapper());
     JS::RootedValue jsvalue(cx);
-    JSAutoRequest ar(cx);
     JSAutoCompartment ac(cx, js_obj);
 
     GjsAutoChar underscore_name = gjs_hyphen_to_underscore(pspec->name);
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index a915bf66..948f2505 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -111,8 +111,6 @@ gjs_gtype_create_gtype_wrapper (JSContext *context,
     g_assert(((void) "Attempted to create wrapper object for invalid GType",
               gtype != 0));
 
-    JSAutoRequest ar(context);
-
     GjsContextPrivate* gjs = GjsContextPrivate::from_cx(context);
     auto p = gjs->gtype_table().lookupForAdd(gtype);
     if (p)
@@ -171,7 +169,6 @@ static bool _gjs_gtype_get_actual_gtype(JSContext* context,
 bool gjs_gtype_get_actual_gtype(JSContext* context, JS::HandleObject object,
                                 GType* gtype_out) {
     g_assert(gtype_out && "Missing return location");
-    JSAutoRequest ar(context);
 
     /* 2 means: recurse at most three times (including this
        call).
diff --git a/gi/ns.cpp b/gi/ns.cpp
index d66b5df3..bb4aea71 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -97,8 +97,6 @@ ns_resolve(JSContext       *context,
               "Found info type %s for '%s' in namespace '%s'",
               gjs_info_type_name(info.type()), info.name(), info.ns());
 
-    JSAutoRequest ar(context);
-
     if (!gjs_define_info(context, obj, info, &defined)) {
         gjs_debug(GJS_DEBUG_GNAMESPACE, "Failed to define info '%s'",
                   info.name());
diff --git a/gi/object.cpp b/gi/object.cpp
index 75b1dd58..c5fb697c 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1169,8 +1169,8 @@ static void wrapped_gobj_toggle_notify(void*, GObject* gobj,
      * of it is taken care by JS::Heap, which we use in GjsMaybeOwned,
      * so we're safe. As for sweeping, it is too late: the JS object
      * is dead, and attempting to keep it alive would soon crash
-     * the process. Plus, if we touch the JSAPI, libmozjs aborts in
-     * the first BeginRequest.
+     * the process. Plus, if we touch the JSAPI from another thread, libmozjs
+     * aborts in most cases when in debug mode.
      * Thus, we drain the toggle queue when GC starts, in order to
      * prevent this from happening.
      * In practice, a toggle up during JS finalize can only happen
diff --git a/gi/private.cpp b/gi/private.cpp
index 26f8e02e..4e0c38f3 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -253,8 +253,6 @@ GJS_JSAPI_RETURN_CONVENTION
 static bool gjs_register_type(JSContext* cx, unsigned argc, JS::Value* vp) {
     JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);
 
-    JSAutoRequest ar(cx);
-
     JS::UniqueChars name;
     GTypeFlags type_flags;
     JS::RootedObject parent(cx), interfaces(cx), properties(cx);
@@ -338,8 +336,6 @@ GJS_JSAPI_RETURN_CONVENTION
 static bool gjs_signal_new(JSContext* cx, unsigned argc, JS::Value* vp) {
     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
 
-    JSAutoRequest ar(cx);
-
     JS::UniqueChars signal_name;
     int32_t flags, accumulator_enum;
     JS::RootedObject gtype_obj(cx), return_gtype_obj(cx), params_obj(cx);
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 90d22329..061b6f68 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -89,8 +89,6 @@ static bool resolve_namespace_object(JSContext* context,
                                      JS::HandleId ns_id) {
     GError *error;
 
-    JSAutoRequest ar(context);
-
     JS::UniqueChars version;
     if (!get_version_for_ns(context, repo_obj, ns_id, &version))
         return false;
@@ -552,7 +550,7 @@ gjs_lookup_namespace_object(JSContext  *context,
 }
 
 /* Check if an exception's 'name' property is equal to compare_name. Ignores
- * all errors that might arise. Requires request. */
+ * all errors that might arise. */
 GJS_USE
 static bool
 error_has_name(JSContext       *cx,
@@ -589,7 +587,6 @@ lookup_override_function(JSContext             *cx,
                          JS::HandleId           ns_name,
                          JS::MutableHandleValue function)
 {
-    JSAutoRequest ar(cx);
     JS::AutoSaveExceptionState saved_exc(cx);
 
     JS::RootedValue importer(cx, gjs_get_global_slot(cx, GJS_GLOBAL_SLOT_IMPORTS));
@@ -635,8 +632,6 @@ JSObject*
 gjs_lookup_namespace_object_by_name(JSContext      *context,
                                     JS::HandleId    ns_name)
 {
-    JSAutoRequest ar(context);
-
     JS::RootedValue importer(context,
         gjs_get_global_slot(context, GJS_GLOBAL_SLOT_IMPORTS));
     g_assert(importer.isObject());
diff --git a/gi/value.cpp b/gi/value.cpp
index a68f6059..cf3d38fd 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -171,7 +171,6 @@ closure_marshal(GClosure        *closure,
     }
 
     JSFunction* func = gjs_closure_get_callable(closure);
-    JSAutoRequest ar(context);
     JSAutoCompartment ac(context, JS_GetFunctionObject(func));
 
     if (marshal_data) {
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 6248bf09..7c938f2e 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -157,7 +157,6 @@ class GIWrapperBase {
      * if not. */
     GJS_USE
     static Base* for_js(JSContext* cx, JS::HandleObject wrapper) {
-        JSAutoRequest ar(cx);
         return static_cast<Base*>(
             JS_GetInstancePrivate(cx, wrapper, &Base::klass, nullptr));
     }
@@ -186,7 +185,6 @@ class GIWrapperBase {
     static Base* for_js_typecheck(
         JSContext* cx, JS::HandleObject wrapper,
         JS::CallArgs& args) {  // NOLINT(runtime/references)
-        JSAutoRequest ar(cx);
         return static_cast<Base*>(
             JS_GetInstancePrivate(cx, wrapper, &Base::klass, &args));
     }
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 1accc773..f1da8c77 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -362,8 +362,6 @@ void GjsContextPrivate::dispose(void) {
                   "Checking unhandled promise rejections");
         warn_about_unhandled_promise_rejections();
 
-        JS_BeginRequest(m_cx);
-
         gjs_debug(GJS_DEBUG_CONTEXT, "Releasing cached JS wrappers");
         m_fundamental_table->clear();
         m_gtype_table->clear();
@@ -374,7 +372,6 @@ void GjsContextPrivate::dispose(void) {
          */
         gjs_debug(GJS_DEBUG_CONTEXT, "Final triggered GC");
         JS_GC(m_cx);
-        JS_EndRequest(m_cx);
 
         gjs_debug(GJS_DEBUG_CONTEXT, "Destroying JS context");
         m_destroying = true;
@@ -485,8 +482,6 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
 
     m_atoms = new GjsAtoms();
 
-    JS_BeginRequest(m_cx);
-
     JS::RootedObject global(m_cx, gjs_create_global_object(m_cx));
     if (!global) {
         gjs_log_exception(m_cx);
@@ -521,8 +516,6 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
         gjs_log_exception(m_cx);
         g_error("Failed to define properties on global object");
     }
-
-    JS_EndRequest(m_cx);
 }
 
 static void
@@ -707,8 +700,6 @@ bool GjsContextPrivate::run_jobs(void) {
     if (m_draining_job_queue || m_should_exit)
         return true;
 
-    JSAutoRequest ar(m_cx);
-
     m_draining_job_queue = true;  // Ignore reentrant calls
 
     JS::RootedObject job(m_cx);
@@ -879,7 +870,6 @@ bool GjsContextPrivate::eval(const char* script, ssize_t script_len,
         auto_profile = false;
 
     JSAutoCompartment ac(m_cx, m_global);
-    JSAutoRequest ar(m_cx);
 
     if (auto_profile)
         gjs_profiler_start(m_profiler);
@@ -978,8 +968,6 @@ bool GjsContextPrivate::eval_with_scope(JS::HandleObject scope_object,
                                         const char* script, ssize_t script_len,
                                         const char* filename,
                                         JS::MutableHandleValue retval) {
-    JSAutoRequest ar(m_cx);
-
     /* log and clear exception if it's set (should not be, normally...) */
     if (JS_IsExceptionPending(m_cx)) {
         g_warning("eval_with_scope() called with a pending exception");
@@ -1040,8 +1028,6 @@ bool GjsContextPrivate::call_function(JS::HandleObject this_obj,
                                       JS::HandleValue func_val,
                                       const JS::HandleValueArray& args,
                                       JS::MutableHandleValue rval) {
-    JSAutoRequest ar(m_cx);
-
     if (!JS_CallFunctionValue(m_cx, this_obj, func_val, args, rval))
         return false;
 
@@ -1061,7 +1047,6 @@ gjs_context_define_string_array(GjsContext  *js_context,
     GjsContextPrivate* gjs = GjsContextPrivate::from_object(js_context);
 
     JSAutoCompartment ac(gjs->context(), gjs->global());
-    JSAutoRequest ar(gjs->context());
 
     JS::RootedObject global_root(gjs->context(), gjs->global());
     if (!gjs_define_string_array(gjs->context(), global_root, array_name,
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index e02526b9..d070c1a4 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -310,7 +310,6 @@ gjs_coverage_write_statistics(GjsCoverage *coverage)
 
     auto cx = static_cast<JSContext *>(gjs_context_get_native_context(priv->context));
     JSAutoCompartment ac(cx, gjs_get_import_global(cx));
-    JSAutoRequest ar(cx);
 
     GjsAutoUnref<GFile> output_file = write_statistics_internal(coverage, cx, &error);
     if (!output_file) {
@@ -341,7 +340,6 @@ bootstrap_coverage(GjsCoverage *coverage)
     GjsCoveragePrivate *priv = (GjsCoveragePrivate *) gjs_coverage_get_instance_private(coverage);
 
     JSContext *context = (JSContext *) gjs_context_get_native_context(priv->context);
-    JSAutoRequest ar(context);
 
     JSObject *debuggee = gjs_get_import_global(context);
     JS::RootedObject debugger_compartment(context,
diff --git a/gjs/debugger.cpp b/gjs/debugger.cpp
index 1d04e449..289ba1c7 100644
--- a/gjs/debugger.cpp
+++ b/gjs/debugger.cpp
@@ -56,7 +56,7 @@
 GJS_JSAPI_RETURN_CONVENTION
 static bool quit(JSContext* cx, unsigned argc, JS::Value* vp) {
     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-    JSAutoRequest ar(cx);
+
     int32_t exitcode;
     if (!gjs_parse_call_args(cx, "quit", args, "i", "exitcode", &exitcode))
         return false;
@@ -69,7 +69,6 @@ static bool quit(JSContext* cx, unsigned argc, JS::Value* vp) {
 GJS_JSAPI_RETURN_CONVENTION
 static bool do_readline(JSContext* cx, unsigned argc, JS::Value* vp) {
     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-    JSAutoRequest ar(cx);
 
     JS::UniqueChars prompt;
     if (!gjs_parse_call_args(cx, "readline", args, "|s", "prompt", &prompt))
@@ -128,7 +127,6 @@ static JSFunctionSpec debugger_funcs[] = {
 
 void gjs_context_setup_debugger_console(GjsContext* gjs) {
     auto cx = static_cast<JSContext*>(gjs_context_get_native_context(gjs));
-    JSAutoRequest ar(cx);
 
     JS::RootedObject debuggee(cx, gjs_get_import_global(cx));
     JS::RootedObject debugger_compartment(cx, gjs_create_global_object(cx));
diff --git a/gjs/global.cpp b/gjs/global.cpp
index 88cef746..7113e617 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -77,8 +77,6 @@ gjs_log(JSContext *cx,
         return false;
     }
 
-    JSAutoRequest ar(cx);
-
     /* JS::ToString might throw, in which case we will only log that the value
      * could not be converted to string */
     JS::AutoSaveExceptionState exc_state(cx);
@@ -113,8 +111,6 @@ gjs_log_error(JSContext *cx,
         return false;
     }
 
-    JSAutoRequest ar(cx);
-
     JS::RootedString jstr(cx);
 
     if (argc == 2) {
@@ -140,8 +136,6 @@ gjs_print_parse_args(JSContext              *cx,
     GString *str;
     guint n;
 
-    JSAutoRequest ar(cx);
-
     str = g_string_new("");
     for (n = 0; n < argv.length(); ++n) {
         /* JS::ToString might throw, in which case we will only log that the
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 9c650f27..acba258a 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -770,8 +770,6 @@ importer_resolve(JSContext        *context,
         return true;
     }
 
-    JSAutoRequest ar(context);
-
     if (!JSID_IS_STRING(id)) {
         *resolved = false;
         return true;
diff --git a/gjs/jsapi-class.h b/gjs/jsapi-class.h
index 757a65dd..a752cefe 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -83,7 +83,6 @@ bool gjs_define_property_dynamic(JSContext       *cx,
     }                                                                          \
     GJS_ALWAYS_INLINE GJS_USE static inline type* priv_from_js(                \
         JSContext* cx, JS::HandleObject obj) {                                 \
-        JSAutoRequest ar(cx);                                                  \
         return static_cast<type*>(                                             \
             JS_GetInstancePrivate(cx, obj, &klass, nullptr));                  \
     }                                                                          \
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 6b6cb427..a5388f0b 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -55,8 +55,6 @@ bool gjs_init_class_dynamic(JSContext* context, JS::HandleObject in_object,
        use JS_InitClass for static classes like Math */
     g_assert (constructor_native != NULL);
 
-    JSAutoRequest ar(context);
-
     /* Class initalization consists of five parts:
        - building a prototype
        - defining prototype properties and functions
@@ -166,8 +164,6 @@ gjs_construct_object_dynamic(JSContext                  *context,
                              JS::HandleObject            proto,
                              const JS::HandleValueArray& args)
 {
-    JSAutoRequest ar(context);
-
     const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
     JS::RootedObject constructor(context);
 
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 9419acbe..d8bb99ab 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -292,7 +292,6 @@ G_GNUC_UNUSED GJS_JSAPI_RETURN_CONVENTION static bool gjs_parse_call_args(
               *format == '\0'));
 
     if (!ignore_trailing_args && args.length() > 0) {
-        JSAutoRequest ar(cx);
         gjs_throw(cx, "Error invoking %s: Expected 0 arguments, got %d",
                   function_name, args.length());
         return false;
@@ -370,8 +369,6 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_parse_call_args(
     g_assert(((void) "Wrong number of parameters passed to gjs_parse_call_args()",
               sizeof...(Args) / 2 == n_total));
 
-    JSAutoRequest ar(cx);
-
     /* COMPAT: In future, use args.requireAtLeast()
      * https://bugzilla.mozilla.org/show_bug.cgi?id=1334338 */
     if (args.length() < n_required ||
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index 391234e9..f39ce69d 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -56,8 +56,6 @@ gjs_throw_valist(JSContext       *context,
 
     s = g_strdup_vprintf(format, args);
 
-    JS_BeginRequest(context);
-
     if (JS_IsExceptionPending(context)) {
         /* Often it's unclear whether a given jsapi.h function
          * will throw an exception, so we will throw ourselves
@@ -71,7 +69,6 @@ gjs_throw_valist(JSContext       *context,
                   "Ignoring second exception: '%s'",
                   s);
         g_free(s);
-        JS_EndRequest(context);
         return;
     }
 
@@ -117,8 +114,6 @@ gjs_throw_valist(JSContext       *context,
         JS_ReportErrorUTF8(context, "Failed to throw exception '%s'", s);
     }
     g_free(s);
-
-    JS_EndRequest(context);
 }
 
 /* Throws an exception, like "throw new Error(message)"
diff --git a/gjs/jsapi-util-root.h b/gjs/jsapi-util-root.h
index 2aae8443..9e9b5b91 100644
--- a/gjs/jsapi-util-root.h
+++ b/gjs/jsapi-util-root.h
@@ -292,7 +292,6 @@ class GjsMaybeOwned {
 
         /* Prevent the thing from being garbage collected while it is in neither
          * m_heap nor m_root */
-        JSAutoRequest ar(cx);
         JS::Rooted<T> thing(cx, m_heap);
 
         reset();
@@ -306,7 +305,6 @@ class GjsMaybeOwned {
 
         /* Prevent the thing from being garbage collected while it is in neither
          * m_heap nor m_root */
-        JSAutoRequest ar(cx);
         JS::Rooted<T> thing(cx, *m_root);
 
         reset();
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index eca93896..6674cede 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -62,8 +62,6 @@ char* gjs_hyphen_to_underscore(const char* str) {
  */
 bool gjs_string_to_utf8(JSContext* cx, const JS::Value value,
                         JS::UniqueChars* utf8_string_p) {
-    JSAutoRequest ar(cx);
-
     if (!value.isString()) {
         gjs_throw(cx, "Value is not a string, cannot convert to UTF-8");
         return false;
@@ -79,14 +77,11 @@ gjs_string_from_utf8(JSContext             *context,
                      const char            *utf8_string,
                      JS::MutableHandleValue value_p)
 {
-    JS_BeginRequest(context);
-
     JS::ConstUTF8CharsZ chars(utf8_string, strlen(utf8_string));
     JS::RootedString str(context, JS_NewStringCopyUTF8Z(context, chars));
     if (str)
         value_p.setString(str);
 
-    JS_EndRequest(context);
     return str != nullptr;
 }
 
@@ -96,8 +91,6 @@ gjs_string_from_utf8_n(JSContext             *cx,
                        size_t                 len,
                        JS::MutableHandleValue out)
 {
-    JSAutoRequest ar(cx);
-
     JS::UTF8Chars chars(utf8_chars, len);
     JS::RootedString str(cx, JS_NewStringCopyUTF8N(cx, chars));
     if (str)
@@ -197,8 +190,6 @@ gjs_string_get_char16_data(JSContext       *context,
                            char16_t       **data_p,
                            size_t          *len_p)
 {
-    JSAutoRequest ar(context);
-
     if (JS_StringHasLatin1Chars(str))
         return from_latin1(context, str, data_p, len_p);
 
@@ -235,7 +226,6 @@ gjs_string_to_ucs4(JSContext       *cx,
     if (ucs4_string_p == NULL)
         return true;
 
-    JSAutoRequest ar(cx);
     size_t len;
     GError *error = NULL;
 
@@ -305,7 +295,6 @@ gjs_string_from_ucs4(JSContext             *cx,
         return false;
     }
 
-    JSAutoRequest ar(cx);
     /* Avoid a copy - assumes that g_malloc == js_malloc == malloc */
     JS::RootedString str(cx, JS_NewUCString(cx, u16_string, u16_string_length));
 
@@ -369,7 +358,6 @@ jsid
 gjs_intern_string_to_id(JSContext  *cx,
                         const char *string)
 {
-    JSAutoRequest ar(cx);
     JS::RootedString str(cx, JS_AtomizeAndPinString(cx, string));
     if (!str)
         return JSID_VOID;
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 62d824d0..e8a35980 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -65,8 +65,6 @@ throw_property_lookup_error(JSContext       *cx,
  *
  * SpiderMonkey will emit a warning if the property is not present, so don't
  * use this if you expect the property not to be present some of the time.
- *
- * Requires request.
  */
 bool
 gjs_object_require_property(JSContext             *context,
@@ -237,8 +235,6 @@ gjs_define_string_array(JSContext       *context,
                         const char     **array_values,
                         unsigned         attrs)
 {
-    JSAutoRequest ar(context);
-
     JS::RootedObject array(context,
         gjs_build_string_array(context, array_length, (char **) array_values));
 
@@ -267,8 +263,6 @@ gjs_string_readable(JSContext       *context,
 {
     GString *buf = g_string_new("");
 
-    JS_BeginRequest(context);
-
     g_string_append_c(buf, '"');
 
     JS::UniqueChars chars(JS_EncodeStringToUTF8(context, string));
@@ -291,8 +285,6 @@ gjs_string_readable(JSContext       *context,
 
     g_string_append_c(buf, '"');
 
-    JS_EndRequest(context);
-
     return g_string_free(buf, false);
 }
 
@@ -356,8 +348,6 @@ gjs_value_debug_string(JSContext      *context,
         return gjs_string_readable(context, str);
     }
 
-    JS_BeginRequest(context);
-
     JS::RootedString str(context, JS::ToString(context, value));
 
     if (!str) {
@@ -374,17 +364,13 @@ gjs_value_debug_string(JSContext      *context,
             if (klass != NULL) {
                 str = JS_NewStringCopyZ(context, klass->name);
                 JS_ClearPendingException(context);
-                if (!str) {
-                    JS_EndRequest(context);
+                if (!str)
                     return g_strdup("[out of memory copying class name]");
-                }
             } else {
                 gjs_log_exception(context);
-                JS_EndRequest(context);
                 return g_strdup("[unknown object]");
             }
         } else {
-            JS_EndRequest(context);
             return g_strdup("[unknown non-object]");
         }
     }
@@ -392,7 +378,6 @@ gjs_value_debug_string(JSContext      *context,
     g_assert(str);
 
     bytes = JS_EncodeStringToUTF8(context, str);
-    JS_EndRequest(context);
 
     debugstr = _gjs_g_utf8_make_valid(bytes);
     JS_free(context, bytes);
@@ -408,7 +393,6 @@ gjs_log_exception_full(JSContext       *context,
     bool is_syntax;
     const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
 
-    JS_BeginRequest(context);
     JS::RootedObject exc_obj(context);
     JS::RootedString exc_str(context, JS::ToString(context, exc));
     JS::UniqueChars utf8_exception;
@@ -487,32 +471,20 @@ gjs_log_exception_full(JSContext       *context,
         }
     }
 
-    JS_EndRequest(context);
-
     return true;
 }
 
 bool
 gjs_log_exception(JSContext  *context)
 {
-    bool retval = false;
-
-    JS_BeginRequest(context);
-
     JS::RootedValue exc(context);
     if (!JS_GetPendingException(context, &exc))
-        goto out;
+        return false;
 
     JS_ClearPendingException(context);
 
     gjs_log_exception_full(context, exc, nullptr);
-
-    retval = true;
-
- out:
-    JS_EndRequest(context);
-
-    return retval;
+    return true;
 }
 
 #ifdef __linux__
diff --git a/modules/system.cpp b/modules/system.cpp
index b0e536db..638b5379 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -180,20 +180,14 @@ gjs_exit(JSContext *context,
     return false;  /* without gjs_throw() == "throw uncatchable exception" */
 }
 
-static bool
-gjs_clear_date_caches(JSContext *context,
-                      unsigned   argc,
-                      JS::Value *vp)
-{
+static bool gjs_clear_date_caches(JSContext*, unsigned argc, JS::Value* vp) {
     JS::CallArgs rec = JS::CallArgsFromVp(argc, vp);
-    JS_BeginRequest(context);
 
     // Workaround for a bug in SpiderMonkey where tzset is not called before
     // localtime_r, see https://bugzilla.mozilla.org/show_bug.cgi?id=1004706
     tzset();
 
     JS::ResetTimeZone();
-    JS_EndRequest(context);
 
     rec.rval().setUndefined();
     return true;
diff --git a/test/gjs-test-utils.cpp b/test/gjs-test-utils.cpp
index 5855364a..b6e2a303 100644
--- a/test/gjs-test-utils.cpp
+++ b/test/gjs-test-utils.cpp
@@ -36,8 +36,6 @@ void gjs_unit_test_fixture_setup(GjsUnitTestFixture* fx, const void*) {
     fx->gjs_context = gjs_context_new();
     fx->cx = (JSContext *) gjs_context_get_native_context(fx->gjs_context);
 
-    JS_BeginRequest(fx->cx);
-
     JS::RootedObject global(fx->cx, gjs_get_import_global(fx->cx));
     fx->compartment = JS_EnterCompartment(fx->cx, global);
 }
@@ -50,7 +48,6 @@ gjs_unit_test_destroy_context(GjsUnitTestFixture *fx)
         g_printerr("**\n%s\n", message.get());
 
     JS_LeaveCompartment(fx->cx, fx->compartment);
-    JS_EndRequest(fx->cx);
 
     g_object_unref(fx->gjs_context);
 }


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