[gjs/wip/ptomato/mozjs31: 16/17] WIP - stuff



commit b7acfc9b1572cf8b2f8c6454f5fc3799c93d53db
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Oct 5 21:44:25 2016 -0700

    WIP - stuff

 gi/arg.cpp                  |   28 +++++++-------
 gi/boxed.cpp                |    9 ++---
 gi/enumeration.cpp          |    7 +---
 gi/function.cpp             |   34 +++++++-----------
 gi/fundamental.cpp          |    8 ++---
 gi/interface.cpp            |    3 +-
 gi/keep-alive.cpp           |    5 +--
 gi/ns.cpp                   |   10 +++---
 gi/object.cpp               |   39 ++++++++++----------
 gi/param.cpp                |    8 ++---
 gi/repo.cpp                 |   22 +++++-------
 gi/union.cpp                |    8 ++---
 gjs/byteArray.cpp           |   31 +++++++---------
 gjs/context.cpp             |    9 ++---
 gjs/coverage.cpp            |   85 +++++++++++++++++--------------------------
 gjs/importer.cpp            |   48 +++++++++++--------------
 gjs/jsapi-dynamic-class.cpp |   14 ++++---
 gjs/jsapi-util-args.h       |    3 +-
 gjs/jsapi-util-error.cpp    |    9 +++--
 gjs/jsapi-util-string.cpp   |    2 +-
 gjs/jsapi-util.cpp          |   30 +++++++--------
 gjs/jsapi-util.h            |   11 +++---
 gjs/stack.cpp               |    3 +-
 23 files changed, 188 insertions(+), 238 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index c158982..00b9a49 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -287,7 +287,7 @@ gjs_array_to_g_list(JSContext   *context,
         GArgument elem_arg = { 0 };
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, array, i, elem.address())) {
+        if (!JS_GetElement(context, array, i, &elem)) {
             gjs_throw(context,
                       "Missing array element %u",
                       i);
@@ -512,14 +512,14 @@ gjs_object_to_g_hash(JSContext   *context,
         gpointer key_ptr, val_ptr;
         GIArgument val_arg = { 0 };
 
-        if (!JS_IdToValue(context, cur_id, key_js.address()))
+        if (!JS_IdToValue(context, cur_id, &key_js))
             goto free_hash_and_fail;
 
         /* Type check key type. */
         if (!value_to_ghashtable_key(context, key_js, key_param_info, &key_ptr))
             goto free_hash_and_fail;
 
-        if (!JS_GetPropertyById(context, props, cur_id, val_js.address()))
+        if (!JS_GetPropertyById(context, props, cur_id, &val_js))
             goto free_hash_and_fail;
 
         /* Type check and convert value to a c type */
@@ -602,7 +602,7 @@ gjs_array_to_strv(JSContext   *context,
 
     for (i = 0; i < length; ++i) {
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, array, i, elem.address())) {
+        if (!JS_GetElement(context, array, i, &elem)) {
             g_free(result);
             gjs_throw(context,
                       "Missing array element %u",
@@ -684,7 +684,7 @@ gjs_array_to_gboolean_array(JSContext      *cx,
     gboolean *result = g_new0(gboolean, length);
 
     for (i = 0; i < length; i++) {
-        if (!JS_GetElement(cx, array, i, elem.address())) {
+        if (!JS_GetElement(cx, array, i, &elem)) {
             g_free(result);
             gjs_throw(cx, "Missing array element %u", i);
             return false;
@@ -719,7 +719,7 @@ gjs_array_to_intarray(JSContext   *context,
         bool success;
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, array, i, elem.address())) {
+        if (!JS_GetElement(context, array, i, &elem)) {
             g_free(result);
             gjs_throw(context,
                       "Missing array element %u",
@@ -776,7 +776,7 @@ gjs_gtypearray_to_array(JSContext   *context,
         GType gtype;
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, array, i, elem.address())) {
+        if (!JS_GetElement(context, array, i, &elem)) {
             g_free(result);
             gjs_throw(context, "Missing array element %u", i);
             return false;
@@ -823,7 +823,7 @@ gjs_array_to_floatarray(JSContext   *context,
         bool success;
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, array, i, elem.address())) {
+        if (!JS_GetElement(context, array, i, &elem)) {
             g_free(result);
             gjs_throw(context,
                       "Missing array element %u",
@@ -879,7 +879,7 @@ gjs_array_to_ptrarray(JSContext   *context,
         bool success;
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, array_obj, i, elem.address())) {
+        if (!JS_GetElement(context, array_obj, i, &elem)) {
             g_free(array);
             gjs_throw(context,
                       "Missing array element %u",
@@ -925,7 +925,7 @@ gjs_array_to_flat_gvalue_array(JSContext   *context,
     for (i = 0; i < length; i ++) {
         elem = JS::UndefinedValue();
 
-        if (!JS_GetElement(context, array, i, elem.address())) {
+        if (!JS_GetElement(context, array, i, &elem)) {
             g_free(values);
             gjs_throw(context,
                       "Missing array element %u",
@@ -966,7 +966,7 @@ gjs_array_from_flat_gvalue_array(JSContext             *context,
 
     if (result) {
         JSObject *jsarray;
-        jsarray = JS_NewArrayObject(context, length, elems.begin());
+        jsarray = JS_NewArrayObject(context, elems);
         value.setObjectOrNull(jsarray);
     }
 
@@ -2535,7 +2535,8 @@ gjs_object_from_g_hash (JSContext             *context,
         return true;
     }
 
-    JS::RootedObject obj(context, JS_NewObject(context, NULL, NULL, NULL));
+    JS::RootedObject obj(context,
+        JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
     if (obj == NULL)
         return false;
 
@@ -2566,8 +2567,7 @@ gjs_object_from_g_hash (JSContext             *context,
                                        true))
             goto out;
 
-        if (!JS_DefineProperty(context, obj, keyutf8, valjs,
-                               NULL, NULL, JSPROP_ENUMERATE))
+        if (!JS_DefineProperty(context, obj, keyutf8, valjs, JSPROP_ENUMERATE))
             goto out;
 
         g_free(keyutf8);
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 8b65204..fa11d9a 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -440,7 +440,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(boxed)
                         "boxed constructor, obj %p priv %p",
                         object.get(), priv);
 
-    JS_GetPrototype(context, object, proto.address());
+    JS_GetPrototype(context, object, &proto);
     gjs_debug_lifecycle(GJS_DEBUG_GBOXED, "boxed instance __proto__ is %p",
                         proto.get());
     /* If we're the prototype, then post-construct we'll fill in priv->info.
@@ -862,8 +862,8 @@ define_boxed_class_fields (JSContext       *context,
         bool result;
 
         result = JS_DefineProperty(context, proto, field_name, JS::NullHandleValue,
-                                   boxed_field_getter, boxed_field_setter,
-                                   JSPROP_PERMANENT | JSPROP_SHARED);
+                                   JSPROP_PERMANENT | JSPROP_SHARED,
+                                   boxed_field_getter, boxed_field_setter);
 
         g_base_info_unref ((GIBaseInfo *)field);
 
@@ -919,7 +919,6 @@ struct JSClass gjs_boxed_class = {
     (JSResolveOp) boxed_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
     boxed_finalize,
-    NULL,  /* checkAccess */
     NULL,  /* call */
     NULL,  /* hasInstance */
     NULL,  /* construct */
@@ -1176,7 +1175,7 @@ gjs_define_boxed_class(JSContext       *context,
     JS::RootedValue value(context,
         JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, priv->gtype)));
     JS_DefineProperty(context, constructor, "$gtype", value,
-                      NULL, NULL, JSPROP_PERMANENT);
+                      JSPROP_PERMANENT);
 }
 
 JSObject*
diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp
index 1b2361c..051ffa2 100644
--- a/gi/enumeration.cpp
+++ b/gi/enumeration.cpp
@@ -68,7 +68,6 @@ gjs_define_enum_value(JSContext       *context,
     JS::RootedValue value_js(context, JS::NumberValue(value_val));
     if (!JS_DefineProperty(context, in_object,
                            fixed_name, value_js,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS)) {
         gjs_throw(context, "Unable to define enumeration value %s %" G_GINT64_FORMAT " (no memory most 
likely)",
                   fixed_name, value_val);
@@ -108,8 +107,7 @@ gjs_define_enum_values(JSContext       *context,
     gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)info);
     JS::RootedValue value(context,
         JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype)));
-    JS_DefineProperty(context, in_object, "$gtype", value,
-                      NULL, NULL, JSPROP_PERMANENT);
+    JS_DefineProperty(context, in_object, "$gtype", value, JSPROP_PERMANENT);
 
     return true;
 }
@@ -168,7 +166,7 @@ gjs_define_enumeration(JSContext       *context,
 
     enum_name = g_base_info_get_name( (GIBaseInfo*) info);
 
-    JS::RootedObject enum_obj(context, JS_NewObject(context, NULL, NULL,
+    JS::RootedObject enum_obj(context, JS_NewObject(context, NULL, JS::NullPtr(),
                                                     global));
     if (enum_obj == NULL) {
         g_error("Could not create enumeration %s.%s",
@@ -191,7 +189,6 @@ gjs_define_enumeration(JSContext       *context,
 
     JS::RootedValue v_enum(context, JS::ObjectValue(*enum_obj));
     if (!JS_DefineProperty(context, in_object, enum_name, v_enum,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS)) {
         gjs_throw(context, "Unable to define enumeration property (no memory most likely)");
         return false;
diff --git a/gi/function.cpp b/gi/function.cpp
index 4cf9d66..8dffc5d 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -87,7 +87,7 @@ gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline)
 
         if (!trampoline->is_vfunc) {
             JS_BeginRequest(context);
-            JS_RemoveValueRoot(context, trampoline->js_function.unsafeGet());
+            JS::RemoveValueRoot(context, &trampoline->js_function);
             JS_EndRequest(context);
         }
 
@@ -292,9 +292,8 @@ gjs_callback_closure(ffi_cif *cif,
     if (!JS_CallFunctionValue(context,
                               this_object,
                               rooted_function,
-                              n_jsargs,
-                              jsargs.begin(),
-                              rval.address())) {
+                              jsargs,
+                              &rval)) {
         goto out;
     }
 
@@ -354,7 +353,7 @@ gjs_callback_closure(ffi_cif *cif,
         if (!ret_type_is_void) {
             GIArgument argument;
 
-            if (!JS_GetElement(context, out_array, elem_idx, elem.address()))
+            if (!JS_GetElement(context, out_array, elem_idx, &elem))
                 goto out;
 
             if (!gjs_value_to_g_argument(context,
@@ -382,7 +381,7 @@ gjs_callback_closure(ffi_cif *cif,
                 continue;
 
             g_arg_info_load_type(&arg_info, &type_info);
-            if (!JS_GetElement(context, out_array, elem_idx, elem.address()))
+            if (!JS_GetElement(context, out_array, elem_idx, &elem))
                 goto out;
 
             if (!gjs_value_to_g_argument(context,
@@ -455,7 +454,7 @@ gjs_callback_trampoline_new(JSContext      *context,
     g_base_info_ref((GIBaseInfo*)trampoline->info);
     trampoline->js_function = function;
     if (!is_vfunc)
-        JS_AddValueRoot(context, trampoline->js_function.unsafeGet());
+        JS::AddValueRoot(context, &trampoline->js_function);
 
     /* Analyze param types and directions, similarly to init_cached_function_data */
     n_args = g_callable_info_get_n_args(trampoline->info);
@@ -1279,9 +1278,7 @@ release:
                 *js_rval = return_values[0];
             } else {
                 JSObject *array;
-                array = JS_NewArrayObject(context,
-                                          function->js_out_argc,
-                                          &return_values[0]);
+                array = JS_NewArrayObject(context, return_values);
                 if (array == NULL) {
                     failed = true;
                 } else {
@@ -1478,13 +1475,11 @@ struct JSClass gjs_function_class = {
     JS_ResolveStub,
     JS_ConvertStub,
     function_finalize,
-    NULL,
-    function_call,
-    NULL, NULL, NULL
+    function_call
 };
 
 JSPropertySpec gjs_function_proto_props[] = {
-    JS_PSG("length", get_num_arguments, JSPROP_READONLY | JSPROP_PERMANENT),
+    JS_PSG("length", get_num_arguments, JSPROP_PERMANENT),
     JS_PS_END
 };
 
@@ -1661,10 +1656,10 @@ function_new(JSContext      *context,
         JS::RootedObject parent_proto(context);
         JS::RootedValue v_native_function(context);
 
-        JS_GetProperty(context, global, "Function", v_native_function.address());
+        JS_GetProperty(context, global, "Function", &v_native_function);
         JS::RootedObject native_function(context, &v_native_function.toObject());
         /* We take advantage from that fact that Function.__proto__ is Function.prototype */
-        JS_GetPrototype(context, native_function, parent_proto.address());
+        JS_GetPrototype(context, native_function, &parent_proto);
 
         prototype = JS_InitClass(context, global,
                                  /* parent prototype JSObject* for
@@ -1696,7 +1691,7 @@ function_new(JSContext      *context,
     }
 
     JS::RootedObject function(context,
-                              JS_NewObject(context, &gjs_function_class, NULL, global));
+        JS_NewObject(context, &gjs_function_class, JS::NullPtr(), global));
     if (function == NULL) {
         gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to construct function");
         return NULL;
@@ -1748,10 +1743,7 @@ gjs_define_function(JSContext       *context,
         g_assert_not_reached ();
     }
 
-    /* COMPAT: JS_DefineProperty is overloaded to take JS::HandleObject in 31 */
-    JS::RootedValue v_function(context, JS::ObjectValue(*function));
-    if (!JS_DefineProperty(context, in_object, name, v_function,
-                           NULL, NULL,
+    if (!JS_DefineProperty(context, in_object, name, function,
                            GJS_MODULE_PROP_FLAGS)) {
         gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to define function");
         function = NULL;
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index d18e4a9..8b0679d 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -134,7 +134,7 @@ proto_priv_from_js(JSContext       *context,
                    JS::HandleObject obj)
 {
     JS::RootedObject proto(context);
-    JS_GetPrototype(context, obj, proto.address());
+    JS_GetPrototype(context, obj, &proto);
     return (Fundamental*) priv_from_js(context, proto);
 }
 
@@ -558,7 +558,6 @@ struct JSClass gjs_fundamental_instance_class = {
     (JSResolveOp) fundamental_instance_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
     fundamental_finalize,
-    NULL,  /* checkAccess */
     NULL,  /* call */
     NULL,  /* hasInstance */
     NULL,  /* construct */
@@ -594,7 +593,7 @@ gjs_lookup_fundamental_prototype(JSContext    *context,
         return NULL;
 
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, constructor_name, value.address()))
+    if (!JS_GetProperty(context, in_object, constructor_name, &value))
         return NULL;
 
     JS::RootedObject constructor(context);
@@ -733,8 +732,7 @@ gjs_define_fundamental_class(JSContext              *context,
 
     JS::RootedValue value(context,
         JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype)));
-    JS_DefineProperty(context, constructor, "$gtype", value,
-                      NULL, NULL, JSPROP_PERMANENT);
+    JS_DefineProperty(context, constructor, "$gtype", value, JSPROP_PERMANENT);
 
     return true;
 }
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 699a7fc..c03f635 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -168,8 +168,7 @@ struct JSClass gjs_interface_class = {
     JS_EnumerateStub,
     (JSResolveOp) interface_new_resolve,
     JS_ConvertStub,
-    interface_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    interface_finalize
 };
 
 JSPropertySpec gjs_interface_proto_props[] = {
diff --git a/gi/keep-alive.cpp b/gi/keep-alive.cpp
index 104b071..4060935 100644
--- a/gi/keep-alive.cpp
+++ b/gi/keep-alive.cpp
@@ -159,7 +159,6 @@ struct JSClass gjs_keep_alive_class = {
     NULL,
     NULL,
     NULL,
-    NULL,
     keep_alive_trace,
 };
 
@@ -206,7 +205,7 @@ gjs_keep_alive_new(JSContext *context)
                                   * prototype; NULL for
                                   * Object.prototype
                                   */
-                                 NULL,
+                                 JS::NullPtr(),
                                  &gjs_keep_alive_class,
                                  /* constructor for instances (NULL for
                                   * none - just name the prototype like
@@ -235,7 +234,7 @@ gjs_keep_alive_new(JSContext *context)
               context, global.get());
 
     JS::RootedObject keep_alive(context,
-                                JS_NewObject(context, &gjs_keep_alive_class, NULL, global));
+        JS_NewObject(context, &gjs_keep_alive_class, JS::NullPtr(), global));
     if (keep_alive == NULL) {
         gjs_log_exception(context);
         g_error("Failed to create keep_alive object");
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 4e2df0d..2cff633 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -175,12 +175,11 @@ struct JSClass gjs_ns_class = {
     JS_EnumerateStub,
     (JSResolveOp) ns_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
-    ns_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    ns_finalize
 };
 
 JSPropertySpec gjs_ns_proto_props[] = {
-    JS_PSG("__name__", get_name, GJS_MODULE_PROP_FLAGS | JSPROP_READONLY),
+    JS_PSG("__name__", get_name, GJS_MODULE_PROP_FLAGS),
     JS_PS_END
 };
 
@@ -207,7 +206,7 @@ ns_new(JSContext    *context,
                                   * prototype; NULL for
                                   * Object.prototype
                                   */
-                                 NULL,
+                                 JS::NullPtr(),
                                  &gjs_ns_class,
                                  /* constructor for instances (NULL for
                                   * none - just name the prototype like
@@ -231,7 +230,8 @@ ns_new(JSContext    *context,
                   gjs_ns_class.name, prototype);
     }
 
-    JS::RootedObject ns(context, JS_NewObject(context, &gjs_ns_class, NULL, global));
+    JS::RootedObject ns(context, JS_NewObject(context, &gjs_ns_class,
+                                              JS::NullPtr(), global));
     if (ns == NULL)
         g_error("No memory to create ns object");
 
diff --git a/gi/object.cpp b/gi/object.cpp
index 9b256e8..b824974 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -98,6 +98,8 @@ static volatile gint pending_idle_toggles;
 
 GJS_DEFINE_PRIV_FROM_JS(ObjectInstance, gjs_object_instance_class)
 
+static JS::Heap<JSObject *> *ensure_heap_wrapper(GObject *gobj);
+
 static JSObject*       peek_js_obj  (GObject   *gobj);
 static void            set_js_obj   (GObject   *gobj,
                                      JSObject  *obj);
@@ -246,7 +248,7 @@ proto_priv_from_js(JSContext       *context,
                    JS::HandleObject obj)
 {
     JS::RootedObject proto(context);
-    JS_GetPrototype(context, obj, proto.address());
+    JS_GetPrototype(context, obj, &proto);
     return priv_from_js(context, proto);
 }
 
@@ -1065,8 +1067,7 @@ wrapped_gobj_toggle_notify(gpointer      data,
                         G_OBJECT_TYPE_NAME(gobj));
             }
             if (is_sweeping) {
-                JS::RootedObject object(js_context, peek_js_obj(gobj));
-                if (JS_IsAboutToBeFinalized(object.address())) {
+                if (JS_IsAboutToBeFinalized(ensure_heap_wrapper(gobj))) {
                     /* Ouch, the JS object is dead already. Disassociate the GObject
                      * and hope the GObject dies too.
                      */
@@ -1463,7 +1464,7 @@ gjs_lookup_object_constructor_from_info(JSContext    *context,
         return NULL;
 
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, constructor_name, value.address()))
+    if (!JS_GetProperty(context, in_object, constructor_name, &value))
         return NULL;
 
     JS::RootedObject constructor(context);
@@ -1706,9 +1707,9 @@ emit_func(JSContext *context,
 
         g_value_init(value, signal_query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE);
         if ((signal_query.param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE) != 0)
-            failed = !gjs_value_to_g_value_no_copy(context, argv.handleOrUndefinedAt(i + 1), value);
+            failed = !gjs_value_to_g_value_no_copy(context, argv.get(i + 1), value);
         else
-            failed = !gjs_value_to_g_value(context, argv.handleOrUndefinedAt(i + 1), value);
+            failed = !gjs_value_to_g_value(context, argv.get(i + 1), value);
 
         if (failed)
             break;
@@ -1770,7 +1771,6 @@ struct JSClass gjs_object_instance_class = {
     NULL,
     NULL,
     NULL,
-    NULL,
     object_instance_trace,
     
 };
@@ -1964,7 +1964,7 @@ gjs_define_object_class(JSContext              *context,
     JS::RootedValue value(context,
         JS::ObjectValue(*gjs_gtype_create_gtype_wrapper(context, gtype)));
     JS_DefineProperty(context, constructor, "$gtype", value,
-                      NULL, NULL, JSPROP_PERMANENT);
+                      JSPROP_PERMANENT);
 }
 
 static void
@@ -2354,7 +2354,7 @@ gjs_object_get_gproperty (GObject    *object,
     JS::RootedValue jsvalue(context);
 
     underscore_name = hyphen_to_underscore((gchar *)pspec->name);
-    if (!JS_GetProperty(context, js_obj, underscore_name, jsvalue.address()) ||
+    if (!JS_GetProperty(context, js_obj, underscore_name, &jsvalue) ||
         !gjs_value_to_g_value(context, jsvalue, value))
         gjs_log_exception(context);
     g_free (underscore_name);
@@ -2373,7 +2373,7 @@ jsobj_set_gproperty(JSContext       *context,
         return;
 
     underscore_name = hyphen_to_underscore((gchar *)pspec->name);
-    if (!JS_SetProperty(context, object, underscore_name, jsvalue.address()))
+    if (!JS_SetProperty(context, object, underscore_name, jsvalue))
         gjs_log_exception(context);
     g_free (underscore_name);
 }
@@ -2419,17 +2419,18 @@ gjs_object_constructor (GType                  type,
             guint i;
 
             JS::RootedObject props_hash(context,
-                JS_NewObject(context, NULL, NULL, NULL));
+                JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
 
             for (i = 0; i < n_construct_properties; i++)
                 jsobj_set_gproperty(context, props_hash,
                                     construct_properties[i].value,
                                     construct_properties[i].pspec);
 
-            JS::RootedValue argv(context, JS::ObjectValue(*props_hash));
-            object = JS_New(context, constructor, 1, argv.address());
+            JS::AutoValueArray<1> args(context);
+            args[0].set(JS::ObjectValue(*props_hash));
+            object = JS_New(context, constructor, args);
         } else {
-            object = JS_New(context, constructor, 0, NULL);
+            object = JS_New(context, constructor, JS::HandleValueArray::empty());
         }
 
         if (!object)
@@ -2609,7 +2610,7 @@ gjs_object_custom_init(GTypeInstance *instance,
 
     JS::RootedValue r(context);
     if (!JS_CallFunctionValue(context, object, v,
-                              0, NULL, r.address()))
+                              JS::HandleValueArray::empty(), &r))
         gjs_log_exception(context);
 }
 
@@ -2668,7 +2669,7 @@ get_interface_gtypes(JSContext       *cx,
         JS::RootedValue iface_val(cx);
         GType iface_type;
 
-        if (!JS_GetElement(cx, interfaces, i, &iface_val.get()))
+        if (!JS_GetElement(cx, interfaces, i, &iface_val))
             return false;
 
         if (!iface_val.isObject()) {
@@ -2703,7 +2704,7 @@ save_properties_for_class_init(JSContext       *cx,
     for (i = 0; i < n_properties; i++) {
         JS::RootedValue prop_val(cx);
 
-        if (!JS_GetElement(cx, properties, i, &prop_val.get())) {
+        if (!JS_GetElement(cx, properties, i, &prop_val)) {
             g_clear_pointer(&properties_native, g_ptr_array_unref);
             return false;
         }
@@ -2965,7 +2966,7 @@ gjs_signal_new(JSContext *cx,
     params = g_newa(GType, n_parameters);
     JS::RootedValue gtype_val(cx);
     for (i = 0; i < n_parameters; i++) {
-        if (!JS_GetElement(cx, params_obj, i, gtype_val.address()) ||
+        if (!JS_GetElement(cx, params_obj, i, &gtype_val) ||
             !gtype_val.isObject()) {
             gjs_throw(cx, "Invalid signal parameter number %d", i);
             return false;
@@ -3007,7 +3008,7 @@ bool
 gjs_define_private_gi_stuff(JSContext              *cx,
                             JS::MutableHandleObject module)
 {
-    module.set(JS_NewObject(cx, NULL, NULL, NULL));
+    module.set(JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr()));
     return JS_DefineFunctions(cx, module, &module_funcs[0]);
 }
 
diff --git a/gi/param.cpp b/gi/param.cpp
index 1e1d0fa..aefdc3a 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -163,8 +163,7 @@ struct JSClass gjs_param_class = {
     JS_EnumerateStub,
     (JSResolveOp) param_new_resolve,
     JS_ConvertStub,
-    param_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    param_finalize
 };
 
 JSPropertySpec gjs_param_proto_props[] = {
@@ -190,7 +189,7 @@ gjs_lookup_param_prototype(JSContext    *context)
         return NULL;
 
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, "ParamSpec", value.address()))
+    if (!JS_GetProperty(context, in_object, "ParamSpec", &value))
         return NULL;
 
     if (G_UNLIKELY (!value.isObject()))
@@ -240,8 +239,7 @@ gjs_define_param_class(JSContext       *context,
 
     JS::RootedValue value(context,
         JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, G_TYPE_PARAM)));
-    JS_DefineProperty(context, constructor, "$gtype", value,
-                      NULL, NULL, JSPROP_PERMANENT);
+    JS_DefineProperty(context, constructor, "$gtype", value, JSPROP_PERMANENT);
 
     info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), G_TYPE_PARAM);
     gjs_object_define_static_methods(context, constructor, G_TYPE_PARAM, info);
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 9eaa4f4..6606ef1 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -122,7 +122,6 @@ resolve_namespace_object(JSContext       *context,
        the override module looks for namespaces that import this */
     JS::RootedValue v_namespace(context, JS::ObjectValue(*gi_namespace));
     if (!JS_DefineProperty(context, repo_obj, ns_name, v_namespace,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS))
         g_error("no memory to define ns property");
 
@@ -132,9 +131,7 @@ resolve_namespace_object(JSContext       *context,
     if (!override.isNull() &&
         !JS_CallFunctionValue (context, gi_namespace, /* thisp */
                                override, /* callee */
-                               0, /* argc */
-                               NULL, /* argv */
-                               result.address()))
+                               JS::HandleValueArray::empty(), &result))
         return false;
 
     gjs_debug(GJS_DEBUG_GNAMESPACE,
@@ -228,8 +225,7 @@ struct JSClass gjs_repo_class = {
     JS_EnumerateStub,
     (JSResolveOp) repo_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
-    repo_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    repo_finalize
 };
 
 JSPropertySpec gjs_repo_proto_props[] = {
@@ -260,7 +256,7 @@ repo_new(JSContext *context)
                                   * prototype; NULL for
                                   * Object.prototype
                                   */
-                                 NULL,
+                                 JS::NullPtr(),
                                  &gjs_repo_class,
                                  /* constructor for instances (NULL for
                                   * none - just name the prototype like
@@ -284,7 +280,8 @@ repo_new(JSContext *context)
                   gjs_repo_class.name, prototype);
     }
 
-    JS::RootedObject repo(context, JS_NewObject(context, &gjs_repo_class, NULL, global));
+    JS::RootedObject repo(context,
+        JS_NewObject(context, &gjs_repo_class, JS::NullPtr(), global));
     if (repo == NULL) {
         gjs_throw(context, "No memory to create repo object");
         return NULL;
@@ -300,7 +297,7 @@ repo_new(JSContext *context)
     gjs_debug_lifecycle(GJS_DEBUG_GREPO,
                         "repo constructor, obj %p priv %p", repo.get(), priv);
 
-    versions = JS_NewObject(context, NULL, NULL, global);
+    versions = JS_NewObject(context, NULL, JS::NullPtr(), global);
     versions_name = gjs_context_get_const_string(context, GJS_STRING_GI_VERSIONS);
     JS_DefinePropertyById(context, repo,
                           versions_name,
@@ -308,7 +305,7 @@ repo_new(JSContext *context)
                           NULL, NULL,
                           JSPROP_PERMANENT);
 
-    private_ns = JS_NewObject(context, NULL, NULL, global);
+    private_ns = JS_NewObject(context, NULL, JS::NullPtr(), global);
     private_ns_name = gjs_context_get_const_string(context, GJS_STRING_PRIVATE_NS_MARKER);
     JS_DefinePropertyById(context, repo,
                           private_ns_name,
@@ -320,7 +317,7 @@ repo_new(JSContext *context)
      */
     {
         JS::RootedValue value(context);
-        JS_GetProperty(context, repo, "GLib", value.address());
+        JS_GetProperty(context, repo, "GLib", &value);
     }
 
     return repo;
@@ -356,7 +353,6 @@ gjs_define_constant(JSContext       *context,
 
     if (JS_DefineProperty(context, in_object,
                           name, value,
-                          NULL, NULL,
                           GJS_MODULE_PROP_FLAGS))
         ret = true;
 
@@ -754,7 +750,7 @@ gjs_lookup_generic_constructor(JSContext  *context,
         return NULL;
 
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, constructor_name, value.address()))
+    if (!JS_GetProperty(context, in_object, constructor_name, &value))
         return NULL;
 
     if (G_UNLIKELY (!value.isObject()))
diff --git a/gi/union.cpp b/gi/union.cpp
index c319b19..29da5dd 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -208,7 +208,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(union)
                         "union constructor, obj %p priv %p",
                         object.get(), priv);
 
-    JS_GetPrototype(context, object, proto.address());
+    JS_GetPrototype(context, object, &proto);
     gjs_debug_lifecycle(GJS_DEBUG_GBOXED, "union instance __proto__ is %p",
                         proto.get());
 
@@ -306,8 +306,7 @@ struct JSClass gjs_union_class = {
     JS_EnumerateStub,
     (JSResolveOp) union_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
-    union_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    union_finalize
 };
 
 JSPropertySpec gjs_union_proto_props[] = {
@@ -377,8 +376,7 @@ gjs_define_union_class(JSContext       *context,
 
     JS::RootedValue value(context,
         JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype)));
-    JS_DefineProperty(context, constructor, "$gtype", value,
-                      NULL, NULL, JSPROP_PERMANENT);
+    JS_DefineProperty(context, constructor, "$gtype", value, JSPROP_PERMANENT);
 
     return true;
 }
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index a27825b..18a8736 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -64,8 +64,7 @@ struct JSClass gjs_byte_array_class = {
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub,
-    byte_array_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    byte_array_finalize
 };
 
 bool
@@ -201,7 +200,7 @@ byte_array_get_prop(JSContext *context,
         return true; /* prototype, not an instance. */
 
     JS::RootedValue id_value(context);
-    if (!JS_IdToValue(context, id, id_value.address()))
+    if (!JS_IdToValue(context, id, &id_value))
         return false;
 
     /* First handle array indexing */
@@ -251,9 +250,7 @@ byte_array_length_setter(JSContext *context,
 
     byte_array_ensure_array(priv);
 
-    // COMPAT: Indexing JS::CallArgs should provide a handle in mozjs31
-    JS::RootedValue arg(context, args[0]);
-    if (!gjs_value_to_gsize(context, arg, &len)) {
+    if (!gjs_value_to_gsize(context, args[0], &len)) {
         gjs_throw(context,
                   "Can't set ByteArray length to non-integer");
         return false;
@@ -310,7 +307,7 @@ byte_array_set_prop(JSContext *context,
         return true; /* prototype, not an instance. */
 
     JS::RootedValue id_value(context);
-    if (!JS_IdToValue(context, id, id_value.address()))
+    if (!JS_IdToValue(context, id, &id_value))
         return false;
 
     /* First handle array indexing */
@@ -534,9 +531,9 @@ byte_array_new(JSContext *context)
 {
     ByteArrayInstance *priv;
 
+    JS::RootedObject proto(context, byte_array_get_prototype(context));
     JS::RootedObject array(context,
-                           JS_NewObject(context, &gjs_byte_array_class,
-                                        byte_array_get_prototype(context), NULL));
+        JS_NewObject(context, &gjs_byte_array_class, proto, JS::NullPtr()));
 
     priv = g_slice_new0(ByteArrayInstance);
 
@@ -664,13 +661,14 @@ from_array_func(JSContext *context,
 
     priv->array = gjs_g_byte_array_new(0);
 
-    if (!JS_IsArrayObject(context, &argv[0].toObject())) {
+    JS::RootedObject array_obj(context, &argv[0].toObject());
+    if (!JS_IsArrayObject(context, array_obj)) {
         gjs_throw(context,
                   "byteArray.fromArray() called with non-array as first arg");
         return false;
     }
 
-    if (!JS_GetArrayLength(context, &argv[0].toObject(), &len)) {
+    if (!JS_GetArrayLength(context, array_obj, &len)) {
         gjs_throw(context,
                   "byteArray.fromArray() can't get length of first array arg");
         return false;
@@ -683,7 +681,7 @@ from_array_func(JSContext *context,
         guint8 b;
 
         elem = JS::UndefinedValue();
-        if (!JS_GetElement(context, &argv[0].toObject(), i, elem.address())) {
+        if (!JS_GetElement(context, array_obj, i, &elem)) {
             /* this means there was an exception, while elem.isUndefined()
              * means no element found
              */
@@ -743,9 +741,9 @@ gjs_byte_array_from_byte_array (JSContext *context,
     g_return_val_if_fail(context != NULL, NULL);
     g_return_val_if_fail(array != NULL, NULL);
 
+    JS::RootedObject proto(context, byte_array_get_prototype(context));
     JS::RootedObject object(context,
-                            JS_NewObject(context, &gjs_byte_array_class,
-                                         byte_array_get_prototype(context), NULL));
+        JS_NewObject(context, &gjs_byte_array_class, proto, JS::NullPtr()));
     if (!object) {
         gjs_throw(context, "failed to create byte array");
         return NULL;
@@ -832,10 +830,9 @@ gjs_define_byte_array_stuff(JSContext              *context,
 {
     JSObject *prototype;
 
-    module.set(JS_NewObject(context, NULL, NULL, NULL));
+    module.set(JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
 
-    prototype = JS_InitClass(context, module,
-                             NULL,
+    prototype = JS_InitClass(context, module, JS::NullPtr(),
                              &gjs_byte_array_class,
                              gjs_byte_array_constructor,
                              0,
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 7c730b7..29ef9ad 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -172,8 +172,7 @@ gjs_log_error(JSContext *context,
         JS_RestoreExceptionState(context, exc_state);
     }
 
-    /* COMPAT: JS::CallArgs::operator[] will yield Handle in mozjs31 */
-    gjs_log_exception_full(context, argv.handleOrUndefinedAt(0), jstr);
+    gjs_log_exception_full(context, argv[0], jstr);
 
     JS_EndRequest(context);
     argv.rval().setUndefined();
@@ -441,7 +440,6 @@ gjs_context_constructed(GObject *object)
     JS::RootedValue v_global(js_context->context, JS::ObjectValue(*global));
     if (!JS_DefineProperty(js_context->context, global,
                            "window", v_global,
-                           NULL, NULL,
                            JSPROP_READONLY | JSPROP_PERMANENT))
         g_error("No memory to export global object as 'window'");
 
@@ -721,8 +719,9 @@ gjs_context_define_string_array(GjsContext  *js_context,
                                 GError       **error)
 {
     JSAutoCompartment ac(js_context->context, js_context->global);
+    JS::RootedObject global_root(js_context->context, js_context->global);
     if (!gjs_define_string_array(js_context->context,
-                                 js_context->global,
+                                 global_root,
                                  array_name, array_length, array_values,
                                  JSPROP_READONLY | JSPROP_PERMANENT)) {
         gjs_log_exception(js_context->context);
@@ -767,7 +766,7 @@ gjs_object_get_property_const(JSContext             *cx,
                               JS::MutableHandleValue value_p)
 {
     JS::RootedId pname(cx, gjs_context_get_const_string(cx, property_name));
-    return JS_GetPropertyById(cx, obj, pname, value_p.address());
+    return JS_GetPropertyById(cx, obj, pname, value_p);
 }
 
 /**
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index ec2ad31..47be2da 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -406,8 +406,7 @@ get_array_from_js_value(JSContext             *context,
     g_return_val_if_fail(out_array != NULL, false);
     g_return_val_if_fail(*out_array == NULL, false);
 
-    JS::RootedObject js_array(context, &value.toObject());
-    if (!JS_IsArrayObject(context, js_array)) {
+    if (!JS_IsArrayObject(context, value)) {
         g_critical("Returned object from is not an array");
         return false;
     }
@@ -417,6 +416,7 @@ get_array_from_js_value(JSContext             *context,
      * preallocate to. */
     GArray *c_side_array = g_array_new(true, true, array_element_size);
     u_int32_t js_array_len;
+    JS::RootedObject js_array(context, &value.toObject());
 
     if (element_clear_func)
         g_array_set_clear_func(c_side_array, element_clear_func);
@@ -425,7 +425,7 @@ get_array_from_js_value(JSContext             *context,
         u_int32_t i = 0;
         JS::RootedValue element(context);
         for (; i < js_array_len; ++i) {
-            if (!JS_GetElement(context, js_array, i, element.address())) {
+            if (!JS_GetElement(context, js_array, i, &element)) {
                 g_array_unref(c_side_array);
                 gjs_throw(context, "Failed to get function names array element %d", i);
                 return false;
@@ -472,12 +472,11 @@ get_executed_lines_for(JSContext        *context,
 {
     GArray *array = NULL;
     JS::RootedValue rval(context);
+    JS::AutoValueArray<1> args(context);
+    args[0].set(filename_value);
 
-    /* Removing const with cast is OK because the function arguments are not
-     * mutated in JS_CallFunction */
     if (!JS_CallFunctionName(context, coverage_statistics, "getExecutedLinesFor",
-                             1, (JS::Value *) filename_value.address(),
-                             rval.address())) {
+                             args, &rval)) {
         gjs_log_exception(context);
         return NULL;
     }
@@ -585,12 +584,11 @@ get_functions_for(JSContext        *context,
 {
     GArray *array = NULL;
     JS::RootedValue rval(context);
+    JS::AutoValueArray<1> args(context);
+    args[0].set(filename_value);
 
-    /* Removing const with cast is OK because the function arguments are not
-     * mutated in JS_CallFunction */
     if (!JS_CallFunctionName(context, coverage_statistics, "getFunctionsFor",
-                             1, (JS::Value *) filename_value.address(),
-                             rval.address())) {
+                             args, &rval)) {
         gjs_log_exception(context);
         return NULL;
     }
@@ -680,7 +678,7 @@ convert_and_insert_branch_info(GArray         *array,
         JS::RootedValue branch_exits_value(context);
         GArray *branch_exits_array = NULL;
 
-        if (!JS_GetProperty(context, object, "exits", branch_exits_value.address()) ||
+        if (!JS_GetProperty(context, object, "exits", &branch_exits_value) ||
             !branch_exits_value.isObject()) {
             gjs_throw(context, "Failed to get exits property from element");
             return false;
@@ -714,13 +712,12 @@ get_branches_for(JSContext        *context,
                  JS::HandleValue   filename_value)
 {
     GArray *array = NULL;
+    JS::AutoValueArray<1> args(context);
+    args[0].set(filename_value);
     JS::RootedValue rval(context);
 
-    /* Removing const with cast is OK because the function arguments are not
-     * mutated in JS_CallFunction */
     if (!JS_CallFunctionName(context, coverage_statistics, "getBranchesFor",
-                             1, (JS::Value *) filename_value.address(),
-                             rval.address())) {
+                             args, &rval)) {
         gjs_log_exception(context);
         return NULL;
     }
@@ -855,7 +852,7 @@ get_covered_files(GjsCoverage *coverage)
     uint32_t n_files;
 
     if (!JS_CallFunctionName(context, rooted_priv, "getCoveredFiles",
-                             0, NULL, rval.address())) {
+                             JS::HandleValueArray::empty(), &rval)) {
         gjs_log_exception(context);
         return NULL;
     }
@@ -871,7 +868,7 @@ get_covered_files(GjsCoverage *coverage)
     JS::RootedValue element(context);
     for (uint32_t i = 0; i < n_files; i++) {
         char *file;
-        if (!JS_GetElement(context, files_obj, i, element.address()))
+        if (!JS_GetElement(context, files_obj, i, &element))
             goto error;
 
         if (!gjs_string_to_utf8(context, element, &file))
@@ -1013,9 +1010,8 @@ gjs_serialize_statistics(GjsCoverage *coverage)
     JS::RootedValue string_value_return(js_runtime);
 
     if (!JS_CallFunctionName(js_context, rooted_priv, "stringify",
-                             0,
-                             NULL,
-                             string_value_return.address())) {
+                             JS::HandleValueArray::empty(),
+                             &string_value_return)) {
         gjs_log_exception(js_context);
         return NULL;
     }
@@ -1169,9 +1165,8 @@ coverage_statistics_has_stale_cache(GjsCoverage *coverage)
     JS::RootedObject rooted_priv(js_context, priv->coverage_statistics);
     JS::RootedValue stale_cache_value(js_context);
     if (!JS_CallFunctionName(js_context, rooted_priv, "staleCache",
-                             0,
-                             NULL,
-                             stale_cache_value.address())) {
+                             JS::HandleValueArray::empty(),
+                             &stale_cache_value)) {
         gjs_log_exception(js_context);
         g_error("Failed to call into javascript to get stale cache value. This is a bug");
     }
@@ -1258,8 +1253,7 @@ gjs_coverage_init(GjsCoverage *self)
 static JSClass coverage_global_class = {
     "GjsCoverageGlobal", JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
     JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
 };
 
 static bool
@@ -1379,8 +1373,7 @@ coverage_get_file_modification_time(JSContext *context,
         goto out;
 
     if (gjs_get_path_mtime(filename, &mtime)) {
-        JS::RootedObject mtime_values_array(runtime,
-                                            JS_NewArrayObject(context, 0, NULL));
+        JS::RootedObject mtime_values_array(runtime, JS_NewArrayObject(context, 0));
         if (!JS_DefineElement(context, mtime_values_array, 0, JS::Int32Value(mtime.tv_sec), NULL, NULL, 0))
             goto out;
         if (!JS_DefineElement(context, mtime_values_array, 1, JS::Int32Value(mtime.tv_usec), NULL, NULL, 0))
@@ -1494,10 +1487,8 @@ gjs_run_script_in_coverage_compartment(GjsCoverage *coverage,
     JSContext          *js_context = (JSContext *) gjs_context_get_native_context(priv->context);
     JSAutoCompartment ac(js_context, priv->coverage_statistics);
     JS::RootedValue rval(js_context);
-    if (!gjs_eval_with_scope(js_context,
-                             priv->coverage_statistics,
-                             script,
-                             strlen(script),
+    JS::RootedObject rooted_priv(js_context, priv->coverage_statistics);
+    if (!gjs_eval_with_scope(js_context, rooted_priv, script, strlen(script),
                              "<coverage_modifier>",
                              &rval)) {
         gjs_log_exception(js_context);
@@ -1522,10 +1513,7 @@ gjs_inject_value_into_coverage_compartment(GjsCoverage     *coverage,
     JS::RootedObject coverage_global_scope(JS_GetRuntime(js_context),
                                            JS_GetGlobalForObject(js_context, priv->coverage_statistics));
 
-    /* Removing const with cast is OK because the property value is not
-     * mutated in JS_SetProperty */
-    if (!JS_SetProperty(js_context, coverage_global_scope, property,
-                        (JS::Value *) value.address())) {
+    if (!JS_SetProperty(js_context, coverage_global_scope, property, value)) {
         g_warning("Failed to set property %s to requested value", property);
         return false;
     }
@@ -1549,7 +1537,7 @@ gjs_wrap_root_importer_in_compartment(JSContext *context,
 
     JS::RootedObject wrapped_importer(JS_GetRuntime(context),
                                       importer.toObjectOrNull());
-    if (!JS_WrapObject(context, wrapped_importer.address())) {
+    if (!JS_WrapObject(context, &wrapped_importer)) {
         return NULL;
     }
 
@@ -1571,20 +1559,19 @@ bootstrap_coverage(GjsCoverage *coverage)
     JS::CompartmentOptions options;
     options.setVersion(JSVERSION_LATEST);
     JS::RootedObject debugger_compartment(JS_GetRuntime(context),
-                                          JS_NewGlobalObject(context, &coverage_global_class, NULL, 
options));
+        JS_NewGlobalObject(context, &coverage_global_class, NULL,
+                           JS::FireOnNewGlobalHook, options));
     {
         JSAutoCompartment compartment(context, debugger_compartment);
         JS::RootedObject debuggeeWrapper(context, debuggee);
-        if (!JS_WrapObject(context, debuggeeWrapper.address())) {
+        if (!JS_WrapObject(context, &debuggeeWrapper)) {
             gjs_throw(context, "Failed to wrap debugeee");
             return false;
         }
 
         JS::RootedValue debuggeeWrapperValue(context, JS::ObjectValue(*debuggeeWrapper));
-        /* Removing const with cast is OK because the property value is not
-         * mutated in JS_SetProperty */
         if (!JS_SetProperty(context, debugger_compartment, "debuggee",
-                            (JS::Value *) debuggeeWrapperValue.address())) {
+                            debuggeeWrapperValue)) {
             gjs_throw(context, "Failed to set debuggee property");
             return false;
         }
@@ -1660,15 +1647,13 @@ bootstrap_coverage(GjsCoverage *coverage)
         /* Now create the array to pass the desired prefixes over */
         JSObject *prefixes = gjs_build_string_array(context, -1, priv->prefixes);
 
-        JS::Value coverage_statistics_constructor_arguments[] = {
-            JS::ObjectValue(*prefixes),
-            cache_value.get()
-        };
+        JS::AutoValueArray<2> coverage_statistics_constructor_args(context);
+        coverage_statistics_constructor_args[0].setObject(*prefixes);
+        coverage_statistics_constructor_args[1].set(cache_value);
 
         JSObject *coverage_statistics = JS_New(context,
                                                coverage_statistics_constructor,
-                                               2,
-                                               coverage_statistics_constructor_arguments);
+                                               coverage_statistics_constructor_args);
 
         if (!coverage_statistics) {
             gjs_throw(context, "Failed to create coverage_statitiscs object");
@@ -1746,9 +1731,7 @@ gjs_clear_js_side_statistics_from_coverage_object(GjsCoverage *coverage)
         JS::RootedObject rooted_priv(js_context, priv->coverage_statistics);
         JS::RootedValue rval(JS_GetRuntime(js_context));
         if (!JS_CallFunctionName(js_context, rooted_priv, "deactivate",
-                                 0,
-                                 NULL,
-                                 rval.address())) {
+                                 JS::HandleValueArray::empty(), &rval)) {
             gjs_log_exception(js_context);
             g_error("Failed to deactivate debugger - this is a fatal error");
         }
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 09e2b52..eadd80d 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -74,7 +74,6 @@ define_meta_properties(JSContext       *context,
         JS::RootedValue file_val(context,
             JS::StringValue(JS_NewStringCopyZ(context, full_path)));
         if (!JS_DefineProperty(context, module_obj, "__file__", file_val,
-                               NULL, NULL,
                                /* don't set ENUMERATE since we wouldn't want to copy
                                 * this symbol to any other object for example.
                                 */
@@ -91,7 +90,6 @@ define_meta_properties(JSContext       *context,
 
     if (!JS_DefineProperty(context, module_obj,
                            "__moduleName__", module_name_val,
-                           NULL, NULL,
                            /* don't set ENUMERATE since we wouldn't want to copy
                             * this symbol to any other object for example.
                             */
@@ -100,7 +98,6 @@ define_meta_properties(JSContext       *context,
 
     if (!JS_DefineProperty(context, module_obj,
                            "__parentModule__", parent_module_val,
-                           NULL, NULL,
                            /* don't set ENUMERATE since we wouldn't want to copy
                             * this symbol to any other object for example.
                             */
@@ -138,7 +135,6 @@ define_import(JSContext       *context,
 {
     JS::RootedValue module_val(context, JS::ObjectValue(*module_obj));
     if (!JS_DefineProperty(context, obj, name, module_val,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "Failed to define '%s' in importer",
@@ -242,13 +238,13 @@ import_native_file(JSContext       *context,
 
     JS::RootedValue v_module(context, JS::ObjectValue(*module_obj));
     return JS_DefineProperty(context, obj, name, v_module,
-                             NULL, NULL, GJS_MODULE_PROP_FLAGS);
+                             GJS_MODULE_PROP_FLAGS);
 }
 
 static JSObject *
 create_module_object(JSContext *context)
 {
-    return JS_NewObject(context, NULL, NULL, NULL);
+    return JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr());
 }
 
 static bool
@@ -264,6 +260,7 @@ import_file(JSContext       *context,
     GError *error = NULL;
 
     JS::CompileOptions options(context);
+    JS::RootedValue ignored(context);
 
     if (!(g_file_load_contents(file, NULL, &script, &script_len, NULL, &error))) {
         if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY) &&
@@ -281,7 +278,7 @@ import_file(JSContext       *context,
     full_path = g_file_get_parse_name (file);
 
     if (!gjs_eval_with_scope(context, module_obj, script, script_len,
-                             full_path, NULL))
+                             full_path, &ignored))
         goto out;
 
     ret = true;
@@ -305,10 +302,8 @@ load_module_init(JSContext       *context,
         gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT));
     if (JS_HasPropertyById(context, in_object, module_init_name, &found) && found) {
         JS::RootedValue module_obj_val(context);
-        if (JS_GetPropertyById(context,
-                               in_object,
-                               module_init_name,
-                               module_obj_val.address())) {
+        if (JS_GetPropertyById(context, in_object,
+                               module_init_name, &module_obj_val)) {
             return &module_obj_val.toObject();
         }
     }
@@ -458,7 +453,7 @@ do_import(JSContext       *context,
 
     for (i = 0; i < search_path_len; ++i) {
         elem.setUndefined();
-        if (!JS_GetElement(context, search_path, i, elem.address())) {
+        if (!JS_GetElement(context, search_path, i, &elem)) {
             /* this means there was an exception, while elem.isUndefined()
              * means no element found
              */
@@ -492,14 +487,9 @@ do_import(JSContext       *context,
         module_obj.set(load_module_init(context, obj, full_path));
         if (module_obj != NULL) {
             JS::RootedValue obj_val(context);
-            if (JS_GetProperty(context,
-                               module_obj,
-                               name,
-                               obj_val.address())) {
+            if (JS_GetProperty(context, module_obj, name, &obj_val)) {
                 if (!obj_val.isUndefined() &&
-                    JS_DefineProperty(context, obj,
-                                      name, obj_val,
-                                      NULL, NULL,
+                    JS_DefineProperty(context, obj, name, obj_val,
                                       GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
                     result = true;
                     goto out;
@@ -697,7 +687,7 @@ importer_new_enumerate(JSContext  *context,
             GDir *dir = NULL;
 
             elem = JS::UndefinedValue();
-            if (!JS_GetElement(context, search_path, i, elem.address())) {
+            if (!JS_GetElement(context, search_path, i, &elem)) {
                 /* this means there was an exception, while elem.isUndefined()
                  * means no element found
                  */
@@ -763,7 +753,13 @@ importer_new_enumerate(JSContext  *context,
             g_free(dirname);
         }
 
-        statep.get().setPrivate(iter);
+        /* FIXME: setPrivate() is not in js::MutableValueOperations (see
+         * Value.h) and now SpiderMonkey is stricter with const for
+         * Handle::get(); how to do this correctly? This code might allow
+         * statep_private to get GC'd before going into statep. */
+        JS::Value statep_private;
+        statep_private.setPrivate(iter);
+        statep.set(statep_private);
 
         idp.set(INT_TO_JSID(iter->elements->len));
 
@@ -785,7 +781,7 @@ importer_new_enumerate(JSContext  *context,
                                          &element_val))
                 return false;
 
-            if (!JS_ValueToId(context, element_val, idp.address()))
+            if (!JS_ValueToId(context, element_val, idp))
                 return false;
 
             break;
@@ -901,8 +897,7 @@ struct JSClass gjs_importer_class = {
     (JSEnumerateOp) importer_new_enumerate, /* needs cast since it's the new enumerate signature */
     (JSResolveOp) importer_new_resolve, /* needs cast since it's the new resolve signature */
     JS_ConvertStub,
-    importer_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    importer_finalize
 };
 
 JSPropertySpec gjs_importer_proto_props[] = {
@@ -932,7 +927,7 @@ importer_new(JSContext *context,
                                   * prototype; NULL for
                                   * Object.prototype
                                   */
-                                 NULL,
+                                 JS::NullPtr(),
                                  &gjs_importer_class,
                                  /* constructor for instances (NULL for
                                   * none - just name the prototype like
@@ -957,7 +952,7 @@ importer_new(JSContext *context,
     }
 
     JS::RootedObject importer(context,
-        JS_NewObject(context, &gjs_importer_class, NULL, global));
+        JS_NewObject(context, &gjs_importer_class, JS::NullPtr(), global));
     if (importer == NULL)
         g_error("No memory to create importer importer");
 
@@ -1080,7 +1075,6 @@ gjs_define_importer(JSContext       *context,
 
     JS::RootedValue v_importer(context, JS::ObjectValue(*importer));
     if (!JS_DefineProperty(context, in_object, importer_name, v_importer,
-                           NULL, NULL,
                            GJS_MODULE_PROP_FLAGS))
         g_error("no memory to define importer property");
 
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 559cfec..9db3833 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -106,17 +106,19 @@ gjs_init_class_dynamic(JSContext              *context,
     if (static_fs && !JS_DefineFunctions(context, constructor, static_fs))
         goto out;
 
-    if (!JS_DefineProperty(context, constructor, "prototype", JS::ObjectValue(*prototype),
-                           JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT | JSPROP_READONLY))
+    if (!JS_DefineProperty(context, constructor, "prototype", prototype,
+                           JSPROP_PERMANENT | JSPROP_READONLY,
+                           JS_PropertyStub, JS_StrictPropertyStub))
         goto out;
-    if (!JS_DefineProperty(context, prototype, "constructor", JS::ObjectValue(*constructor),
-                           JS_PropertyStub, JS_StrictPropertyStub, 0))
+    if (!JS_DefineProperty(context, prototype, "constructor", constructor,
+                           0, JS_PropertyStub, JS_StrictPropertyStub))
         goto out;
 
     /* The constructor defined by JS_InitClass has no property attributes, but this
        is a more useful default for gjs */
-    if (!JS_DefineProperty(context, in_object, class_name, JS::ObjectValue(*constructor),
-                           JS_PropertyStub, JS_StrictPropertyStub, GJS_MODULE_PROP_FLAGS))
+    if (!JS_DefineProperty(context, in_object, class_name, constructor,
+                           GJS_MODULE_PROP_FLAGS,
+                           JS_PropertyStub, JS_StrictPropertyStub))
         goto out;
 
     res = true;
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 87f7901..3229350 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -246,8 +246,7 @@ parse_call_args_helper(JSContext    *cx,
     }
 
     try {
-        /* COMPAT: JS::CallArgs::operator[] will yield Handle in mozjs31 */
-        assign(cx, *fchar, nullable, args.handleOrUndefinedAt(param_ix), param_ref);
+        assign(cx, *fchar, nullable, args[param_ix], param_ref);
     } catch (char *message) {
         /* Our error messages are going to be more useful than whatever was
          * thrown by the various conversion functions */
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index 005f81c..bea2694 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -76,15 +76,16 @@ gjs_throw_valist(JSContext       *context,
 
     JS::RootedObject constructor(context);
     JS::RootedObject global(context, JS::CurrentGlobalOrNull(context));
-    JS::RootedValue v_constructor(context), v_message(context), new_exc(context);
+    JS::RootedValue v_constructor(context), new_exc(context);
+    JS::AutoValueArray<1> error_args(context);
     result = false;
 
-    if (!gjs_string_from_utf8(context, s, -1, &v_message)) {
+    if (!gjs_string_from_utf8(context, s, -1, error_args[0])) {
         JS_ReportError(context, "Failed to copy exception string");
         goto out;
     }
 
-    if (!JS_GetProperty(context, global, error_class, v_constructor.address()) ||
+    if (!JS_GetProperty(context, global, error_class, &v_constructor) ||
         !v_constructor.isObject()) {
         JS_ReportError(context, "??? Missing Error constructor in global object?");
         goto out;
@@ -92,7 +93,7 @@ gjs_throw_valist(JSContext       *context,
 
     /* throw new Error(message) */
     constructor = &v_constructor.toObject();
-    new_exc.setObjectOrNull(JS_New(context, constructor, 1, v_message.address()));
+    new_exc.setObjectOrNull(JS_New(context, constructor, error_args));
     JS_SetPendingException(context, new_exc);
 
     result = true;
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 1707256..6143b47 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -313,7 +313,7 @@ gjs_get_string_id (JSContext       *context,
 {
     JS::RootedValue id_val(context);
 
-    if (!JS_IdToValue(context, id, id_val.address()))
+    if (!JS_IdToValue(context, id, &id_val))
         return false;
 
     if (id_val.isString()) {
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 1095f86..db643ff 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -47,8 +47,7 @@ gjs_util_error_quark (void)
 static JSClass global_class = {
     "GjsGlobal", JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
     JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
-    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
-    JSCLASS_NO_OPTIONAL_MEMBERS
+    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
 };
 
 /**
@@ -92,7 +91,7 @@ gjs_init_context_standard (JSContext              *context,
 
     compartment_options.setVersion(JSVERSION_LATEST);
     global.set(JS_NewGlobalObject(context, &global_class, NULL,
-                                  compartment_options));
+                                  JS::FireOnNewGlobalHook, compartment_options));
     if (global == NULL)
         return false;
 
@@ -169,7 +168,7 @@ gjs_object_require_property(JSContext             *context,
 {
     value.setUndefined();
 
-    if (G_UNLIKELY(!JS_GetPropertyById(context, obj, property_name, value.address())))
+    if (G_UNLIKELY(!JS_GetPropertyById(context, obj, property_name, value)))
         return false;
 
     if (G_LIKELY(!value.isUndefined()))
@@ -188,7 +187,7 @@ gjs_object_require_property_value(JSContext       *cx,
                                   bool            *value)
 {
     JS::RootedValue prop_value(cx);
-    if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+    if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
         prop_value.isBoolean()) {
         *value = prop_value.toBoolean();
         return true;
@@ -207,7 +206,7 @@ gjs_object_require_property_value(JSContext       *cx,
                                   int32_t         *value)
 {
     JS::RootedValue prop_value(cx);
-    if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+    if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
         prop_value.isInt32()) {
         *value = prop_value.toInt32();
         return true;
@@ -227,7 +226,7 @@ gjs_object_require_property_value(JSContext       *cx,
                                   char           **value)
 {
     JS::RootedValue prop_value(cx);
-    if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+    if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
         gjs_string_to_utf8(cx, prop_value, value)) {
         return true;
     }
@@ -245,7 +244,7 @@ gjs_object_require_property_value(JSContext              *cx,
                                   JS::MutableHandleObject value)
 {
     JS::RootedValue prop_value(cx);
-    if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+    if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
         prop_value.isObject()) {
         value.set(&prop_value.toObject());
         return true;
@@ -264,7 +263,7 @@ gjs_object_require_converted_property_value(JSContext       *cx,
                                             uint32_t        *value)
 {
     JS::RootedValue prop_value(cx);
-    if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+    if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
         JS::ToUint32(cx, prop_value, value)) {
         return true;
     }
@@ -318,7 +317,7 @@ gjs_build_string_array(JSContext   *context,
         elems.append(element);
     }
 
-    return JS_NewArrayObject(context, elems.length(), &elems[0]);
+    return JS_NewArrayObject(context, elems);
 }
 
 JSObject*
@@ -336,8 +335,7 @@ gjs_define_string_array(JSContext       *context,
 
     if (array != NULL) {
         JS::RootedValue v_array(context, JS::ObjectValue(*array));
-        if (!JS_DefineProperty(context, in_object, array_name, v_array,
-                               NULL, NULL, attrs))
+        if (!JS_DefineProperty(context, in_object, array_name, v_array, attrs))
             array = NULL;
     }
 
@@ -619,7 +617,7 @@ gjs_log_exception(JSContext  *context)
     JS_BeginRequest(context);
 
     JS::RootedValue exc(context);
-    if (!JS_GetPendingException(context, exc.address()))
+    if (!JS_GetPendingException(context, &exc))
         goto out;
 
     JS_ClearPendingException(context);
@@ -860,14 +858,14 @@ gjs_eval_with_scope(JSContext             *context,
 
     JS::RootedObject eval_obj(context, object);
     if (!eval_obj)
-        eval_obj = JS_NewObject(context, NULL, NULL, NULL);
+        eval_obj = JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr());
 
     JS::CompileOptions options(context);
     options.setUTF8(true)
            .setFileAndLine(filename, start_line_number)
-           .setSourcePolicy(JS::CompileOptions::LAZY_SOURCE);
+           .setSourceIsLazy(true);
 
-    if (!JS::Evaluate(context, eval_obj, options, script, script_len, retval.address()))
+    if (!JS::Evaluate(context, eval_obj, options, script, script_len, retval))
         return false;
 
     gjs_schedule_gc_if_needed(context);
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 0ed6b3f..b9a0b61 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -195,8 +195,7 @@ static struct JSClass gjs_##cname##_class = { \
     JS_EnumerateStub,\
     (JSResolveOp) gjs_##cname##_new_resolve, \
     JS_ConvertStub, \
-    gjs_##cname##_finalize, \
-    JSCLASS_NO_OPTIONAL_MEMBERS \
+    gjs_##cname##_finalize \
 }; \
 JS::Value                                                                      \
 gjs_##cname##_create_proto(JSContext *context,                                 \
@@ -208,7 +207,7 @@ gjs_##cname##_create_proto(JSContext *context,                                 \
     JS::RootedObject global(context, gjs_get_import_global(context));          \
     JS::RootedId class_name(context,                                           \
         gjs_intern_string_to_id(context, gjs_##cname##_class.name));           \
-    if (!JS_GetPropertyById(context, global, class_name, rval.address()))      \
+    if (!JS_GetPropertyById(context, global, class_name, &rval))               \
         return JS::NullValue(); \
     if (rval.isUndefined()) { \
         JS::RootedObject prototype(context,                                    \
@@ -225,14 +224,14 @@ gjs_##cname##_create_proto(JSContext *context,                                 \
             return JS::NullValue(); \
         } \
         if (!JS_DefineProperty(context, module, proto_name, \
-                               rval, NULL, NULL, GJS_MODULE_PROP_FLAGS)) \
+                               rval, GJS_MODULE_PROP_FLAGS))                   \
             return JS::NullValue(); \
         if (gtype != G_TYPE_NONE) { \
             JS::RootedValue value(context,                                     \
                 JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context,  \
                                                                      gtype))); \
             JS_DefineProperty(context, &rval.toObject(), "$gtype", value, \
-                              NULL, NULL, JSPROP_PERMANENT);            \
+                              JSPROP_PERMANENT);                               \
         } \
     } \
     return rval; \
@@ -267,7 +266,7 @@ gjs_##name##_constructor(JSContext  *context,           \
             gjs_throw_constructor_error(context);                              \
             return false;                                                      \
         }                                                                      \
-        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
+        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, argv); \
         if (object == NULL)                                                    \
             return false;                                                      \
     }
diff --git a/gjs/stack.cpp b/gjs/stack.cpp
index c99201f..7dba9b1 100644
--- a/gjs/stack.cpp
+++ b/gjs/stack.cpp
@@ -63,7 +63,8 @@ gjs_context_get_frame_info(JSContext                              *context,
                                            error_id, &constructor))
         return false;
 
-    JS::RootedObject err_obj(context, JS_New(context, constructor, 0, NULL));
+    JS::RootedObject err_obj(context, JS_New(context, constructor,
+                                             JS::HandleValueArray::empty()));
 
     if (!stack.empty() &&
         !gjs_object_get_property_const(context, err_obj, GJS_STRING_STACK,


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