[gjs] Backport of patch required for vectors MOZ_MUST_USE returns



commit e6cc09ddb4ef8a18bc56afbad9525ddde30ad735
Author: luke nukem jones gmail com <luke nukem jones gmail com>
Date:   Sun Jul 30 14:10:00 2017 -0700

    Backport of patch required for vectors MOZ_MUST_USE returns
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785424

 gi/arg.cpp         |   20 ++++++++++++++------
 gi/function.cpp    |   16 ++++++++++++----
 gi/repo.cpp        |    6 ++----
 gi/value.cpp       |    7 +++++--
 gjs/importer.cpp   |    9 ++++++---
 gjs/jsapi-util.cpp |   10 +++++++---
 gjs/module.cpp     |    4 +++-
 7 files changed, 49 insertions(+), 23 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index efd229b..5cb4a99 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -589,7 +589,9 @@ gjs_array_from_strv(JSContext             *context,
      * the case.
      */
     for (i = 0; strv != NULL && strv[i] != NULL; i++) {
-        elems.growBy(1);
+        if (!elems.growBy(1))
+            g_error("Unable to grow vector");
+
         if (!gjs_string_from_utf8(context, strv[i], -1, elems[i]))
             return false;
     }
@@ -974,7 +976,9 @@ gjs_array_from_flat_gvalue_array(JSContext             *context,
     GValue *values = (GValue *)array;
     unsigned int i;
     JS::AutoValueVector elems(context);
-    elems.resize(length);
+    if (!elems.resize(length))
+        g_error("Unable to resize vector");
+
     bool result = true;
 
     for (i = 0; i < length; i ++) {
@@ -2170,7 +2174,8 @@ gjs_array_from_g_list (JSContext             *context,
     if (list_tag == GI_TYPE_TAG_GLIST) {
         for ( ; list != NULL; list = list->next) {
             arg.v_pointer = list->data;
-            elems.growBy(1);
+            if (!elems.growBy(1))
+                g_error("Unable to grow vector");
 
             if (!gjs_value_from_g_argument(context, elems[i], param_info, &arg,
                                            true))
@@ -2180,7 +2185,8 @@ gjs_array_from_g_list (JSContext             *context,
     } else {
         for ( ; slist != NULL; slist = slist->next) {
             arg.v_pointer = slist->data;
-            elems.growBy(1);
+            if (!elems.growBy(1))
+                g_error("Unable to grow vector");
 
             if (!gjs_value_from_g_argument(context, elems[i], param_info, &arg,
                                            true))
@@ -2234,7 +2240,8 @@ gjs_array_from_carray_internal (JSContext             *context,
         return gjs_string_from_ucs4(context, (gunichar *) array, length, value_p);
 
     JS::AutoValueVector elems(context);
-    elems.resize(length);
+    if (!elems.resize(length))
+        g_error("Unable to resize vector");
 
 #define ITERATE(type) \
     for (i = 0; i < length; i++) { \
@@ -2454,7 +2461,8 @@ gjs_array_from_zero_terminated_c_array (JSContext             *context,
         g##type *array = (g##type *) c_array; \
         for (i = 0; array[i]; i++) { \
             arg.v_##type = array[i]; \
-            elems.growBy(1);                                            \
+            if (!elems.growBy(1))                                       \
+                g_error("Unable to grow vector");                       \
             if (!gjs_value_from_g_argument(context, elems[i],           \
                                            param_info, &arg, true))     \
                 return false; \
diff --git a/gi/function.cpp b/gi/function.cpp
index 9cb0866..21b104d 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -216,7 +216,10 @@ gjs_callback_closure(ffi_cif *cif,
 
     n_outargs = 0;
     JS::AutoValueVector jsargs(context);
-    jsargs.reserve(n_args);
+
+    if (!jsargs.reserve(n_args))
+        g_error("Unable to reserve space for vector");
+
     JS::RootedValue rval(context);
     JS::RootedValue rooted_function(context, trampoline->js_function);
     JS::RootedObject this_object(context);
@@ -259,14 +262,18 @@ gjs_callback_closure(ffi_cif *cif,
                                                (GArgument *) args[array_length_pos], true))
                     goto out;
 
-                jsargs.growBy(1);
+                if (!jsargs.growBy(1))
+                    g_error("Unable to grow vector");
+
                 if (!gjs_value_from_explicit_array(context, jsargs[n_jsargs++],
                                                    &type_info, (GArgument*) args[i], length.toInt32()))
                     goto out;
                 break;
             }
             case PARAM_NORMAL:
-                jsargs.growBy(1);
+                if (!jsargs.growBy(1))
+                    g_error("Unable to grow vector");
+
                 if (!gjs_value_from_g_argument(context, jsargs[n_jsargs++],
                                                &type_info,
                                                (GArgument *) args[i], false))
@@ -1044,7 +1051,8 @@ gjs_invoke_c_function(JSContext                             *context,
     /* Only process return values if the function didn't throw */
     if (function->js_out_argc > 0 && !did_throw_gerror) {
         for (size_t i = 0; i < function->js_out_argc; i++)
-            return_values.append(JS::UndefinedValue());
+            if (!return_values.append(JS::UndefinedValue()))
+                g_error("Unable to append to vector");
 
         if (return_tag != GI_TYPE_TAG_VOID) {
             GITransfer transfer = g_callable_info_get_caller_owns((GICallableInfo*) function->info);
diff --git a/gi/repo.cpp b/gi/repo.cpp
index d893ce2..4cc1e6c 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -250,10 +250,8 @@ repo_new(JSContext *context)
 
     JS::RootedObject repo(context,
         JS_NewObjectWithGivenProto(context, &gjs_repo_class, proto));
-    if (repo == NULL) {
-        gjs_throw(context, "No memory to create repo object");
-        return NULL;
-    }
+    if (repo == nullptr)
+        g_error("No memory to create repo object");
 
     priv = g_slice_new0(Repo);
 
diff --git a/gi/value.cpp b/gi/value.cpp
index 6585375..c718828 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -221,7 +221,9 @@ closure_marshal(GClosure        *closure,
     }
 
     JS::AutoValueVector argv(context);
-    argv.reserve(n_param_values);  /* May end up being less */
+    /* May end up being less */
+    if (!argv.reserve(n_param_values))
+        g_error("Unable to reserve space");
     JS::RootedValue argv_to_append(context);
     for (i = 0; i < n_param_values; ++i) {
         const GValue *gval = &param_values[i];
@@ -262,7 +264,8 @@ closure_marshal(GClosure        *closure,
             return;
         }
 
-        argv.append(argv_to_append);
+        if (!argv.append(argv_to_append))
+            g_error("Unable to append to vector");
     }
 
     for (i = 1; i < n_param_values; i++)
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 458e23a..6fd886f 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -377,7 +377,8 @@ load_module_elements(JSContext        *cx,
         return;
 
     for (ix = 0, length = ids.length(); ix < length; ix++)
-        prop_ids.append(ids[ix]);
+        if (!prop_ids.append(ids[ix]))
+            g_error("Unable to append to vector");
 }
 
 /* If error, returns false. If not found, returns true but does not touch
@@ -725,12 +726,14 @@ importer_enumerate(JSContext        *context,
                 continue;
 
             if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY) {
-                properties.append(gjs_intern_string_to_id(context, filename));
+                if (!properties.append(gjs_intern_string_to_id(context, filename)))
+                    g_error("Unable to append to vector");
             } else if (g_str_has_suffix(filename, "." G_MODULE_SUFFIX) ||
                        g_str_has_suffix(filename, ".js")) {
                 GjsAutoChar filename_noext =
                     g_strndup(filename, strlen(filename) - 3);
-                properties.append(gjs_intern_string_to_id(context, filename_noext));
+                if (!properties.append(gjs_intern_string_to_id(context, filename_noext)))
+                    g_error("Unable to append to vector");
             }
         }
     }
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 8627cb7..57e4cb4 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -287,12 +287,14 @@ gjs_build_string_array(JSContext   *context,
         array_length = g_strv_length(array_values);
 
     JS::AutoValueVector elems(context);
-    elems.reserve(array_length);
+    if (!elems.reserve(array_length))
+        g_error("Unable to reserve memory for vector");
 
     for (i = 0; i < array_length; ++i) {
         JS::RootedValue element(context,
             JS::StringValue(JS_NewStringCopyZ(context, array_values[i])));
-        elems.append(element);
+        if (!elems.append(element))
+            g_error("Unable to append to vector");
     }
 
     return JS_NewArrayObject(context, elems);
@@ -839,7 +841,9 @@ gjs_eval_with_scope(JSContext             *context,
         return false;
 
     JS::AutoObjectVector scope_chain(context);
-    scope_chain.append(eval_obj);
+    if (!scope_chain.append(eval_obj))
+        g_error("Unable to append to vector");
+
     if (!JS_ExecuteScript(context, scope_chain, compiled_script, retval))
         return false;
 
diff --git a/gjs/module.cpp b/gjs/module.cpp
index 6b03c96..b476848 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -96,7 +96,9 @@ class GjsModule {
             return false;
 
         JS::AutoObjectVector scope_chain(cx);
-        scope_chain.append(module);
+        if (!scope_chain.append(module))
+            g_error("Unable to append to vector");
+
         JS::RootedValue ignored_retval(cx);
         if (!JS_ExecuteScript(cx, scope_chain, compiled_script, &ignored_retval))
             return false;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]