[gjs/wip/ptomato/mozjs31: 12/12] WIP - stuff



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

    WIP - stuff

 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.cpp          |   30 +++++++--------
 gjs/jsapi-util.h            |    2 +-
 8 files changed, 97 insertions(+), 125 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index b0eea35..0681fbc 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.cpp b/gjs/jsapi-util.cpp
index 9516265..05979fc 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 f307349..68de9a2 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -267,7 +267,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;                                                      \
     }


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