diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2017-03-19 05:14:40 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2017-05-05 23:26:30 -0700 |
commit | 9d7cf0d4a22191e8c245204ac5f096cf364aa6c3 (patch) | |
tree | 313ffa32613a13d87fd0de6a40f614d4874d7811 | |
parent | 46f42229b968f7ee9b328e5e2fbe83be513f3c39 (diff) | |
download | gjs-9d7cf0d4a22191e8c245204ac5f096cf364aa6c3.tar.gz |
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.)
-rw-r--r-- | gi/object.cpp | 9 | ||||
-rw-r--r-- | gjs/byteArray.cpp | 5 | ||||
-rw-r--r-- | gjs/coverage.cpp | 5 | ||||
-rw-r--r-- | gjs/importer.cpp | 12 | ||||
-rw-r--r-- | modules/cairo-context.cpp | 5 |
5 files changed, 27 insertions, 9 deletions
diff --git a/gi/object.cpp b/gi/object.cpp index 82663927..604f7447 100644 --- a/gi/object.cpp +++ b/gi/object.cpp @@ -2628,8 +2628,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; } @@ -2637,7 +2640,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 b0130edb..200ae99a 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 831853d0..d502cee5 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 f1c6af8e..a6c29bc4 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 f74d95ff..5f34d21f 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; } |