[gjs/wip/ptomato/mozjs45: 15/25] js: New JS_IsArrayObject() API
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs45: 15/25] js: New JS_IsArrayObject() API
- Date: Sat, 6 May 2017 06:27:35 +0000 (UTC)
commit 9d7cf0d4a22191e8c245204ac5f096cf364aa6c3
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 8266392..604f744 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 b0130ed..200ae99 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 831853d..d502cee 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 f1c6af8..a6c29bc 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 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]