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




commit daef852371fbfe32684a2e68e30ee1e493cb8553
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 5eaf955e..f5af889a 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -460,7 +460,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.
@@ -529,6 +530,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]