[gjs/wip/ptomato/mozjs31prep: 14/15] class: Deprecate gjs_new_object_for_constructor()



commit 19c255eb338425e71ada6cfc1725583ff1afda59
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/compat.h                |    2 +-
 gjs/jsapi-dynamic-class.cpp |   22 +++++-----------------
 gjs/jsapi-util.h            |    4 +++-
 3 files changed, 9 insertions(+), 19 deletions(-)
---
diff --git a/gjs/compat.h b/gjs/compat.h
index fe072a9..5b3aa7a 100644
--- a/gjs/compat.h
+++ b/gjs/compat.h
@@ -84,7 +84,7 @@ gjs_##name##_constructor(JSContext  *context,           \
             gjs_throw_constructor_error(context);                       \
             return false;                                               \
         }                                                               \
-        object = gjs_new_object_for_constructor(context, &gjs_##name##_class, vp); \
+        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
         if (object == NULL)                                             \
             return false;                                               \
     }
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 3cb4633..c87fc9b 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);
 }
 
 bool
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index b68d6fc..3aa0d0e 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -221,7 +221,9 @@ bool        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);
+
 bool        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]