[gjs/wip/ptomato/mozjs45prep: 14/23] js: new IsArrayObject API



commit 18a52f2842ff87122161bf99ef8a12c5c2094d4c
Author: Philip Chimento <philip endlessm com>
Date:   Sun Mar 19 05:14:40 2017 +0000

    js: new IsArrayObject API

 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 4751329..11c38da 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2782,8 +2782,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;
     }
@@ -2791,7 +2794,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 b51d42b..95fa10d 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -665,6 +665,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)
@@ -678,7 +679,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 e04ac63..61cd40a 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -503,16 +503,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;
     }
@@ -687,6 +688,7 @@ importer_enumerate(JSContext        *context,
     Importer *priv;
     guint32 search_path_len;
     guint32 i;
+    bool is_array;
 
     priv = priv_from_js(context, object);
 
@@ -700,7 +702,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 5f1164b..35a1bfb 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -535,13 +535,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]