[gjs/mozjs91: 121/135] Some Object-related functions have moved to js/Object.h




commit 00f68dea91d3910b5b398eb0b85a354425d2413f
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Jul 10 20:14:56 2021 -0700

    Some Object-related functions have moved to js/Object.h
    
    - JS_[Get,Set]Private is now JS::[Get,Set]Private
    - JS_GetReservedSlot is now JS::GetReservedSlot
    - JS_SetReservedSlot still exists, but we'll update it now
    
    See https://bugzilla.mozilla.org/show_bug.cgi?id=1663365

 gi/cwrapper.h             | 11 ++++++-----
 gi/function.cpp           |  5 +++--
 gi/gtype.cpp              |  3 ++-
 gi/ns.cpp                 |  7 ++++---
 gi/param.cpp              |  7 ++++---
 gi/wrapperutils.h         | 11 ++++++-----
 gjs/context.cpp           |  2 +-
 gjs/gjs_pch.hh            |  1 +
 gjs/global.cpp            |  5 +++--
 gjs/module.cpp            |  5 +++--
 modules/cairo-context.cpp |  3 ++-
 modules/cairo-path.cpp    |  5 +++--
 modules/cairo-pattern.cpp |  5 +++--
 modules/cairo-surface.cpp |  5 +++--
 test/gjs-test-rooting.cpp |  7 ++++---
 15 files changed, 48 insertions(+), 34 deletions(-)
---
diff --git a/gi/cwrapper.h b/gi/cwrapper.h
index 436eefd2..55324380 100644
--- a/gi/cwrapper.h
+++ b/gi/cwrapper.h
@@ -17,6 +17,7 @@
 #include <js/Class.h>
 #include <js/ComparisonOperators.h>
 #include <js/Id.h>
+#include <js/Object.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Value.h>
@@ -134,7 +135,7 @@ class CWrapperPointerOps {
      * (It can return null if no private data has been set yet on the wrapper.)
      */
     [[nodiscard]] static Wrapped* for_js_nocheck(JSObject* wrapper) {
-        return static_cast<Wrapped*>(JS_GetPrivate(wrapper));
+        return static_cast<Wrapped*>(JS::GetPrivate(wrapper));
     }
 };
 
