[gjs/mozjs102: 48/59] js: Use length overload of JS::NewArrayObject()




commit 43149ba7f1d120d61fcc1043d0b635163d1667bf
Author: Evan Welsh <contact evanwelsh com>
Date:   Fri Jul 22 10:40:34 2022 -0700

    js: Use length overload of JS::NewArrayObject()
    
    It's not necessary to use JS::HandleValueArray::empty() here, since we
    can just create an empty array of the proper length using the overload
    that lets you specify an integer length.

 modules/cairo-context.cpp | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
---
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 463e06215..c2396a96d 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -86,9 +86,7 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
         return false;                                                       \
     cfunc(cr, &arg1, &arg2);                                                \
     if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {                         \
-        JS::RootedObject array(                                             \
-            context,                                                        \
-            JS::NewArrayObject(context, JS::HandleValueArray::empty()));    \
+        JS::RootedObject array(context, JS::NewArrayObject(context, 2));    \
         if (!array)                                                         \
             return false;                                                   \
         JS::RootedValue r(context, JS::NumberValue(arg1));                  \
@@ -107,9 +105,7 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
     _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())); \
+        JS::RootedObject array(context, JS::NewArrayObject(context, 2)); \
         if (!array)                                                      \
             return false;                                                \
         JS::RootedValue r(context, JS::NumberValue(arg1));               \
@@ -128,9 +124,7 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
     _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(method)                             \
     cfunc(cr, &arg1, &arg2, &arg3, &arg4);                               \
     {                                                                    \
-        JS::RootedObject array(                                          \
-            context,                                                     \
-            JS::NewArrayObject(context, JS::HandleValueArray::empty())); \
+        JS::RootedObject array(context, JS::NewArrayObject(context, 4)); \
         if (!array)                                                      \
             return false;                                                \
         JS::RootedValue r(context, JS::NumberValue(arg1));               \


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