[gjs: 11/16] importer: Make load_module_elements() fallible
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 11/16] importer: Make load_module_elements() fallible
- Date: Sat, 3 Nov 2018 02:42:09 +0000 (UTC)
commit e3b2143812d7c751ccc32bbb4e93f2d81ee6fdb0
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Oct 28 16:56:52 2018 -0400
importer: Make load_module_elements() fallible
Errors were being ignored in this function, so instead they should be
propagated to the caller.
gjs/importer.cpp | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 73aa9b6f..3deb2a99 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -361,25 +361,26 @@ load_module_init(JSContext *context,
return module_obj;
}
-static void
-load_module_elements(JSContext *cx,
- JS::HandleObject in_object,
- JS::AutoIdVector& prop_ids,
- const char *init_path)
-{
+GJS_JSAPI_RETURN_CONVENTION
+static bool load_module_elements(JSContext* cx, JS::HandleObject in_object,
+ JS::AutoIdVector& prop_ids,
+ const char* init_path) {
size_t ix, length;
JS::RootedObject module_obj(cx, load_module_init(cx, in_object, init_path));
-
if (!module_obj)
- return;
+ return false;
JS::Rooted<JS::IdVector> ids(cx, cx);
if (!JS_Enumerate(cx, module_obj, &ids))
- return;
+ return false;
for (ix = 0, length = ids.length(); ix < length; ix++)
- if (!prop_ids.append(ids[ix]))
- g_error("Unable to append to vector");
+ if (!prop_ids.append(ids[ix])) {
+ JS_ReportOutOfMemory(cx);
+ return false;
+ }
+
+ return true;
}
/* If error, returns false. If not found, returns true but does not touch
@@ -664,7 +665,8 @@ static bool importer_new_enumerate(JSContext* context, JS::HandleObject object,
init_path =
g_build_filename(dirname.get(), MODULE_INIT_FILENAME, nullptr);
- load_module_elements(context, object, properties, init_path);
+ if (!load_module_elements(context, object, properties, init_path))
+ return false;
g_free(init_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]