@@ -213,7 +214,7 @@ class CWrapper : public CWrapperPointerOps<Base, Wrapped> {
         Wrapped* priv = Base::constructor_impl(cx, args);
         if (!priv)
             return false;
-        JS_SetPrivate(object, priv);
+        JS::SetPrivate(object, priv);
 
         args.rval().setObject(*object);
         return true;
@@ -258,7 +259,7 @@ class CWrapper : public CWrapperPointerOps<Base, Wrapped> {
         Base::finalize_impl(fop, priv);
 
         // Remove the pointer from the JSObject
-        JS_SetPrivate(obj, nullptr);
+        JS::SetPrivate(obj, nullptr);
     }
 
     static constexpr JSClassOps class_ops = {
@@ -494,8 +495,8 @@ class CWrapper : public CWrapperPointerOps<Base, Wrapped> {
         if (!wrapper)
             return nullptr;
 
-        assert(!JS_GetPrivate(wrapper));
-        JS_SetPrivate(wrapper, Base::copy_ptr(ptr));
+        assert(!JS::GetPrivate(wrapper));
+        JS::SetPrivate(wrapper, Base::copy_ptr(ptr));
 
         debug_lifecycle(ptr, wrapper, "from_c_ptr");
 
diff --git a/gi/function.cpp b/gi/function.cpp
index 2c549203..e3d193f6 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -23,6 +23,7 @@
 #include <js/Class.h>
 #include <js/ErrorReport.h>  // for JS_ReportOutOfMemory
 #include <js/Exception.h>
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_PERMANENT
 #include <js/PropertySpec.h>
 #include <js/Realm.h>  // for GetRealmFunctionPrototype
@@ -1299,8 +1300,8 @@ JSObject* Function::create(JSContext* context, GType gtype,
 
     auto* priv = new Function(info);
 
-    g_assert(!JS_GetPrivate(function) && "Function should be a fresh object");
-    JS_SetPrivate(function, priv);
+    g_assert(!JS::GetPrivate(function) && "Function should be a fresh object");
+    JS::SetPrivate(function, priv);
 
     debug_lifecycle(function, priv, "Constructor");
 
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 7ccb8099..d6589250 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -12,6 +12,7 @@
 #include <js/CallArgs.h>
 #include <js/Class.h>
 #include <js/GCHashTable.h>         // for WeakCache
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_PERMANENT
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -170,7 +171,7 @@ class GTypeObj : public CWrapper<GTypeObj, void> {
         if (!gtype_wrapper)
             return nullptr;
 
-        JS_SetPrivate(gtype_wrapper, GSIZE_TO_POINTER(gtype));
+        JS::SetPrivate(gtype_wrapper, GSIZE_TO_POINTER(gtype));
 
         gjs->gtype_table().put(gtype, gtype_wrapper);
 
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 714e5b34..a5d5feb3 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -12,12 +12,13 @@
 #include <js/ComparisonOperators.h>
 #include <js/ErrorReport.h>  // for JS_ReportOutOfMemory
 #include <js/Id.h>
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
-#include <jsapi.h>       // for JS_GetPrivate, JS_NewObjectWithGivenProto
+#include <jsapi.h>       // for JS_NewObjectWithGivenProto
 
 #include "gi/cwrapper.h"
 #include "gi/ns.h"
@@ -218,8 +219,8 @@ class Ns : private GjsAutoChar, public CWrapper<Ns> {
             return nullptr;
 
         auto* priv = new Ns(ns_name);
-        g_assert(!JS_GetPrivate(ns));
-        JS_SetPrivate(ns, priv);
+        g_assert(!JS::GetPrivate(ns));
+        JS::SetPrivate(ns, priv);
 
         gjs_debug_lifecycle(GJS_DEBUG_GNAMESPACE,
                             "ns constructor, obj %p priv %p", ns.get(), priv);
diff --git a/gi/param.cpp b/gi/param.cpp
index 29d2e6f0..a0796fc6 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -9,6 +9,7 @@
 
 #include <js/CallArgs.h>
 #include <js/Class.h>
+#include <js/Object.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
@@ -113,14 +114,14 @@ static bool gjs_param_constructor(JSContext* cx, unsigned argc, JS::Value* vp) {
 }
 
 static void param_finalize(JSFreeOp*, JSObject* obj) {
-    Param* priv = static_cast<Param*>(JS_GetPrivate(obj));
+    Param* priv = static_cast<Param*>(JS::GetPrivate(obj));
     gjs_debug_lifecycle(GJS_DEBUG_GPARAM, "finalize, obj %p priv %p", obj,
                         priv);
     if (!priv)
         return; /* wrong class? */
 
     GJS_DEC_COUNTER(param);
-    JS_SetPrivate(obj, nullptr);
+    JS::SetPrivate(obj, nullptr);
     delete priv;
 }
 
@@ -219,7 +220,7 @@ gjs_param_from_g_param(JSContext    *context,
 
     GJS_INC_COUNTER(param);
     auto* priv = new Param(gparam);
-    JS_SetPrivate(obj, priv);
+    JS::SetPrivate(obj, priv);
 
     gjs_debug(GJS_DEBUG_GPARAM,
               "JSObject created with param instance %p type %s", gparam,
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 777fb72c..da346a38 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -20,9 +20,10 @@
 #include <js/ComparisonOperators.h>
 #include <js/Id.h>
 #include <js/MemoryFunctions.h>
+#include <js/Object.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
-#include <jsapi.h>       // for JS_GetPrivate, JS_SetPrivate, JS_Ge...
+#include <jsapi.h>       // for JS_Ge...
 #include <jspubtd.h>     // for JSProto_TypeError
 
 #include "gi/arg-inl.h"
@@ -369,7 +370,7 @@ class GIWrapperBase : public CWrapperPointerOps<Base> {
             priv->to_instance()->finalize_impl(fop, obj);
 
         // Remove the pointer from the JSObject
-        JS_SetPrivate(obj, nullptr);
+        JS::SetPrivate(obj, nullptr);
     }
 
     /*
@@ -852,7 +853,7 @@ class GIWrapperPrototype : public Base {
         // a garbage collection or error happens subsequently, then this object
         // might be traced and we would end up dereferencing a null pointer.
         Prototype* proto = priv.release();
-        JS_SetPrivate(prototype, proto);
+        JS::SetPrivate(prototype, proto);
 
         if (!gjs_wrapper_define_gtype_prop(cx, constructor, gtype))
             return nullptr;
@@ -970,13 +971,13 @@ class GIWrapperInstance : public Base {
      */
     [[nodiscard]] static Instance* new_for_js_object(JSContext* cx,
                                                      JS::HandleObject obj) {
-        g_assert(!JS_GetPrivate(obj));
+        g_assert(!JS::GetPrivate(obj));
         auto* priv = new Instance(cx, obj);
 
         // Init the private variable before we do anything else. If a garbage
         // collection happens when calling the constructor, then this object
         // might be traced and we would end up dereferencing a null pointer.
-        JS_SetPrivate(obj, priv);
+        JS::SetPrivate(obj, priv);
 
         return priv;
     }
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 349bd3a1..d208dae1 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -423,7 +423,7 @@ void GjsContextPrivate::dispose(void) {
         m_gtype_table->clear();
 
         /* Do a full GC here before tearing down, since once we do
-         * that we may not have the JS_GetPrivate() to access the
+         * that we may not have the JS::GetPrivate() to access the
          * context
          */
         gjs_debug(GJS_DEBUG_CONTEXT, "Final triggered GC");
diff --git a/gjs/gjs_pch.hh b/gjs/gjs_pch.hh
index be31fd0d..6d15bddf 100644
--- a/gjs/gjs_pch.hh
+++ b/gjs/gjs_pch.hh
@@ -74,6 +74,7 @@
 #include <js/MapAndSet.h>
 #include <js/MemoryFunctions.h>
 #include <js/Modules.h>
+#include <js/Object.h>
 #include <js/ProfilingCategory.h>
 #include <js/ProfilingStack.h>
 #include <js/Promise.h>
diff --git a/gjs/global.cpp b/gjs/global.cpp
index c6f28a67..912d5a84 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -18,6 +18,7 @@
 #include <js/CompileOptions.h>
 #include <js/Id.h>
 #include <js/MapAndSet.h>
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_PERMANENT, JSPROP_RE...
 #include <js/PropertySpec.h>
 #include <js/Realm.h>  // for GetObjectRealmOrNull, SetRealmPrivate
@@ -522,11 +523,11 @@ bool gjs_define_global_properties(JSContext* cx, JS::HandleObject global,
 }
 
 void detail::set_global_slot(JSObject* global, uint32_t slot, JS::Value value) {
-    JS_SetReservedSlot(global, JSCLASS_GLOBAL_SLOT_COUNT + slot, value);
+    JS::SetReservedSlot(global, JSCLASS_GLOBAL_SLOT_COUNT + slot, value);
 }
 
 JS::Value detail::get_global_slot(JSObject* global, uint32_t slot) {
-    return JS_GetReservedSlot(global, JSCLASS_GLOBAL_SLOT_COUNT + slot);
+    return JS::GetReservedSlot(global, JSCLASS_GLOBAL_SLOT_COUNT + slot);
 }
 
 decltype(GjsGlobal::klass) constexpr GjsGlobal::klass;
diff --git a/gjs/module.cpp b/gjs/module.cpp
index 5aa6a981..c41f4b38 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -24,6 +24,7 @@
 #include <js/GCVector.h>  // for RootedVector
 #include <js/Id.h>
 #include <js/Modules.h>
+#include <js/Object.h>
 #include <js/Promise.h>
 #include <js/PropertyDescriptor.h>
 #include <js/Realm.h>
@@ -67,13 +68,13 @@ class GjsScriptModule {
     /* Private data accessors */
 
     [[nodiscard]] static inline GjsScriptModule* priv(JSObject* module) {
-        return static_cast<GjsScriptModule*>(JS_GetPrivate(module));
+        return static_cast<GjsScriptModule*>(JS::GetPrivate(module));
     }
 
     /* Creates a JS module object. Use instead of the class's constructor */
     [[nodiscard]] static JSObject* create(JSContext* cx, const char* name) {
         JSObject* module = JS_NewObject(cx, &GjsScriptModule::klass);
-        JS_SetPrivate(module, new GjsScriptModule(name));
+        JS::SetPrivate(module, new GjsScriptModule(name));
         return module;
     }
 
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 803b9e19..d6899622 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -13,6 +13,7 @@
 #include <js/Array.h>  // for JS::NewArrayObject
 #include <js/CallArgs.h>
 #include <js/Conversions.h>
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -368,7 +369,7 @@ dispose_func(JSContext *context,
     _GJS_CAIRO_CONTEXT_GET_PRIV_CR_CHECKED(context, argc, vp, rec, obj);
 
     cairo_destroy(cr);
-    JS_SetPrivate(obj, nullptr);
+    JS::SetPrivate(obj, nullptr);
 
     rec.rval().setUndefined();
     return true;
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index a4a82725..76a879df 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -8,6 +8,7 @@
 #include <cairo.h>
 #include <glib.h>  // for g_assert
 
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -37,8 +38,8 @@ JSObject* CairoPath::take_c_ptr(JSContext* cx, cairo_path_t* ptr) {
     if (!wrapper)
         return nullptr;
 
-    g_assert(!JS_GetPrivate(wrapper));
-    JS_SetPrivate(wrapper, ptr);
+    g_assert(!JS::GetPrivate(wrapper));
+    JS::SetPrivate(wrapper, ptr);
 
     debug_lifecycle(ptr, wrapper, "take_c_ptr");
 
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index 093e6fd8..53658cf1 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -9,11 +9,12 @@
 
 #include <js/CallArgs.h>
 #include <js/Class.h>
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
-#include <jsapi.h>  // for JS_GetPrivate, JS_GetClass, ...
+#include <jsapi.h>  // for JS_GetClass, ...
 
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-util.h"
@@ -136,5 +137,5 @@ cairo_pattern_t* CairoPattern::for_js(JSContext* cx,
         return nullptr;
     }
 
-    return static_cast<cairo_pattern_t*>(JS_GetPrivate(pattern_wrapper));
+    return static_cast<cairo_pattern_t*>(JS::GetPrivate(pattern_wrapper));
 }
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index d8b50483..0697c58b 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -11,13 +11,14 @@
 #include <js/Array.h>
 #include <js/CallArgs.h>
 #include <js/Class.h>
+#include <js/Object.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Value.h>
 #include <js/ValueArray.h>
-#include <jsapi.h>  // for JS_GetPrivate, JS_GetClass, ...
+#include <jsapi.h>  // for JS_GetClass, ...
 
 #include "gi/arg-inl.h"
 #include "gi/arg.h"
@@ -272,7 +273,7 @@ cairo_surface_t* CairoSurface::for_js(JSContext* cx,
         return nullptr;
     }
 
-    return static_cast<cairo_surface_t*>(JS_GetPrivate(surface_wrapper));
+    return static_cast<cairo_surface_t*>(JS::GetPrivate(surface_wrapper));
 }
 
 [[nodiscard]] static bool surface_to_g_argument(
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index a58753da..7a82f70d 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -7,10 +7,11 @@
 
 #include <js/Class.h>
 #include <js/GCAPI.h>  // for JS_GC, JS_SetGCCallback, JSGCStatus
+#include <js/Object.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Value.h>
-#include <jsapi.h>  // for JS_GetPrivate, JS_NewObject, JS_Set...
+#include <jsapi.h>  // for JS_NewObject
 
 #include "gjs/context-private.h"
 #include "gjs/jsapi-util-root.h"
@@ -37,7 +38,7 @@ struct GjsRootingFixture {
 };
 
 static void test_obj_finalize(JSFreeOp*, JSObject* obj) {
-    bool *finalized_p = static_cast<bool *>(JS_GetPrivate(obj));
+    bool* finalized_p = static_cast<bool*>(JS::GetPrivate(obj));
     g_assert_false(*finalized_p);
     *finalized_p = true;
 }
@@ -61,7 +62,7 @@ static JSObject *
 test_obj_new(GjsRootingFixture *fx)
 {
     JSObject *retval = JS_NewObject(PARENT(fx)->cx, &test_obj_class);
-    JS_SetPrivate(retval, &fx->finalized);
+    JS::SetPrivate(retval, &fx->finalized);
     return retval;
 }
 


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