[gjs/wip/ptomato/mozjs45prep: 4/23] object: Don't crash on error in gjs_object_from_g_object()



commit 1e3a2d1b2422e121faa315448c213a4311ecdd5a
Author: Philip Chimento <philip endlessm com>
Date:   Tue Mar 14 15:00:55 2017 -0700

    object: Don't crash on error in gjs_object_from_g_object()
    
    Fix one spot where we ignore a JS exception from
    gjs_lookup_object_prototype() which causes a crash later. Also fix
    another spot where we would crash if JS_NewObjectWithGivenProto() fails,
    though that is unlikely except on OOM.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779918

 gi/object.cpp |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 63731df..43cb425 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2197,14 +2197,16 @@ gjs_object_from_g_object(JSContext    *context,
 
         JS::RootedObject proto(context,
             gjs_lookup_object_prototype(context, gtype));
+        if (!proto)
+            return nullptr;
+
         JS::RootedObject global(context, gjs_get_import_global(context));
 
         JS::RootedObject obj(context,
             JS_NewObjectWithGivenProto(context, JS_GetClass(proto), proto,
                                        global));
-
         if (obj == NULL)
-            goto out;
+            return nullptr;
 
         priv = init_object_private(context, obj);
 
@@ -2217,7 +2219,6 @@ gjs_object_from_g_object(JSContext    *context,
         g_assert(priv->keep_alive == obj);
     }
 
- out:
     return priv->keep_alive;
 }
 


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