[gjs/mozjs31: 3/14] js: Use HandleValueArray as function param



commit 35aa419ab02846e385d0b244455a2cf15f9d9971
Author: Philip Chimento <philip endlessm com>
Date:   Wed Oct 26 16:33:57 2016 -0700

    js: Use HandleValueArray as function param
    
    JS::HandleValueArray is a useful way to pass arrays of arguments around,
    has handy constructors such that you can pass in JS::CallArgs directly.
    Therefore we refactor some functions to take it instead of argc, argv.
    This will make the following commit easier where we adapt to the new APIs
    of JS_New(), JS_CallFunction(), etc. which require JS::HandleValueArray.
    
    This requires some changes in the closure callback marshal as previously
    we were passing in an array that was longer with some empty elements at
    the end, and relying on argc not to fall off the end. Now that there is
    no argc parameter, we have to rearrange things a bit in that function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751252

 gi/boxed.cpp                |   18 ++++++-----
 gi/closure.cpp              |    9 ++---
 gi/closure.h                |    7 ++--
 gi/function.cpp             |   67 ++++++++++++++++++------------------------
 gi/function.h               |   22 ++++++--------
 gi/fundamental.cpp          |   15 ++++-----
 gi/object.cpp               |   31 +++++++++-----------
 gi/union.cpp                |    2 +-
 gi/value.cpp                |   57 +++++++++++++++---------------------
 gjs/jsapi-dynamic-class.cpp |    9 ++---
 gjs/jsapi-util.cpp          |   14 ++++-----
 gjs/jsapi-util.h            |   18 +++++------
 12 files changed, 120 insertions(+), 149 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 49e9f6b..665b211 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -339,7 +339,7 @@ boxed_invoke_constructor(JSContext             *context,
         return false;
 
     return gjs_call_function_value(context, JS::NullPtr(), js_constructor_func,
-                                   args.length(), args.array(), args.rval());
+                                   args, args.rval());
 }
 
 static bool
@@ -683,12 +683,12 @@ out:
 }
 
 static bool
