[gjs/wip/ptomato/mozjs31prep] util: Root gjs_build_string_array()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31prep] util: Root gjs_build_string_array()
- Date: Tue, 4 Oct 2016 04:47:53 +0000 (UTC)
commit 5cce5409d24dc5404a1ca6b6323a65bb93ed4cbf
Author: Philip Chimento <philip chimento gmail com>
Date: Mon Oct 3 21:38:34 2016 -0700
util: Root gjs_build_string_array()
This was an easy target and also gets rid of more alignment problems with
GArray. JS_NewArrayObject will take a JS::HandleValueArray parameter in
mozjs31.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
gjs/jsapi-util.cpp | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index f748d86..3e7b169 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -216,25 +216,21 @@ gjs_build_string_array(JSContext *context,
gssize array_length,
char **array_values)
{
- GArray *elems;
- JSObject *array;
int i;
if (array_length == -1)
array_length = g_strv_length(array_values);
- elems = g_array_sized_new(false, false, sizeof(JS::Value), array_length);
+ JS::AutoValueVector elems(context);
+ elems.reserve(array_length);
for (i = 0; i < array_length; ++i) {
- JS::Value element;
- element = JS::StringValue(JS_NewStringCopyZ(context, array_values[i]));
- g_array_append_val(elems, element);
+ JS::RootedValue element(context,
+ JS::StringValue(JS_NewStringCopyZ(context, array_values[i])));
+ elems.append(element);
}
- array = JS_NewArrayObject(context, elems->len, (JS::Value *) elems->data);
- g_array_free(elems, true);
-
- return array;
+ return JS_NewArrayObject(context, elems.length(), &elems[0]);
}
JSObject*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]