From 645785871dbf504ba13cdbfa3275ca79bb28b9fe Mon Sep 17 00:00:00 2001 From: roytam1 Date: Mon, 18 Apr 2022 14:16:07 +0800 Subject: [PATCH] import from UXP: Bug 1328948 - Add is(), as() to Cell. (d646d440) --- js/src/gc/Heap.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/src/gc/Heap.h b/js/src/gc/Heap.h index 697803380..7f2c5fb4f 100644 --- a/js/src/gc/Heap.h +++ b/js/src/gc/Heap.h @@ -29,6 +29,7 @@ #include "js/HeapAPI.h" #include "js/RootingAPI.h" #include "js/TracingAPI.h" +#include "js/TraceKind.h" struct JSRuntime; @@ -273,6 +274,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;