summaryrefslogtreecommitdiffstats
path: root/js/src/ds
diff options
context:
space:
mode:
authortrav90 <travawine@palemoon.org>2018-09-02 18:59:51 -0500
committertrav90 <travawine@palemoon.org>2018-09-02 20:07:47 -0500
commit36cb80d1cac66a1511bec4ad97947a2deeab2e08 (patch)
tree71212ddd26aa7a37b5ef4c5390e3e33c4db69c94 /js/src/ds
parentb4aed63f5758b955e84840c5871b1301ccb6968f (diff)
downloadUXP-36cb80d1cac66a1511bec4ad97947a2deeab2e08.tar
UXP-36cb80d1cac66a1511bec4ad97947a2deeab2e08.tar.gz
UXP-36cb80d1cac66a1511bec4ad97947a2deeab2e08.tar.lz
UXP-36cb80d1cac66a1511bec4ad97947a2deeab2e08.tar.xz
UXP-36cb80d1cac66a1511bec4ad97947a2deeab2e08.zip
Call the relevant scope-data constructor when allocating it, and poison/mark as undefined the memory for the trailing array of BindingNames, ratther than impermissibly PodZero-ing non-trivial classes.
Diffstat (limited to 'js/src/ds')
-rw-r--r--js/src/ds/LifoAlloc.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/js/src/ds/LifoAlloc.h b/js/src/ds/LifoAlloc.h
index f349cd476..b4e9c3418 100644
--- a/js/src/ds/LifoAlloc.h
+++ b/js/src/ds/LifoAlloc.h
@@ -15,6 +15,8 @@
#include "mozilla/TemplateLib.h"
#include "mozilla/TypeTraits.h"
+#include <new>
+
// This data structure supports stacky LIFO allocation (mark/release and
// LifoAllocScope). It does not maintain one contiguous segment; instead, it
// maintains a bunch of linked memory segments. In order to prevent malloc/free
@@ -285,6 +287,20 @@ class LifoAlloc
return allocImpl(n);
}
+ template<typename T, typename... Args>
+ MOZ_ALWAYS_INLINE T*
+ allocInSize(size_t n, Args&&... args)
+ {
+ MOZ_ASSERT(n >= sizeof(T), "must request enough space to store a T");
+ static_assert(alignof(T) <= detail::LIFO_ALLOC_ALIGN,
+ "LifoAlloc must provide enough alignment to store T");
+ void* ptr = alloc(n);
+ if (!ptr)
+ return nullptr;
+
+ return new (ptr) T(mozilla::Forward<Args>(args)...);
+ }
+
MOZ_ALWAYS_INLINE
void* allocInfallible(size_t n) {
AutoEnterOOMUnsafeRegion oomUnsafe;