From 5e6632a42b53ae7306af1a6b84f741f6c488e686 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Thu, 13 Jun 2024 07:33:54 +0000 Subject: [PATCH] Bug 1896973 - Part 1: Tidy some JS::Heap methods r=sfink This renames address() and unsafeGet() methods to be const and non-const versions of unsafeAddress. The unnecessary operator bool() overload is removed. Differential Revision: https://phabricator.services.mozilla.com/D212260 --- dom/bindings/BindingUtils.cpp | 2 +- dom/bindings/Codegen.py | 2 +- dom/promise/Promise-inl.h | 2 +- js/public/RootingAPI.h | 14 +++----------- js/public/TracingAPI.h | 2 +- js/src/gc/Marking.cpp | 2 +- js/xpconnect/src/XPCWrappedJS.cpp | 2 +- 7 files changed, 9 insertions(+), 17 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 198db3b5e2b5..6790fe1bc436 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -4239,7 +4239,7 @@ JS::Handle GetPerInterfaceObjectHandle( const JS::Heap& entrySlot = protoAndIfaceCache.EntrySlotMustExist(aSlotId); JS::AssertObjectIsNotGray(entrySlot); - return JS::Handle::fromMarkedLocation(entrySlot.address()); + return JS::Handle::fromMarkedLocation(entrySlot.unsafeAddress()); } namespace binding_detail { diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 59b711f3010a..9723a1546e52 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3883,7 +3883,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): fill( """ JS::AssertObjectIsNotGray(*protoCache); - JS::Handle proto = JS::Handle::fromMarkedLocation(protoCache->address()); + JS::Handle proto = JS::Handle::fromMarkedLocation(protoCache->unsafeAddress()); if (!proto) { $*{failureCode} } diff --git a/dom/promise/Promise-inl.h b/dom/promise/Promise-inl.h index a7a6ebd0fdbe..e9a9f22c45ed 100644 --- a/dom/promise/Promise-inl.h +++ b/dom/promise/Promise-inl.h @@ -195,7 +195,7 @@ class NativeThenHandler, template static JS::Handle GetJSArgHandleForCall(JS::Heap& aArg) { aArg.exposeToActiveJS(); - return JS::Handle::fromMarkedLocation(aArg.address()); + return JS::Handle::fromMarkedLocation(aArg.unsafeAddress()); } template diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index eaae2db1b7e1..9ced6b56413d 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -343,8 +343,6 @@ class MOZ_NON_MEMMOVABLE Heap : public js::HeapOperations> { DECLARE_POINTER_CONSTREF_OPS(T); DECLARE_POINTER_ASSIGN_OPS(Heap, T); - const T* address() const { return &ptr; } - void exposeToActiveJS() const { js::BarrierMethods::exposeToJS(ptr); } const T& get() const { @@ -362,17 +360,14 @@ class MOZ_NON_MEMMOVABLE Heap : public js::HeapOperations> { ptr = newPtr; postWriteBarrier(tmp, ptr); } - - T* unsafeGet() { return &ptr; } - void unbarrieredSet(const T& newPtr) { ptr = newPtr; } + T* unsafeAddress() { return &ptr; } + const T* unsafeAddress() const { return &ptr; } + explicit operator bool() const { return bool(js::BarrierMethods::asGCThingOrNull(ptr)); } - explicit operator bool() { - return bool(js::BarrierMethods::asGCThingOrNull(ptr)); - } private: void postWriteBarrier(const T& prev, const T& next) { @@ -526,9 +521,6 @@ class TenuredHeap : public js::HeapOperations> { explicit operator bool() const { return bool(js::BarrierMethods::asGCThingOrNull(unbarrieredGetPtr())); } - explicit operator bool() { - return bool(js::BarrierMethods::asGCThingOrNull(unbarrieredGetPtr())); - } TenuredHeap& operator=(T p) { setPtr(p); diff --git a/js/public/TracingAPI.h b/js/public/TracingAPI.h index 4db1b0a30ca5..72a043718f71 100644 --- a/js/public/TracingAPI.h +++ b/js/public/TracingAPI.h @@ -348,7 +348,7 @@ template inline void TraceEdge(JSTracer* trc, JS::Heap* thingp, const char* name) { MOZ_ASSERT(thingp); if (*thingp) { - js::gc::TraceExternalEdge(trc, thingp->unsafeGet(), name); + js::gc::TraceExternalEdge(trc, thingp->unsafeAddress(), name); } } diff --git a/js/src/gc/Marking.cpp b/js/src/gc/Marking.cpp index c53fbb62b417..ccad6a817ad1 100644 --- a/js/src/gc/Marking.cpp +++ b/js/src/gc/Marking.cpp @@ -2607,7 +2607,7 @@ namespace js::gc { template JS_PUBLIC_API bool TraceWeakEdge(JSTracer* trc, JS::Heap* thingp) { - return TraceEdgeInternal(trc, gc::ConvertToBase(thingp->unsafeGet()), + return TraceEdgeInternal(trc, gc::ConvertToBase(thingp->unsafeAddress()), "JS::Heap edge"); } diff --git a/js/xpconnect/src/XPCWrappedJS.cpp b/js/xpconnect/src/XPCWrappedJS.cpp index d01c8016002e..36ec8b47c76e 100644 --- a/js/xpconnect/src/XPCWrappedJS.cpp +++ b/js/xpconnect/src/XPCWrappedJS.cpp @@ -615,7 +615,7 @@ void nsXPCWrappedJS::SystemIsBeingShutDown() { // containing mJSObj, which may have been freed at this point. This is safe // if we are not currently running an incremental GC. MOZ_ASSERT(!JS::IsIncrementalGCInProgress(xpc_GetSafeJSContext())); - *mJSObj.unsafeGet() = nullptr; + mJSObj.unbarrieredSet(nullptr); if (isInList()) { remove(); }