[gjs/mozjs78: 8/22] js: Refactor Array-related JSAPI calls.




commit c60c0c04f60529a7ac70dcb0945b396f3f6dea1d
Author: Evan Welsh <noreply evanwelsh com>
Date:   Sat Jul 4 22:09:47 2020 -0500

    js: Refactor Array-related JSAPI calls.
    
    - <js/Array.h> and <js/ValueArray.h> are new headers.
    - Rename JS_NewArrayObject to JS::NewArrayObject.
    - Rename JS_GetArrayLength to JS::GetArrayLength.
    - Rename JS_IsArrayObject to JS::IsArrayObject.
    - Rename JS::AutoValueArray to JS::RootedValueArray.
    
    See: GNOME/gjs#329

 gi/arg.cpp                  |  17 +++---
 gi/boxed.cpp                |   4 +-
 gi/closure.cpp              |   1 +
 gi/function.cpp             |   5 +-
 gi/gerror.cpp               |   3 +-
 gi/gobject.cpp              |   2 +-
 gi/private.cpp              |  13 +++--
 gi/value.cpp                |   1 +
 gjs/context.cpp             |   2 +-
 gjs/importer.cpp            |   9 +--
 gjs/jsapi-dynamic-class.cpp |   1 +
 gjs/jsapi-util-error.cpp    |   3 +-
 gjs/jsapi-util.cpp          |   4 +-
 modules/cairo-context.cpp   | 136 ++++++++++++++++++++++++--------------------
 test/gjs-tests.cpp          |   6 +-
 15 files changed, 116 insertions(+), 91 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index d02d37d0..d945a38a 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -35,6 +35,7 @@
 #include <glib-object.h>
 #include <glib.h>
 
+#include <js/Array.h>
 #include <js/CharacterEncoding.h>
 #include <js/Conversions.h>
 #include <js/GCVector.h>            // for RootedVector, MutableWrappedPtrOp...
@@ -43,9 +44,9 @@
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>        // for JS_ReportOutOfMemory, JS_GetElement
 #include <jsfriendapi.h>  // for JS_IsUint8Array, JS_GetObjectFunc...
-#include <mozilla/Vector.h>
 
 #include "gi/arg-inl.h"
 #include "gi/arg.h"
@@ -779,7 +780,7 @@ gjs_array_from_strv(JSContext             *context,
             return false;
     }
 
-    JS::RootedObject obj(context, JS_NewArrayObject(context, elems));
+    JS::RootedObject obj(context, JS::NewArrayObject(context, elems));
     if (!obj)
         return false;
 
