[gjs/wip/ptomato/mozjs52: 12/35] js: New JS_IsArrayObject() API
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs52: 12/35] js: New JS_IsArrayObject() API
- Date: Sun, 11 Jun 2017 03:13:12 +0000 (UTC)
commit a01626c4503d147acdb2394939f584a78d5f3f03
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 fc9596f..6a9ac49 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2596,8 +2596,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;
}
@@ -2605,7 +2608,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 2090a33..a14f65d 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -637,6 +637,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)
@@ -650,7 +651,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 20e9151..5ef6fee 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 1a3eca7..89e19d2 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -502,16 +502,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;
}
@@ -684,6 +685,7 @@ importer_enumerate(JSContext *context,
Importer *priv;
guint32 search_path_len;
guint32 i;
+ bool is_array;
priv = priv_from_js(context, object);
@@ -697,7 +699,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 f74d95f..5f34d21 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]