[gjs/mozjs102: 9/11] js: Remove Gjs::maybe_get_private()



commit ab18f5dad74820a589b878ce74d290bf18636f18
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 6 17:06:56 2022 -0700

    js: Remove Gjs::maybe_get_private()
    
    This function was necessary in SpiderMonkey 91, but now the same
    functionality is part of the SpiderMonkey API. There is no longer any need
    to define our own.

 gi/cwrapper.h             |  6 +++---
 gi/param.cpp              |  4 ++--
 gjs/jsapi-util.h          | 14 --------------
 gjs/module.cpp            |  2 +-
 modules/cairo-pattern.cpp |  4 ++--
 modules/cairo-surface.cpp |  4 ++--
 test/gjs-test-rooting.cpp |  3 +--
 7 files changed, 11 insertions(+), 26 deletions(-)
---
diff --git a/gi/cwrapper.h b/gi/cwrapper.h
index 47c8e29ae..cc13d6d68 100644
--- a/gi/cwrapper.h
+++ b/gi/cwrapper.h
@@ -86,7 +86,7 @@ class CWrapperPointerOps {
         if (!JS_InstanceOf(cx, wrapper, &Base::klass, nullptr))
             return nullptr;
 
-        return Gjs::maybe_get_private<Wrapped>(wrapper, POINTER);
+        return JS::GetMaybePtrFromReservedSlot<Wrapped>(wrapper, POINTER);
     }
 
     /*
@@ -139,7 +139,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 Gjs::maybe_get_private<Wrapped>(wrapper, POINTER);
+        return JS::GetMaybePtrFromReservedSlot<Wrapped>(wrapper, POINTER);
     }
 
  protected:
@@ -153,7 +153,7 @@ class CWrapperPointerOps {
      * wrapper object.
      */
     [[nodiscard]] static bool has_private(JSObject* wrapper) {
-        return !!Gjs::maybe_get_private<Wrapped>(wrapper, POINTER);
+        return !!JS::GetMaybePtrFromReservedSlot<Wrapped>(wrapper, POINTER);
     }
 
     /*
diff --git a/gi/param.cpp b/gi/param.cpp
index 089b7572e..93fff17e6 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -48,7 +48,7 @@ struct Param : GjsAutoParam {
     if (!JS_InstanceOf(cx, obj, &gjs_param_class, nullptr))
         return nullptr;
 
-    auto* priv = Gjs::maybe_get_private<Param>(obj, POINTER);
+    auto* priv = JS::GetMaybePtrFromReservedSlot<Param>(obj, POINTER);
     return priv ? priv->get() : nullptr;
 }
 
@@ -124,7 +124,7 @@ static bool gjs_param_constructor(JSContext* cx, unsigned argc, JS::Value* vp) {
 }
 
 static void param_finalize(JS::GCContext*, JSObject* obj) {
-    Param* priv = Gjs::maybe_get_private<Param>(obj, POINTER);
+    Param* priv = JS::GetMaybePtrFromReservedSlot<Param>(obj, POINTER);
     gjs_debug_lifecycle(GJS_DEBUG_GPARAM, "finalize, obj %p priv %p", obj,
                         priv);
     if (!priv)
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index a891fa42c..0724181e3 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -26,10 +26,8 @@
 #include <js/GCAPI.h>
 #include <js/GCPolicyAPI.h>  // for IgnoreGCPolicy
 #include <js/Id.h>
-#include <js/Object.h>  // for GetReservedSlot
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
-#include <js/Value.h>
 #include <jspubtd.h>     // for JSProtoKey
 
 #include "gjs/macros.h"
@@ -636,18 +634,6 @@ template <typename T>
     return true;
 }
 
-/**
- * Helper function, backported from future SpiderMonkey's
- * JS::GetMaybePtrFromReservedSlot(), to get the pointer value (or nullptr if
- * not set) from an object's reserved slot. The slot must contain either a
- * JS::PrivateValue(T*) or JS::UndefinedValue.
- */
-template <typename T>
-inline T* maybe_get_private(JSObject* obj, size_t slot) {
-    JS::Value v = JS::GetReservedSlot(obj, slot);
-    return v.isUndefined() ? nullptr : static_cast<T*>(v.toPrivate());
-}
-
 }  // namespace Gjs
 
 [[nodiscard]] const char* gjs_explain_gc_reason(JS::GCReason reason);
diff --git a/gjs/module.cpp b/gjs/module.cpp
index ccf20374c..c0422caf0 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -80,7 +80,7 @@ class GjsScriptModule {
     /* Private data accessors */
 
     [[nodiscard]] static inline GjsScriptModule* priv(JSObject* module) {
-        return Gjs::maybe_get_private<GjsScriptModule>(
+        return JS::GetMaybePtrFromReservedSlot<GjsScriptModule>(
             module, GjsScriptModule::POINTER);
     }
 
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index 9d5a847ac..9e7e36929 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -136,6 +136,6 @@ cairo_pattern_t* CairoPattern::for_js(JSContext* cx,
         return nullptr;
     }
 
-    return Gjs::maybe_get_private<cairo_pattern_t>(pattern_wrapper,
-                                                   CairoPattern::POINTER);
+    return JS::GetMaybePtrFromReservedSlot<cairo_pattern_t>(
+        pattern_wrapper, CairoPattern::POINTER);
 }
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index abeca366b..877186439 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -271,8 +271,8 @@ cairo_surface_t* CairoSurface::for_js(JSContext* cx,
         return nullptr;
     }
 
-    return Gjs::maybe_get_private<cairo_surface_t>(surface_wrapper,
-                                                   CairoSurface::POINTER);
+    return JS::GetMaybePtrFromReservedSlot<cairo_surface_t>(
+        surface_wrapper, CairoSurface::POINTER);
 }
 
 [[nodiscard]] static bool surface_to_g_argument(
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index ecf79f453..7a96ba1ed 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -16,7 +16,6 @@
 
 #include "gjs/context-private.h"
 #include "gjs/jsapi-util-root.h"
-#include "gjs/jsapi-util.h"  // for maybe_get_private
 #include "test/gjs-test-utils.h"
 
 class JSTracer;
@@ -45,7 +44,7 @@ struct GjsRootingFixture {
 };
 
 static void test_obj_finalize(JS::GCContext*, JSObject* obj) {
-    bool* finalized_p = Gjs::maybe_get_private<bool>(obj, POINTER);
+    bool* finalized_p = JS::GetMaybePtrFromReservedSlot<bool>(obj, POINTER);
     g_assert_false(*finalized_p);
     *finalized_p = true;
 }


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