summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2022-08-06 17:06:56 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2022-08-07 16:42:03 -0700
commit853d32d367e395b9c18b9c067a966192cdbe10ce (patch)
treebaa1c5dfe353fd7f6c5682811bc129698515b17e
parentfdcfc12272d0b25a4c028ffbe7ef1f4063db88f3 (diff)
downloadgjs-853d32d367e395b9c18b9c067a966192cdbe10ce.tar.gz
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.
-rw-r--r--gi/cwrapper.h6
-rw-r--r--gi/param.cpp4
-rw-r--r--gjs/jsapi-util.h14
-rw-r--r--gjs/module.cpp2
-rw-r--r--modules/cairo-pattern.cpp4
-rw-r--r--modules/cairo-surface.cpp4
-rw-r--r--test/gjs-test-rooting.cpp3
7 files changed, 11 insertions, 26 deletions
diff --git a/gi/cwrapper.h b/gi/cwrapper.h
index 47c8e29a..cc13d6d6 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 089b7572..93fff17e 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 a891fa42..0724181e 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 ccf20374..c0422caf 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 9d5a847a..9e7e3692 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 abeca366..87718643 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 ecf79f45..7a96ba1e 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;
}