summaryrefslogtreecommitdiffstats
path: root/js/src
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-11-09 21:10:53 -0500
committerMatt A. Tobin <email@mattatobin.com>2020-11-09 21:10:53 -0500
commit4694c609642b6c193d8e16cf1203694d9a3b008c (patch)
tree7938ed64254807d68798748fed4d6868a2e12bd8 /js/src
parent74ebcea4094f6e350936bb416c4c9598f404af0f (diff)
downloadUXP-4694c609642b6c193d8e16cf1203694d9a3b008c.tar
UXP-4694c609642b6c193d8e16cf1203694d9a3b008c.tar.gz
UXP-4694c609642b6c193d8e16cf1203694d9a3b008c.tar.lz
UXP-4694c609642b6c193d8e16cf1203694d9a3b008c.tar.xz
UXP-4694c609642b6c193d8e16cf1203694d9a3b008c.zip
Bug 1328948 - Add is(), as() to Cell.
Tag #1679
Diffstat (limited to 'js/src')
-rw-r--r--js/src/gc/Heap.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/js/src/gc/Heap.h b/js/src/gc/Heap.h
index 60e7ef729..208941532 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 <class T>
+ inline bool is() const {
+ return getTraceKind() == JS::MapTypeToTraceKind<T>::kind;
+ }
+
+ template<class T>
+ inline T* as() {
+ MOZ_ASSERT(is<T>());
+ return static_cast<T*>(this);
+ }
+
+ template <class T>
+ inline const T* as() const {
+ MOZ_ASSERT(is<T>());
+ return static_cast<const T*>(this);
+ }
+
#ifdef DEBUG
inline bool isAligned() const;
void dump(FILE* fp) const;