From 4694c609642b6c193d8e16cf1203694d9a3b008c Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Mon, 9 Nov 2020 21:10:53 -0500 Subject: Bug 1328948 - Add is(), as() to Cell. Tag #1679 --- js/src/gc/Heap.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'js/src/gc/Heap.h') diff --git a/js/src/gc/Heap.h b/js/src/gc/Heap.h index 60e7ef729c..2089415326 100644 --- a/js/src/gc/Heap.h +++ b/js/src/gc/Heap.h @@ -28,6 +28,7 @@ #include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TracingAPI.h" +#include "js/TraceKind.h" struct JSRuntime; @@ -272,6 +273,23 @@ struct Cell static MOZ_ALWAYS_INLINE bool needWriteBarrierPre(JS::Zone* zone); + template + inline bool is() const { + return getTraceKind() == JS::MapTypeToTraceKind::kind; + } + + template + inline T* as() { + MOZ_ASSERT(is()); + return static_cast(this); + } + + template + inline const T* as() const { + MOZ_ASSERT(is()); + return static_cast(this); + } + #ifdef DEBUG inline bool isAligned() const; void dump(FILE* fp) const; -- cgit v1.2.3