[gjs/wip/ptomato/mozjs45prep: 25/36] js: New JS_IsArrayObject() API



commit bc1458e274fb8fd4d09f9759a844ac5bb5375cf6
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Mar 19 05:14:40 2017 +0000

    js: New JS_IsArrayObject() API
    
    Now JS_IsArrayObject() distinguishes between errors (returning false) and
    the object not being an array (returning true but setting the passed-in
    bool ref to false.)

 gi/object.cpp             |    9 +++++++--
 gjs/byteArray.cpp         |    5 ++++-
 gjs/coverage.cpp          |    5 ++++-
 gjs/importer.cpp          |   12 ++++++++----
 modules/cairo-context.cpp |    5 ++++-
 5 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 63fd4a7..a8c4621 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2625,8 +2625,11 @@ validate_interfaces_and_properties_args(JSContext       *cx,
                                         uint32_t        *n_properties)
 {
     guint32 n_int, n_prop;
+    bool is_array;
 
-    if (!JS_IsArrayObject(cx, interfaces)) {
+    if (!JS_IsArrayObject(cx, interfaces, &is_array))
+        return false;
+    if (!is_array) {
         gjs_throw(cx, "Invalid parameter interfaces (expected Array)");
         return false;
     }
@@ -2634,7 +2637,9 @@ validate_interfaces_and_properties_args(JSContext       *cx,
     if (!JS_GetArrayLength(cx, interfaces, &n_int))
         return false;
 
-    if (!JS_IsArrayObject(cx, properties)) {
+    if (!JS_IsArrayObject(cx, properties, &is_array))
+        return false;
+    if (!is_array) {
         gjs_throw(cx, "Invalid parameter properties (expected Array)");
         return false;
     }
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 5513e84..6b4230d 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -650,6 +650,7 @@ from_array_func(JSContext *context,
     ByteArrayInstance *priv;
     guint32 len;
     guint32 i;
+    bool is_array;
     JS::RootedObject obj(context, byte_array_new(context));
 
     if (obj == NULL)
@@ -663,7 +664,9 @@ from_array_func(JSContext *context,
     priv->array = gjs_g_byte_array_new(0);
 
     JS::RootedObject array_obj(context, &argv[0].toObject());
-    if (!JS_IsArrayObject(context, array_obj)) {
+    if (!JS_IsArrayObject(context, array_obj, &is_array))
+        return false;
+    if (!is_array) {
         gjs_throw(context,
                   "byteArray.fromArray() called with non-array as first arg");
         return false;
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index c75cb8c..794487b 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -407,7 +407,10 @@ 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);
 
-    if (!JS_IsArrayObject(context, value)) {
+    bool is_array;
+    if (!JS_IsArrayObject(context, value, &is_array))
+        return false;
+    if (!is_array) {
         g_critical("Returned object from is not an array");
         return false;
     }
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 9f8d73d..168ca3d 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -506,16 +506,17 @@ do_import(JSContext       *context,
     JS::RootedObject search_path(context);
     guint32 search_path_len;
     guint32 i;
-    bool result;
+    bool result, exists, is_array;
     GPtrArray *directories;
     GFile *gfile;
-    bool exists;
 
     if (!gjs_object_require_property(context, obj, "importer",
                                      GJS_STRING_SEARCH_PATH, &search_path))
         return false;
 
-    if (!JS_IsArrayObject(context, search_path)) {
+    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;
     }
@@ -690,6 +691,7 @@ importer_enumerate(JSContext        *context,
     Importer *priv;
     guint32 search_path_len;
     guint32 i;
+    bool is_array;
 
     priv = priv_from_js(context, object);
 
@@ -703,7 +705,9 @@ importer_enumerate(JSContext        *context,
                                      &search_path))
         return false;
 
-    if (!JS_IsArrayObject(context, search_path)) {
+    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;
     }
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 9a101fa..692b4a5 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -540,13 +540,16 @@ setDash_func(JSContext *context,
     JS::RootedObject dashes(context);
     double offset;
     guint len;
+    bool is_array;
 
     if (!gjs_parse_call_args(context, "setDash", argv, "of",
                              "dashes", &dashes,
                              "offset", &offset))
         return false;
 
-    if (!JS_IsArrayObject(context, dashes)) {
+    if (!JS_IsArrayObject(context, dashes, &is_array))
+        return false;
+    if (!is_array) {
         gjs_throw(context, "dashes must be an array");
         return false;
     }


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