[gjs/mozjs78: 50/50] wrapperutils: Be stricter about having a prototype with correct JSClass




commit e7b387d2c4962c31afa5529caf254951840eec09
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 1 15:21:17 2020 -0700

    wrapperutils: Be stricter about having a prototype with correct JSClass
    
    I'm not sure what changed here or why this didn't already fail, but it
    seems that we need to check that the prototype is of the right JSClass,
    before calling JS_GetInstancePrivate() on it — which will fail if it is
    of the wrong JSClass.
    
    See: GNOME/gjs#329

 gi/wrapperutils.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 912ab36e..b5a47441 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -459,7 +459,8 @@ class GIWrapperBase {
      */
     static void finalize(JSFreeOp* fop, JSObject* obj) {
         Base* priv = Base::for_js_nocheck(obj);
-        g_assert(priv);
+        if (!priv)
+            return;  // construction didn't finish
 
         // Call only GIWrapperBase's original method here, not any overrides;
         // e.g., we don't want to deal with a read barrier in ObjectInstance.
@@ -528,6 +529,14 @@ class GIWrapperBase {
         if (!obj)
             return false;
 
+        JS::RootedObject proto(cx);
+        if (!JS_GetPrototype(cx, obj, &proto))
+            return false;
+        if (JS_GetClass(proto) != &Base::klass) {
+            gjs_throw(cx, "Tried to construct an object without a GType");
+            return false;
+        }
+
         args.rval().setUndefined();
 
         Instance* priv = Instance::new_for_js_object(cx, obj);


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