@@ -1200,7 +1201,7 @@ gjs_array_from_flat_gvalue_array(JSContext             *context,
 
     // a null array pointer takes precedence over whatever `length` says
     if (!values) {
-        JSObject* jsarray = JS_NewArrayObject(context, 0);
+        JSObject* jsarray = JS::NewArrayObject(context, 0);
         if (!jsarray)
             return false;
         value.setObject(*jsarray);
@@ -1225,7 +1226,7 @@ gjs_array_from_flat_gvalue_array(JSContext             *context,
 
     if (result) {
         JSObject *jsarray;
-        jsarray = JS_NewArrayObject(context, elems);
+        jsarray = JS::NewArrayObject(context, elems);
         value.setObjectOrNull(jsarray);
     }
 
@@ -2376,7 +2377,7 @@ gjs_array_from_g_list (JSContext             *context,
         }
     }
 
-    JS::RootedObject obj(context, JS_NewArrayObject(context, elems));
+    JS::RootedObject obj(context, JS::NewArrayObject(context, elems));
     if (!obj)
         return false;
 
@@ -2432,7 +2433,7 @@ gjs_array_from_carray_internal (JSContext             *context,
 
     // a null array pointer takes precedence over whatever `length` says
     if (!array) {
-        JSObject* jsarray = JS_NewArrayObject(context, 0);
+        JSObject* jsarray = JS::NewArrayObject(context, 0);
         if (!jsarray)
             return false;
         value_p.setObject(*jsarray);
@@ -2549,7 +2550,7 @@ gjs_array_from_carray_internal (JSContext             *context,
           return false;
     }
 
-    JS::RootedObject obj(context, JS_NewArrayObject(context, elems));
+    JS::RootedObject obj(context, JS::NewArrayObject(context, elems));
     if (!obj)
         return false;
 
@@ -2767,7 +2768,7 @@ gjs_array_from_zero_terminated_c_array (JSContext             *context,
           return false;
     }
 
-    JS::RootedObject obj(context, JS_NewArrayObject(context, elems));
+    JS::RootedObject obj(context, JS::NewArrayObject(context, elems));
     if (!obj)
         return false;
 
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 2537159f..05e4a496 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -40,9 +40,9 @@
 #include <js/TracingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>  // for IdVector, JS_AtomizeAndPinJSString
 #include <mozilla/HashTable.h>
-#include <mozilla/Vector.h>
 
 #include "gi/arg-inl.h"
 #include "gi/arg.h"
@@ -608,7 +608,7 @@ bool BoxedInstance::set_nested_interface_object(JSContext* context,
      */
     BoxedBase* source_priv = get_copy_source(context, value);
     if (!source_priv) {
-        JS::AutoValueArray<1> args(context);
+        JS::RootedValueArray<1> args(context);
         args[0].set(value);
         JS::RootedObject tmp_object(context,
             gjs_construct_object_dynamic(context, proto, args));
diff --git a/gi/closure.cpp b/gi/closure.cpp
index f654cff4..e9cfb09b 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -29,6 +29,7 @@
 
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>  // for JS_IsExceptionPending, Call, JS_Get...
 
 #include "gi/closure.h"
diff --git a/gi/function.cpp b/gi/function.cpp
index e194b8ec..a5cd2d41 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -36,6 +36,7 @@
 #include <glib-object.h>
 #include <glib.h>
 
+#include <js/Array.h>
 #include <js/CallArgs.h>
 #include <js/Class.h>
 #include <js/GCVector.h>
@@ -396,7 +397,7 @@ static void gjs_callback_closure(ffi_cif* cif [[maybe_unused]], void* result,
         }
     } else {
         bool is_array = rval.isObject();
-        if (!JS_IsArrayObject(context, rval, &is_array))
+        if (!JS::IsArrayObject(context, rval, &is_array))
             goto out;
 
         if (!is_array) {
@@ -980,7 +981,7 @@ release:
         if (function->js_out_argc == 1) {
             args.rval().set(return_values[0]);
         } else {
-            JSObject* array = JS_NewArrayObject(context, return_values);
+            JSObject* array = JS::NewArrayObject(context, return_values);
             if (!array) {
                 failed = true;
             } else {
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 851f9dec..5382210f 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -36,6 +36,7 @@
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>    // for JS_DefinePropertyById, JS_GetProp...
 #include <jspubtd.h>  // for JSProtoKey, JSProto_Error, JSProt...
 
@@ -344,7 +345,7 @@ static JSObject *
 gjs_error_from_js_gerror(JSContext *cx,
                          GError    *gerror)
 {
-    JS::AutoValueArray<1> error_args(cx);
+    JS::RootedValueArray<1> error_args(cx);
     if (!gjs_string_from_utf8(cx, gerror->message, error_args[0]))
         return nullptr;
 
diff --git a/gi/gobject.cpp b/gi/gobject.cpp
index 81902374..3e4f892c 100644
--- a/gi/gobject.cpp
+++ b/gi/gobject.cpp
@@ -127,7 +127,7 @@ static GObject* gjs_object_constructor(
                                      construct_properties[i].pspec))
                 return nullptr;
 
-        JS::AutoValueArray<1> args(cx);
+        JS::RootedValueArray<1> args(cx);
         args[0].set(JS::ObjectValue(*props_hash));
         object = JS_New(cx, constructor, args);
     } else {
diff --git a/gi/private.cpp b/gi/private.cpp
index 9159776d..44c73cc3 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -29,13 +29,14 @@
 #include <glib-object.h>
 #include <glib.h>
 
+#include <js/Array.h>  // for JS::GetArrayLength,
 #include <js/CallArgs.h>
 #include <js/Id.h>  // for JSID_TO_SYMBOL
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
-#include <jsapi.h>       // for JS_GetArrayLength, JS_GetElement
+#include <jsapi.h>       // for JS_GetElement
 
 #include "gi/gobject.h"
 #include "gi/gtype.h"
@@ -106,7 +107,7 @@ static bool validate_interfaces_and_properties_args(JSContext* cx,
                                                     uint32_t* n_interfaces,
                                                     uint32_t* n_properties) {
     bool is_array;
-    if (!JS_IsArrayObject(cx, interfaces, &is_array))
+    if (!JS::IsArrayObject(cx, interfaces, &is_array))
         return false;
     if (!is_array) {
         gjs_throw(cx, "Invalid parameter interfaces (expected Array)");
@@ -114,10 +115,10 @@ static bool validate_interfaces_and_properties_args(JSContext* cx,
     }
 
     uint32_t n_int;
-    if (!JS_GetArrayLength(cx, interfaces, &n_int))
+    if (!JS::GetArrayLength(cx, interfaces, &n_int))
         return false;
 
-    if (!JS_IsArrayObject(cx, properties, &is_array))
+    if (!JS::IsArrayObject(cx, properties, &is_array))
         return false;
     if (!is_array) {
         gjs_throw(cx, "Invalid parameter properties (expected Array)");
@@ -125,7 +126,7 @@ static bool validate_interfaces_and_properties_args(JSContext* cx,
     }
 
     uint32_t n_prop;
-    if (!JS_GetArrayLength(cx, properties, &n_prop))
+    if (!JS::GetArrayLength(cx, properties, &n_prop))
         return false;
 
     if (n_interfaces)
@@ -384,7 +385,7 @@ static bool gjs_signal_new(JSContext* cx, unsigned argc, JS::Value* vp) {
     }
 
     uint32_t n_parameters;
-    if (!JS_GetArrayLength(cx, params_obj, &n_parameters))
+    if (!JS::GetArrayLength(cx, params_obj, &n_parameters))
         return false;
 
     GType* params = g_newa(GType, n_parameters);
diff --git a/gi/value.cpp b/gi/value.cpp
index ba82c26d..3bf09dde 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -38,6 +38,7 @@
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>  // for InformalValueTypeName, JS_ClearPendingException
 #include <mozilla/Unused.h>
 
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 747f6f38..ea12fbca 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -65,10 +65,10 @@
 #include <js/UniquePtr.h>
 #include <js/Utility.h>  // for DeletePolicy
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>        // for JS_IsExceptionPending, ...
 #include <jsfriendapi.h>  // for DumpHeap, IgnoreNurseryObjects
 #include <mozilla/UniquePtr.h>
-#include <mozilla/Vector.h>
 
 #include "gi/object.h"
 #include "gi/private.h"
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index a013315a..d7780379 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -37,6 +37,7 @@
 #include <glib-object.h>
 #include <glib.h>
 
+#include <js/Array.h>
 #include <js/CallArgs.h>
 #include <js/CharacterEncoding.h>
 #include <js/Class.h>
@@ -479,14 +480,14 @@ static bool do_import(JSContext* context, JS::HandleObject obj, Importer* priv,
                                      atoms.search_path(), &search_path))
         return false;
 
-    if (!JS_IsArrayObject(context, search_path, &is_array))
+    if (!JS::IsArrayObject(context, search_path, &is_array))
         return false;
     if (!is_array) {
         gjs_throw(context, "searchPath property on importer is not an array");
         return false;
     }
 
-    if (!JS_GetArrayLength(context, search_path, &search_path_len)) {
+    if (!JS::GetArrayLength(context, search_path, &search_path_len)) {
         gjs_throw(context, "searchPath array has no length");
         return false;
     }
@@ -634,14 +635,14 @@ static bool importer_new_enumerate(JSContext* context, JS::HandleObject object,
                                      atoms.search_path(), &search_path))
         return false;
 
-    if (!JS_IsArrayObject(context, search_path, &is_array))
+    if (!JS::IsArrayObject(context, search_path, &is_array))
         return false;
     if (!is_array) {
         gjs_throw(context, "searchPath property on importer is not an array");
         return false;
     }
 
-    if (!JS_GetArrayLength(context, search_path, &search_path_len)) {
+    if (!JS::GetArrayLength(context, search_path, &search_path_len)) {
         gjs_throw(context, "searchPath array has no length");
         return false;
     }
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index a8bdbb34..eb7d98d3 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -35,6 +35,7 @@
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>        // for JS_DefineFunctions, JS_DefineProp...
 #include <jsfriendapi.h>  // for GetFunctionNativeReserved, NewFun...
 #include <jspubtd.h>      // for JSProto_TypeError
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index 509e3c92..6148c894 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -32,6 +32,7 @@
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
+#include <js/ValueArray.h>
 #include <jsapi.h>       // for JS_ReportErrorUTF8, BuildStackString
 #include <jspubtd.h>     // for JSProtoKey, JSProto_Error, JSProto...
 
@@ -83,7 +84,7 @@ gjs_throw_valist(JSContext       *context,
     JS::RootedObject constructor(context);
     JS::RootedValue v_constructor(context), exc_val(context);
     JS::RootedObject new_exc(context);
-    JS::AutoValueArray<1> error_args(context);
+    JS::RootedValueArray<1> error_args(context);
     result = false;
 
     if (!gjs_string_from_utf8(context, s, error_args[0])) {
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 2f8aee00..1c8a499b 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -38,6 +38,7 @@
 #include <utility>  // for move
 #include <vector>
 
+#include <js/Array.h>
 #include <js/CallArgs.h>
 #include <js/CharacterEncoding.h>
 #include <js/Class.h>
@@ -48,6 +49,7 @@
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>        // for JS_GetPropertyById, JS_ClearPendin...
 #include <jsfriendapi.h>  // for ProtoKeyToClass
 
@@ -236,7 +238,7 @@ JSObject* gjs_build_string_array(JSContext* context,
         elems.infallibleAppend(element);
     }
 
-    return JS_NewArrayObject(context, elems);
+    return JS::NewArrayObject(context, elems);
 }
 
 JSObject* gjs_define_string_array(JSContext* context,
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 45e8f7f0..d9cb02a7 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -29,6 +29,7 @@
 #include <girepository.h>
 #include <glib.h>
 
+#include <js/Array.h>  // for JS::NewArrayObject
 #include <js/CallArgs.h>
 #include <js/Class.h>
 #include <js/Conversions.h>
@@ -38,7 +39,7 @@
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
 #include <js/Value.h>
-#include <jsapi.h>  // for JS_SetElement, JS_NewArrayObject
+#include <jsapi.h>  // for JS_SetElement
 
 #include "gi/arg-inl.h"
 #include "gi/arg.h"
@@ -89,65 +90,76 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
     argv.rval().setBoolean(ret);                                           \
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
 
-#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC2FFAFF(method, cfunc, n1, n2)        \
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
-    double arg1, arg2;                                                     \
-    if (!gjs_parse_call_args(context, #method, argv, "ff",                 \
-                             #n1, &arg1, #n2, &arg2))                      \
-        return false;                                                      \
-    cfunc(cr, &arg1, &arg2);                                               \
-    if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {                        \
-      JS::RootedObject array(context,                                      \
-          JS_NewArrayObject(context, JS::HandleValueArray::empty()));      \
-      if (!array)                                                          \
-        return false;                                                      \
-      JS::RootedValue r(context, JS::NumberValue(arg1));                   \
-      if (!JS_SetElement(context, array, 0, r)) return false;              \
-      r.setNumber(arg2);                                                   \
-      if (!JS_SetElement(context, array, 1, r)) return false;              \
-      argv.rval().setObject(*array);                                       \
-    }                                                                      \
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
-
-#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC0AFF(method, cfunc)                  \
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
-    double arg1, arg2;                                                     \
-   _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(method)                                \
-    cfunc(cr, &arg1, &arg2);                                               \
-    if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {                        \
-      JS::RootedObject array(context,                                      \
-          JS_NewArrayObject(context, JS::HandleValueArray::empty()));      \
-      if (!array)                                                          \
-        return false;                                                      \
-      JS::RootedValue r(context, JS::NumberValue(arg1));                   \
-      if (!JS_SetElement(context, array, 0, r)) return false;              \
-      r.setNumber(arg2);                                                   \
-      if (!JS_SetElement(context, array, 1, r)) return false;              \
-      argv.rval().setObject(*array);                                       \
-    }                                                                      \
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
-
-#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC0AFFFF(method, cfunc)                \
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
-    double arg1, arg2, arg3, arg4;                                         \
-   _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(method)                                \
-    cfunc(cr, &arg1, &arg2, &arg3, &arg4);                                 \
-    {                                                                      \
-      JS::RootedObject array(context,                                      \
-          JS_NewArrayObject(context, JS::HandleValueArray::empty()));      \
-      if (!array)                                                          \
-        return false;                                                      \
-      JS::RootedValue r(context, JS::NumberValue(arg1));                   \
-      if (!JS_SetElement(context, array, 0, r)) return false;              \
-      r.setNumber(arg2);                                                   \
-      if (!JS_SetElement(context, array, 1, r)) return false;              \
-      r.setNumber(arg3);                                                   \
-      if (!JS_SetElement(context, array, 2, r)) return false;              \
-      r.setNumber(arg4);                                                   \
-      if (!JS_SetElement(context, array, 3, r)) return false;              \
-      argv.rval().setObject(*array);                                       \
-    }                                                                      \
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
+#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC2FFAFF(method, cfunc, n1, n2)         \
+    _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                            \
+    double arg1, arg2;                                                      \
+    if (!gjs_parse_call_args(context, #method, argv, "ff", #n1, &arg1, #n2, \
+                             &arg2))                                        \
+        return false;                                                       \
+    cfunc(cr, &arg1, &arg2);                                                \
+    if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {                         \
+        JS::RootedObject array(                                             \
+            context,                                                        \
+            JS::NewArrayObject(context, JS::HandleValueArray::empty()));    \
+        if (!array)                                                         \
+            return false;                                                   \
+        JS::RootedValue r(context, JS::NumberValue(arg1));                  \
+        if (!JS_SetElement(context, array, 0, r))                           \
+            return false;                                                   \
+        r.setNumber(arg2);                                                  \
+        if (!JS_SetElement(context, array, 1, r))                           \
+            return false;                                                   \
+        argv.rval().setObject(*array);                                      \
+    }                                                                       \
+    _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
+
+#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC0AFF(method, cfunc)                \
+    _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                         \
+    double arg1, arg2;                                                   \
+    _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(method)                             \
+    cfunc(cr, &arg1, &arg2);                                             \
+    if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {                      \
+        JS::RootedObject array(                                          \
+            context,                                                     \
+            JS::NewArrayObject(context, JS::HandleValueArray::empty())); \
+        if (!array)                                                      \
+            return false;                                                \
+        JS::RootedValue r(context, JS::NumberValue(arg1));               \
+        if (!JS_SetElement(context, array, 0, r))                        \
+            return false;                                                \
+        r.setNumber(arg2);                                               \
+        if (!JS_SetElement(context, array, 1, r))                        \
+            return false;                                                \
+        argv.rval().setObject(*array);                                   \
+    }                                                                    \
+    _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
+
+#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC0AFFFF(method, cfunc)              \
+    _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                         \
+    double arg1, arg2, arg3, arg4;                                       \
+    _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(method)                             \
+    cfunc(cr, &arg1, &arg2, &arg3, &arg4);                               \
+    {                                                                    \
+        JS::RootedObject array(                                          \
+            context,                                                     \
+            JS::NewArrayObject(context, JS::HandleValueArray::empty())); \
+        if (!array)                                                      \
+            return false;                                                \
+        JS::RootedValue r(context, JS::NumberValue(arg1));               \
+        if (!JS_SetElement(context, array, 0, r))                        \
+            return false;                                                \
+        r.setNumber(arg2);                                               \
+        if (!JS_SetElement(context, array, 1, r))                        \
+            return false;                                                \
+        r.setNumber(arg3);                                               \
+        if (!JS_SetElement(context, array, 2, r))                        \
+            return false;                                                \
+        r.setNumber(arg4);                                               \
+        if (!JS_SetElement(context, array, 3, r))                        \
+            return false;                                                \
+        argv.rval().setObject(*array);                                   \
+    }                                                                    \
+    _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
 
 #define _GJS_CAIRO_CONTEXT_DEFINE_FUNC0F(method, cfunc)                    \
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
@@ -546,14 +558,14 @@ setDash_func(JSContext *context,
                              "offset", &offset))
         return false;
 
-    if (!JS_IsArrayObject(context, dashes, &is_array))
+    if (!JS::IsArrayObject(context, dashes, &is_array))
         return false;
     if (!is_array) {
         gjs_throw(context, "dashes must be an array");
         return false;
     }
 
-    if (!JS_GetArrayLength(context, dashes, &len)) {
+    if (!JS::GetArrayLength(context, dashes, &len)) {
         gjs_throw(context, "Can't get length of dashes");
         return false;
     }
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index 67bfcf5a..60f1b493 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -31,11 +31,13 @@
 #include <glib.h>
 #include <glib/gstdio.h>  // for g_unlink
 
+#include <js/Array.h>
 #include <js/CharacterEncoding.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
 #include <js/Value.h>
+#include <js/ValueArray.h>
 #include <jsapi.h>
 
 #include "gjs/context.h"
@@ -315,10 +317,10 @@ static void test_jsapi_util_debug_string_object_with_complicated_to_string(
         0xd83c, 0xdf6a,  /* cookie */
         0xd83c, 0xdf69,  /* doughnut */
     };
-    JS::AutoValueArray<2> contents(fx->cx);
+    JS::RootedValueArray<2> contents(fx->cx);
     contents[0].setString(JS_NewUCStringCopyN(fx->cx, desserts, 2));
     contents[1].setString(JS_NewUCStringCopyN(fx->cx, desserts + 2, 2));
-    JS::RootedObject array(fx->cx, JS_NewArrayObject(fx->cx, contents));
+    JS::RootedObject array(fx->cx, JS::NewArrayObject(fx->cx, contents));
     JS::RootedValue v_array(fx->cx, JS::ObjectValue(*array));
     char *debug_output = gjs_value_debug_string(fx->cx, v_array);
 


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