[gjs: 5/11] js: Remove unnecessary aborts



commit cedbebb5e87421ec34271eeac59503db76993b63
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Oct 15 20:14:59 2018 -0700

    js: Remove unnecessary aborts
    
    There's no reason to abort in cases where a JSAPI function will either have
    set an exception on failure, or thrown an uncatchable exception by calling
    JS_ReportOutOfMemory(). In a few cases we throw a more detailed exception
    matching the message for the previously existing g_error(), but the
    overwritten exception will still be logged.

 gi/enumeration.cpp |  6 +++---
 gi/interface.cpp   |  2 +-
 gi/ns.cpp          |  2 +-
 gi/repo.cpp        |  4 ++--
 gi/union.cpp       |  2 +-
 gjs/importer.cpp   | 10 +++++-----
 gjs/jsapi-class.h  |  2 +-
 7 files changed, 14 insertions(+), 14 deletions(-)
---
diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp
index 6ed0e02a..296e3ec1 100644
--- a/gi/enumeration.cpp
+++ b/gi/enumeration.cpp
@@ -167,9 +167,9 @@ gjs_define_enumeration(JSContext       *context,
 
     JS::RootedObject enum_obj(context, JS_NewPlainObject(context));
     if (!enum_obj) {
-        g_error("Could not create enumeration %s.%s",
-                       g_base_info_get_namespace( (GIBaseInfo*) info),
-                enum_name);
+        gjs_throw(context, "Could not create enumeration %s.%s",
+                  g_base_info_get_namespace(info), enum_name);
+        return false;
     }
 
     if (!gjs_define_enum_values(context, enum_obj, info) ||
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 3f0372e5..c4000aa3 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -238,7 +238,7 @@ gjs_define_interface_class(JSContext              *context,
                                 gjs_interface_static_funcs,
                                 &prototype,
                                 constructor)) {
-        g_error("Can't init class %s", constructor_name);
+        return false;
     }
 
     GJS_INC_COUNTER(interface);
diff --git a/gi/ns.cpp b/gi/ns.cpp
index dc309e5f..505b00cd 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -188,7 +188,7 @@ ns_new(JSContext    *context,
     JS::RootedObject ns(context,
         JS_NewObjectWithGivenProto(context, &gjs_ns_class, proto));
     if (!ns)
-        g_error("No memory to create ns object");
+        return nullptr;
 
     priv = g_slice_new0(Ns);
 
diff --git a/gi/repo.cpp b/gi/repo.cpp
index adefb8bf..f5f65dec 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -132,7 +132,7 @@ static bool resolve_namespace_object(JSContext* context,
        the override module looks for namespaces that import this */
     if (!JS_DefinePropertyById(context, repo_obj, ns_id, gi_namespace,
                                GJS_MODULE_PROP_FLAGS))
-        g_error("no memory to define ns property");
+        return false;
 
     JS::RootedValue override(context);
     if (!lookup_override_function(context, ns_id, &override))
@@ -257,7 +257,7 @@ repo_new(JSContext *context)
     JS::RootedObject repo(context,
         JS_NewObjectWithGivenProto(context, &gjs_repo_class, proto));
     if (repo == nullptr)
-        g_error("No memory to create repo object");
+        return nullptr;
 
     priv = g_slice_new0(Repo);
 
diff --git a/gi/union.cpp b/gi/union.cpp
index 9852080b..23d57aad 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -345,7 +345,7 @@ gjs_define_union_class(JSContext       *context,
                                 NULL,
                                 &prototype,
                                 &constructor)) {
-        g_error("Can't init class %s", constructor_name);
+        return false;
     }
 
     GJS_INC_COUNTER(boxed);
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index d0b2938a..f056b849 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -831,12 +831,12 @@ importer_new(JSContext *context,
 
     JS::RootedObject proto(context);
     if (!gjs_importer_define_proto(context, nullptr, &proto))
-        g_error("Error creating importer prototype");
+        return nullptr;
 
     JS::RootedObject importer(context,
         JS_NewObjectWithGivenProto(context, &gjs_importer_class, proto));
     if (!importer)
-        g_error("No memory to create importer");
+        return nullptr;
 
     priv = g_slice_new0(Importer);
     priv->is_root = is_root;
@@ -942,10 +942,10 @@ gjs_create_importer(JSContext          *context,
                                  "searchPath", -1, search_path.as<const char *>(),
                                  /* settable (no READONLY) but not deleteable (PERMANENT) */
                                  JSPROP_PERMANENT | JSPROP_RESOLVING))
-        g_error("no memory to define importer search path prop");
+        return nullptr;
 
     if (!define_meta_properties(context, importer, NULL, importer_name, in_object))
-        g_error("failed to define meta properties on importer");
+        return nullptr;
 
     return importer;
 }
@@ -965,7 +965,7 @@ gjs_define_importer(JSContext          *context,
 
     if (!JS_DefineProperty(context, in_object, importer_name, importer,
                            GJS_MODULE_PROP_FLAGS))
-        g_error("no memory to define importer property");
+        return nullptr;
 
     gjs_debug(GJS_DEBUG_IMPORTER,
               "Defined importer '%s' %p in %p", importer_name, importer.get(),
diff --git a/gjs/jsapi-class.h b/gjs/jsapi-class.h
index b952fe1d..9464191c 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -243,7 +243,7 @@ GJS_DEFINE_PROTO_FUNCS_WITH_PARENT(cname, no_parent)
                                gjs_##cname##_proto_funcs, nullptr,             \
                                gjs_##cname##_static_funcs));                   \
         if (!proto)                                                            \
-            g_error("Can't init class %s", gjs_##cname##_class.name);          \
+            return false;                                                      \
         gjs_set_global_slot(cx, GJS_GLOBAL_SLOT_PROTOTYPE_##cname,             \
                             JS::ObjectValue(*proto));                          \
                                                                                \


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