-set_nested_interface_object (JSContext   *context,
-                             Boxed       *parent_priv,
-                             GIFieldInfo *field_info,
-                             GITypeInfo  *type_info,
-                             GIBaseInfo  *interface_info,
-                             JS::Value    value)
+set_nested_interface_object (JSContext      *context,
+                             Boxed          *parent_priv,
+                             GIFieldInfo    *field_info,
+                             GITypeInfo     *type_info,
+                             GIBaseInfo     *interface_info,
+                             JS::HandleValue value)
 {
     int offset;
     Boxed *proto_priv;
@@ -711,8 +711,10 @@ set_nested_interface_object (JSContext   *context,
      * to construct a new temporary object.
      */
     if (!boxed_get_copy_source(context, proto_priv, value, &source_priv)) {
+        JS::AutoValueArray<1> args(context);
+        args[0].set(value);
         JS::RootedObject tmp_object(context,
-                                    gjs_construct_object_dynamic(context, proto, 1, &value));
+            gjs_construct_object_dynamic(context, proto, args));
         if (!tmp_object)
             return false;
 
diff --git a/gi/closure.cpp b/gi/closure.cpp
index 8e8e7b5..4b1b07a 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -246,10 +246,9 @@ closure_set_invalid(gpointer  data,
 }
 
 void
-gjs_closure_invoke(GClosure              *closure,
-                   int                    argc,
-                   JS::Value             *argv,
-                   JS::MutableHandleValue retval)
+gjs_closure_invoke(GClosure                   *closure,
+                   const JS::HandleValueArray& args,
+                   JS::MutableHandleValue      retval)
 {
     Closure *c;
     JSContext *context;
@@ -278,7 +277,7 @@ gjs_closure_invoke(GClosure              *closure,
     if (!gjs_call_function_value(context,
                                  /* "this" object; null is some kind of default presumably */
                                  JS::NullPtr(),
-                                 v_closure, argc, argv, retval)) {
+                                 v_closure, args, retval)) {
         /* Exception thrown... */
         gjs_debug_closure("Closure invocation failed (exception should "
                           "have been thrown) closure %p callable %p",
diff --git a/gi/closure.h b/gi/closure.h
index 39cd54c..ddb25ba 100644
--- a/gi/closure.h
+++ b/gi/closure.h
@@ -36,10 +36,9 @@ GClosure*  gjs_closure_new           (JSContext    *context,
                                       const char   *description,
                                       bool          root_function);
 
-void gjs_closure_invoke(GClosure              *closure,
-                        int                    argc,
-                        JS::Value             *argv,
-                        JS::MutableHandleValue retval);
+void gjs_closure_invoke(GClosure                   *closure,
+                        const JS::HandleValueArray& args,
+                        JS::MutableHandleValue      retval);
 
 JSContext* gjs_closure_get_context   (GClosure     *closure);
 bool       gjs_closure_is_valid      (GClosure     *closure);
diff --git a/gi/function.cpp b/gi/function.cpp
index fe6afc2..dc25374 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -675,8 +675,7 @@ static bool
 gjs_invoke_c_function(JSContext                              *context,
                       Function                               *function,
                       JS::HandleObject                        obj, /* "this" object */
-                      unsigned                                js_argc,
-                      JS::Value                              *js_argv,
+                      const JS::HandleValueArray&             args,
                       mozilla::Maybe<JS::MutableHandleValue>& js_rval,
                       GIArgument                             *r_value)
 {
@@ -747,13 +746,14 @@ gjs_invoke_c_function(JSContext                              *context,
      * don't allow too few args, since that would break.
      */
 
-    if (js_argc < function->expected_js_argc) {
-        gjs_throw(context, "Too few arguments to %s %s.%s expected %d got %d",
+    if (args.length() < function->expected_js_argc) {
+        gjs_throw(context,
+                  "Too few arguments to %s %s.%s expected %d got %" G_GSIZE_FORMAT,
                   is_method ? "method" : "function",
                   g_base_info_get_namespace( (GIBaseInfo*) function->info),
                   g_base_info_get_name( (GIBaseInfo*) function->info),
                   function->expected_js_argc,
-                  js_argc);
+                  args.length());
         return false;
     }
 
@@ -849,28 +849,26 @@ gjs_invoke_c_function(JSContext                              *context,
                 GIScopeType scope = g_arg_info_get_scope(&arg_info);
                 GjsCallbackTrampoline *trampoline;
                 ffi_closure *closure;
-                /* COMPAT: Avoid this extra root by changing the function's
-                 * in parameter to JS::HandleValueArray in mozjs31 */
-                JS::RootedValue value(context, js_argv[js_arg_pos]);
+                JS::HandleValue current_arg = args[js_arg_pos];
 
-                if (value.isNull() && g_arg_info_may_be_null(&arg_info)) {
+                if (current_arg.isNull() && g_arg_info_may_be_null(&arg_info)) {
                     closure = NULL;
                     trampoline = NULL;
                 } else {
-                    if (!(JS_TypeOfValue(context, value) == JSTYPE_FUNCTION)) {
+                    if (!(JS_TypeOfValue(context, current_arg) == JSTYPE_FUNCTION)) {
                         gjs_throw(context, "Error invoking %s.%s: Expected function for callback argument 
%s, got %s",
                                   g_base_info_get_namespace( (GIBaseInfo*) function->info),
                                   g_base_info_get_name( (GIBaseInfo*) function->info),
                                   g_base_info_get_name( (GIBaseInfo*) &arg_info),
                                   JS_GetTypeName(context,
-                                                 JS_TypeOfValue(context, value)));
+                                                 JS_TypeOfValue(context, current_arg)));
                         failed = true;
                         break;
                     }
 
                     callable_info = (GICallableInfo*) g_type_info_get_interface(&ainfo);
                     trampoline = gjs_callback_trampoline_new(context,
-                                                             value,
+                                                             current_arg,
                                                              callable_info,
                                                              scope,
                                                              false);
@@ -908,11 +906,8 @@ gjs_invoke_c_function(JSContext                              *context,
                 gint array_length_pos = g_type_info_get_array_length(&ainfo);
                 gsize length;
 
-                /* COMPAT: Avoid this extra root by changing the function's
-                 * in parameter to JS::HandleValueArray in mozjs31 */
-                JS::RootedValue v_arg(context, js_argv[js_arg_pos]);
-                if (!gjs_value_to_explicit_array(context, v_arg, &arg_info,
-                                                 in_value, &length)) {
+                if (!gjs_value_to_explicit_array(context, args[js_arg_pos],
+                                                 &arg_info, in_value, &length)) {
                     failed = true;
                     break;
                 }
@@ -945,11 +940,9 @@ gjs_invoke_c_function(JSContext                              *context,
             }
             case PARAM_NORMAL: {
                 /* Ok, now just convert argument normally */
-                g_assert_cmpuint(js_arg_pos, <, js_argc);
-                /* COMPAT: Avoid this extra root by changing the function's
-                 * in parameter to JS::HandleValueArray in mozjs31 */
-                JS::RootedValue v_arg(context, js_argv[js_arg_pos]);
-                if (!gjs_value_to_arg(context, v_arg, &arg_info, in_value))
+                g_assert_cmpuint(js_arg_pos, <, args.length());
+                if (!gjs_value_to_arg(context, args[js_arg_pos], &arg_info,
+                                      in_value))
                     failed = true;
 
                 break;
@@ -1331,8 +1324,8 @@ function_call(JSContext *context,
     /* COMPAT: mozilla::Maybe gains a much more usable API in future versions */
     mozilla::Maybe<JS::MutableHandleValue> m_retval;
     m_retval.construct(&retval);
-    success = gjs_invoke_c_function(context, priv, object, js_argc,
-                                    js_argv.array(), m_retval, NULL);
+    success = gjs_invoke_c_function(context, priv, object, js_argv, m_retval,
+                                    NULL);
     if (success)
         js_argv.rval().set(retval);
 
@@ -1770,12 +1763,11 @@ gjs_define_function(JSContext       *context,
 
 
 bool
-gjs_invoke_c_function_uncached(JSContext             *context,
-                               GIFunctionInfo        *info,
-                               JS::HandleObject       obj,
-                               unsigned               argc,
-                               JS::Value             *argv,
-                               JS::MutableHandleValue rval)
+gjs_invoke_c_function_uncached(JSContext                  *context,
+                               GIFunctionInfo             *info,
+                               JS::HandleObject            obj,
+                               const JS::HandleValueArray& args,
+                               JS::MutableHandleValue      rval)
 {
   Function function;
   bool result;
@@ -1787,23 +1779,22 @@ gjs_invoke_c_function_uncached(JSContext             *context,
   /* COMPAT: mozilla::Maybe gains a much more usable API in future versions */
   mozilla::Maybe<JS::MutableHandleValue> m_rval;
   m_rval.construct(rval);
-  result = gjs_invoke_c_function(context, &function, obj, argc, argv, m_rval, NULL);
+  result = gjs_invoke_c_function(context, &function, obj, args, m_rval, NULL);
   uninit_cached_function_data (&function);
   return result;
 }
 
 bool
-gjs_invoke_constructor_from_c(JSContext       *context,
-                              JS::HandleObject constructor,
-                              JS::HandleObject obj,
-                              unsigned         argc,
-                              JS::Value       *argv,
-                              GArgument       *rvalue)
+gjs_invoke_constructor_from_c(JSContext                  *context,
+                              JS::HandleObject            constructor,
+                              JS::HandleObject            obj,
+                              const JS::HandleValueArray& args,
+                              GIArgument                 *rvalue)
 {
     Function *priv;
 
     priv = priv_from_js(context, constructor);
 
     mozilla::Maybe<JS::MutableHandleValue> m_jsrval;
-    return gjs_invoke_c_function(context, priv, obj, argc, argv, m_jsrval, rvalue);
+    return gjs_invoke_c_function(context, priv, obj, args, m_jsrval, rvalue);
 }
diff --git a/gi/function.h b/gi/function.h
index 6a2333e..234b551 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -67,19 +67,17 @@ JSObject *gjs_define_function(JSContext       *context,
                               GType            gtype,
                               GICallableInfo  *info);
 
-bool gjs_invoke_c_function_uncached(JSContext             *context,
-                                    GIFunctionInfo        *info,
-                                    JS::HandleObject       obj,
-                                    unsigned               argc,
-                                    JS::Value             *argv,
-                                    JS::MutableHandleValue rval);
+bool gjs_invoke_c_function_uncached(JSContext                  *context,
+                                    GIFunctionInfo             *info,
+                                    JS::HandleObject            obj,
+                                    const JS::HandleValueArray& args,
+                                    JS::MutableHandleValue      rval);
 
-bool      gjs_invoke_constructor_from_c(JSContext       *context,
-                                        JS::HandleObject constructor,
-                                        JS::HandleObject obj,
-                                        unsigned         argc,
-                                        JS::Value       *argv,
-                                        GArgument       *rvalue);
+bool gjs_invoke_constructor_from_c(JSContext                  *context,
+                                   JS::HandleObject            constructor,
+                                   JS::HandleObject            obj,
+                                   const JS::HandleValueArray& args,
+                                   GIArgument                 *rvalue);
 
 G_END_DECLS
 
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index 1fcca1d..c3bfdda 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -378,12 +378,11 @@ fundamental_instance_new_resolve(JSContext  *context,
 }
 
 static bool
-fundamental_invoke_constructor(FundamentalInstance *priv,
-                               JSContext           *context,
-                               JS::HandleObject     obj,
-                               unsigned             argc,
-                               JS::Value           *argv,
-                               GArgument           *rvalue)
+fundamental_invoke_constructor(FundamentalInstance        *priv,
+                               JSContext                  *context,
+                               JS::HandleObject            obj,
+                               const JS::HandleValueArray& args,
+                               GIArgument                 *rvalue)
 {
     JS::RootedId constructor_const(context,
         gjs_context_get_const_string(context, GJS_STRING_CONSTRUCTOR));
@@ -410,7 +409,7 @@ fundamental_invoke_constructor(FundamentalInstance *priv,
         return false;
     }
 
-    return gjs_invoke_constructor_from_c(context, constructor, obj, argc, argv, rvalue);
+    return gjs_invoke_constructor_from_c(context, constructor, obj, args, rvalue);
 }
 
 /* If we set JSCLASS_CONSTRUCT_PROTOTYPE flag, then this is called on
@@ -436,7 +435,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(fundamental_instance)
                         "fundamental constructor, obj %p priv %p",
                         object.get(), priv);
 
-    if (!fundamental_invoke_constructor(priv, context, object, argc, argv.array(), &ret_value))
+    if (!fundamental_invoke_constructor(priv, context, object, argv, &ret_value))
         return false;
 
     associate_js_instance_to_fundamental(context, object, ret_value.v_pointer, false);
diff --git a/gi/object.cpp b/gi/object.cpp
index a11fa35..843bca8 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -668,25 +668,24 @@ free_g_params(GParameter *params,
  * a hash)
  */
 static bool
-object_instance_props_to_g_parameters(JSContext               *context,
-                                      JSObject                *obj,
-                                      unsigned                 argc,
-                                      JS::Value               *argv,
-                                      GType                    gtype,
-                                      std::vector<GParameter>& gparams)
-{
-    if (argc == 0 || argv[0].isUndefined())
+object_instance_props_to_g_parameters(JSContext                  *context,
+                                      JSObject                   *obj,
+                                      const JS::HandleValueArray& args,
+                                      GType                       gtype,
+                                      std::vector<GParameter>&    gparams)
+{
+    if (args.length() == 0 || args[0].isUndefined())
         return true;
 
     JS::RootedObject props(context), iter(context);
     JS::RootedId prop_id(context);
 
-    if (!argv[0].isObject()) {
+    if (!args[0].isObject()) {
         gjs_throw(context, "argument should be a hash with props to set");
         goto free_array_and_fail;
     }
 
-    props = &argv[0].toObject();
+    props = &args[0].toObject();
 
     iter = JS_NewPropertyIterator(context, props);
     if (iter == NULL) {
@@ -1221,10 +1220,9 @@ disassociate_js_gobject (GObject   *gobj)
 }
 
 static bool
-object_instance_init (JSContext              *context,
-                      JS::MutableHandleObject object,
-                      unsigned                argc,
-                      JS::Value              *argv)
+object_instance_init (JSContext                  *context,
+                      JS::MutableHandleObject     object,
+                      const JS::HandleValueArray& args)
 {
     ObjectInstance *priv;
     GType gtype;
@@ -1237,7 +1235,7 @@ object_instance_init (JSContext              *context,
     gtype = priv->gtype;
     g_assert(gtype != G_TYPE_NONE);
 
-    if (!object_instance_props_to_g_parameters(context, object, argc, argv,
+    if (!object_instance_props_to_g_parameters(context, object, args,
                                                gtype, params)) {
         return false;
     }
@@ -1332,8 +1330,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(object_instance)
         return false;
 
     argv.rval().setUndefined();
-    ret = gjs_call_function_value(context, object, initer,
-                                  argc, argv.array(), argv.rval());
+    ret = gjs_call_function_value(context, object, initer, argv, argv.rval());
 
     if (argv.rval().isUndefined())
         argv.rval().setObject(*object);
@@ -1793,7 +1790,7 @@ init_func (JSContext *context,
     if (!do_base_typecheck(context, obj, true))
         return false;
 
-    ret = object_instance_init(context, &obj, argc, argv.array());
+    ret = object_instance_init(context, &obj, argv);
 
     if (ret)
         argv.rval().setObject(*obj);
diff --git a/gi/union.cpp b/gi/union.cpp
index 51ea723..4ac0e11 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -161,7 +161,7 @@ union_new(JSContext       *context,
             JS::RootedValue rval(context, JS::NullValue());
 
             gjs_invoke_c_function_uncached(context, func_info, obj,
-                                           0, NULL, &rval);
+                                           JS::HandleValueArray::empty(), &rval);
 
             g_base_info_unref((GIBaseInfo*) func_info);
 
diff --git a/gi/value.cpp b/gi/value.cpp
index 56ef073..d32a6ff 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -120,14 +120,12 @@ closure_marshal(GClosure        *closure,
     JSContext *context;
     JSRuntime *runtime;
     JSObject *obj;
-    int argc;
-    int i;
+    unsigned i;
     GSignalQuery signal_query = { 0, };
     GISignalInfo *signal_info;
     bool *skip;
     int *array_len_indices_for;
     GITypeInfo **type_info_for;
-    int argv_index;
 
     gjs_debug_marshal(GJS_DEBUG_GCLOSURE,
                       "Marshal closure %p",
@@ -165,14 +163,9 @@ closure_marshal(GClosure        *closure,
     }
 
     obj = gjs_closure_get_callable(closure);
-    JS_BeginRequest(context);
+    JSAutoRequest ar(context);
     JSAutoCompartment ac(context, obj);
 
-    argc = n_param_values;
-    JS::RootedValue rval(context);
-    JS::AutoValueVector argv(context);
-    argv.resize(argc);
-
     if (marshal_data) {
         /* we are used for a signal handler */
         guint signal_id;
@@ -184,31 +177,31 @@ closure_marshal(GClosure        *closure,
         if (!signal_query.signal_id) {
             gjs_debug(GJS_DEBUG_GCLOSURE,
                       "Signal handler being called on invalid signal");
-            goto cleanup;
+            return;
         }
 
         if (signal_query.n_params + 1 != n_param_values) {
             gjs_debug(GJS_DEBUG_GCLOSURE,
                       "Signal handler being called with wrong number of parameters");
-            goto cleanup;
+            return;
         }
     }
 
     /* Check if any parameters, such as array lengths, need to be eliminated
      * before we invoke the closure.
      */
-    skip = g_newa(bool, argc);
-    memset(skip, 0, sizeof (bool) * argc);
-    array_len_indices_for = g_newa(int, argc);
-    for(i = 0; i < argc; i++)
+    skip = g_newa(bool, n_param_values);
+    memset(skip, 0, sizeof (bool) * n_param_values);
+    array_len_indices_for = g_newa(int, n_param_values);
+    for(i = 0; i < n_param_values; i++)
         array_len_indices_for[i] = -1;
-    type_info_for = g_newa(GITypeInfo *, argc);
-    memset(type_info_for, 0, sizeof (gpointer) * argc);
+    type_info_for = g_newa(GITypeInfo *, n_param_values);
+    memset(type_info_for, 0, sizeof (gpointer) * n_param_values);
 
     signal_info = get_signal_info_if_available(&signal_query);
     if (signal_info) {
         /* Start at argument 1, skip the instance parameter */
-        for (i = 1; i < argc; ++i) {
+        for (i = 1; i < n_param_values; ++i) {
             GIArgInfo *arg_info;
             int array_len_pos;
 
@@ -227,8 +220,10 @@ closure_marshal(GClosure        *closure,
         g_base_info_unref((GIBaseInfo *)signal_info);
     }
 
-    argv_index = 0;
-    for (i = 0; i < argc; ++i) {
+    JS::AutoValueVector argv(context);
+    argv.reserve(n_param_values);  /* May end up being less */
+    JS::RootedValue argv_to_append(context);
+    for (i = 0; i < n_param_values; ++i) {
         const GValue *gval = &param_values[i];
         bool no_copy;
         int array_len_index;
@@ -247,14 +242,14 @@ closure_marshal(GClosure        *closure,
         if (array_len_index != -1) {
             const GValue *array_len_gval = &param_values[array_len_index];
             res = gjs_value_from_array_and_length_values(context,
-                                                         argv.handleAt(argv_index),
+                                                         &argv_to_append,
                                                          type_info_for[i],
                                                          gval, array_len_gval,
                                                          no_copy, &signal_query,
                                                          array_len_index);
         } else {
             res = gjs_value_from_g_value_internal(context,
-                                                  argv.handleAt(argv_index),
+                                                  &argv_to_append,
                                                   gval, no_copy, &signal_query,
                                                   i);
         }
@@ -264,36 +259,32 @@ closure_marshal(GClosure        *closure,
                       "Unable to convert arg %d in order to invoke closure",
                       i);
             gjs_log_exception(context);
-            goto cleanup;
+            return;
         }
 
-        argv_index++;
+        argv.append(argv_to_append);
     }
 
-    for (i = 1; i < argc; i++)
+    for (i = 1; i < n_param_values; i++)
         if (type_info_for[i])
             g_base_info_unref((GIBaseInfo *)type_info_for[i]);
 
-    gjs_closure_invoke(closure, argv_index,
-                       argv_index > 0 ? &argv[0] : NULL,
-                       &rval);
+    JS::RootedValue rval(context);
+    gjs_closure_invoke(closure, argv, &rval);
 
     if (return_value != NULL) {
         if (rval.isUndefined()) {
             /* something went wrong invoking, error should be set already */
-            goto cleanup;
+            return;
         }
 
         if (!gjs_value_to_g_value(context, rval, return_value)) {
             gjs_debug(GJS_DEBUG_GCLOSURE,
                       "Unable to convert return value when invoking closure");
             gjs_log_exception(context);
-            goto cleanup;
+            return;
         }
     }
-
- cleanup:
-    JS_EndRequest(context);
 }
 
 GClosure*
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 4ac1071..67ea0fe 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -162,10 +162,9 @@ gjs_typecheck_instance(JSContext       *context,
 }
 
 JSObject*
-gjs_construct_object_dynamic(JSContext       *context,
-                             JS::HandleObject proto,
-                             unsigned         argc,
-                             JS::Value       *argv)
+gjs_construct_object_dynamic(JSContext                  *context,
+                             JS::HandleObject            proto,
+                             const JS::HandleValueArray& args)
 {
     JSAutoRequest ar(context);
 
@@ -177,5 +176,5 @@ gjs_construct_object_dynamic(JSContext       *context,
                                            constructor_name, &constructor))
         return NULL;
 
-    return JS_New(context, constructor, argc, argv);
+    return JS_New(context, constructor, args);
 }
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 81f97b9..6baa1ac 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -633,19 +633,17 @@ gjs_log_exception(JSContext  *context)
 }
 
 bool
-gjs_call_function_value(JSContext             *context,
-                        JS::HandleObject       obj,
-                        JS::HandleValue        fval,
-                        unsigned               argc,
-                        JS::Value             *argv,
-                        JS::MutableHandleValue rval)
+gjs_call_function_value(JSContext                  *context,
+                        JS::HandleObject            obj,
+                        JS::HandleValue             fval,
+                        const JS::HandleValueArray& args,
+                        JS::MutableHandleValue      rval)
 {
     bool result;
 
     JS_BeginRequest(context);
 
-    result = JS_CallFunctionValue(context, obj, fval,
-                                  argc, argv, rval.address());
+    result = JS_CallFunctionValue(context, obj, fval, args, rval);
 
     if (result)
         gjs_schedule_gc_if_needed(context);
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 95be91d..d5abfdd 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -344,10 +344,9 @@ bool gjs_typecheck_instance(JSContext       *context,
                             JSClass         *static_clasp,
                             bool             throw_error);
 
-JSObject *gjs_construct_object_dynamic(JSContext       *context,
-                                       JS::HandleObject proto,
-                                       unsigned         argc,
-                                       JS::Value       *argv);
+JSObject *gjs_construct_object_dynamic(JSContext                  *context,
+                                       JS::HandleObject            proto,
+                                       const JS::HandleValueArray& args);
 
 JSObject*   gjs_build_string_array           (JSContext       *context,
                                               gssize           array_length,
@@ -381,12 +380,11 @@ bool gjs_log_exception_full(JSContext       *context,
 char *gjs_value_debug_string(JSContext      *context,
                              JS::HandleValue value);
 
-bool gjs_call_function_value(JSContext             *context,
-                             JS::HandleObject       obj,
-                             JS::HandleValue        fval,
-                             unsigned               argc,
-                             JS::Value             *argv,
-                             JS::MutableHandleValue rval);
+bool gjs_call_function_value(JSContext                  *context,
+                             JS::HandleObject            obj,
+                             JS::HandleValue             fval,
+                             const JS::HandleValueArray& args,
+                             JS::MutableHandleValue      rval);
 
 void        gjs_error_reporter               (JSContext       *context,
                                               const char      *message,


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