[gjs: 7/7] class: Deprecate gjs_new_object_for_constructor()



commit 2a67a879b2b7a317064f3bfe204ef63609be5fc1
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Sep 18 10:40:30 2016 -0700

    class: Deprecate gjs_new_object_for_constructor()
    
    According to the comments, in mozjs 1.8.5, JS_NewObjectForConstructor()
    did not work with our dynamic classes. Therefore a
    gjs_new_object_for_constructor() shim was created that copied the
    JS_NewObjectForConstructor() code from mozjs 1.9. Now that we are on
    mozjs 24, we can get rid of this shim.
    
    Unfortunately we can't remove the function altogether because it's public
    API in libgjs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742249

 gjs/jsapi-dynamic-class.cpp |   22 +++++-----------------
 gjs/jsapi-util.h            |    6 ++++--
 2 files changed, 9 insertions(+), 19 deletions(-)
---
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 44e3fa9..e46d1b0 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -36,29 +36,17 @@
 #include <math.h>
 
 /*
- * JS 1.8.5 has JS_NewObjectForConstructor, but it attempts
- * to retrieve the JSClass from private fields in the constructor function,
- * which fails for our "dynamic classes".
- * This is the version included in SpiderMonkey 1.9 and later, to be
- * used until we rebase on a newer libmozjs.
+ * This shim was because of a bug in JS_NewObjectForConstructor in JS 1.8.5. It
+ * attempted to retrieve the JSClass from private fields in the constructor
+ * function, which failed for our "dynamic classes".
+ * This function is deprecated.
  */
 JSObject *
 gjs_new_object_for_constructor(JSContext *context,
                                JSClass   *clasp,
                                JS::Value *vp)
 {
-    JS::Value callee;
-    JSObject *parent;
-    JS::Value prototype;
-
-    callee = JS_CALLEE(context, vp);
-    parent = JS_GetParent(&callee.toObject());
-
-    if (!gjs_object_get_property_const(context, &callee.toObject(), GJS_STRING_PROTOTYPE, &prototype))
-        return NULL;
-
-    return JS_NewObjectWithGivenProto(context, clasp,
-                                      &prototype.toObject(), parent);
+    return JS_NewObjectForConstructor(context, clasp, vp);
 }
 
 JSBool
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index ff6a6e9..b8972b1 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -231,7 +231,7 @@ gjs_##name##_constructor(JSContext  *context,           \
             gjs_throw_constructor_error(context);                       \
             return JS_FALSE;                                            \
         }                                                               \
-        object = gjs_new_object_for_constructor(context, &gjs_##name##_class, vp); \
+        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
         if (object == NULL)                                             \
             return JS_FALSE;                                            \
     }
@@ -276,7 +276,9 @@ gboolean    gjs_object_require_property      (JSContext       *context,
 
 JSObject   *gjs_new_object_for_constructor   (JSContext       *context,
                                               JSClass         *clasp,
-                                              JS::Value       *vp);
+                                              JS::Value       *vp)
+G_GNUC_DEPRECATED_FOR(JS_NewObjectForConstructor);
+
 JSBool      gjs_init_class_dynamic           (JSContext       *context,
                                               JSObject        *in_object,
                                               JSObject        *parent_proto,


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