[gjs/wip/ptomato/mozjs31prep] jsapi-util: Use CallArgs in gjs_throw_abstract_constructor_error()



commit 4c7810cbb4ea39d54ea0a3c68f7e7fc68f285466
Author: Philip Chimento <philip endlessm com>
Date:   Tue Oct 25 18:19:23 2016 -0700

    jsapi-util: Use CallArgs in gjs_throw_abstract_constructor_error()
    
    JS_CALLEE(), with which you could figure out the function being called
    from a vp array, is gone in mozjs31. Instead, use JS::CallArgs::callee(),
    meaning that we have to pass JS::CallArgs into
    gjs_throw_abstract_constructor_error() instead of the vp array.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742249

 gjs/jsapi-util.cpp |   23 +++++++++--------------
 gjs/jsapi-util.h   |    8 +++++---
 2 files changed, 14 insertions(+), 17 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 37a635b..38a7920 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -280,23 +280,18 @@ gjs_throw_constructor_error(JSContext *context)
 }
 
 void
-gjs_throw_abstract_constructor_error(JSContext *context,
-                                     JS::Value *vp)
+gjs_throw_abstract_constructor_error(JSContext    *context,
+                                     JS::CallArgs& args)
 {
-    JS::Value callee;
-    JSClass *proto_class;
+    const JSClass *proto_class;
     const char *name = "anonymous";
 
-    callee = JS_CALLEE(context, vp);
-
-    if (callee.isObject()) {
-        JS::RootedObject callee_obj(context, &callee.toObject());
-        JS::RootedValue prototype(context);
-        if (gjs_object_get_property_const(context, callee_obj,
-                                          GJS_STRING_PROTOTYPE, &prototype)) {
-            proto_class = JS_GetClass(&prototype.toObject());
-            name = proto_class->name;
-        }
+    JS::RootedObject callee(context, &args.callee());
+    JS::RootedValue prototype(context);
+    if (gjs_object_get_property_const(context, callee,
+                                      GJS_STRING_PROTOTYPE, &prototype)) {
+        proto_class = JS_GetClass(&prototype.toObject());
+        name = proto_class->name;
     }
 
     gjs_throw(context, "You cannot construct new instances of '%s'", name);
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 78681bb..ea9e074 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -288,7 +288,8 @@ gjs_##name##_constructor(JSContext  *context,           \
 #define GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(name)            \
     GJS_NATIVE_CONSTRUCTOR_DECLARE(name)                        \
     {                                                           \
-        gjs_throw_abstract_constructor_error(context, vp);      \
+        JS::CallArgs args = JS::CallArgsFromVp(argc, vp);       \
+        gjs_throw_abstract_constructor_error(context, args);    \
         return false;                                           \
     }
 
@@ -332,8 +333,9 @@ bool gjs_init_class_dynamic(JSContext              *context,
                             JS::MutableHandleObject constructor);
 
 void gjs_throw_constructor_error             (JSContext       *context);
-void gjs_throw_abstract_constructor_error    (JSContext       *context,
-                                              JS::Value       *vp);
+
+void gjs_throw_abstract_constructor_error(JSContext    *context,
+                                          JS::CallArgs& args);
 
 bool        gjs_typecheck_instance            (JSContext  *context,
                                                JSObject   *obj,


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