mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
LibJS: Allocate concrete TypedArrays with a preallocated base TypedArray
TypedArray constructors/prototypes are currently allocating within their C++ constructor when trying to access the intrinsic base TypedArray. To prevent this, construct these objects with an already-allocated base TypedArray.
This commit is contained in:
parent
c0952e3670
commit
31d315001c
3 changed files with 23 additions and 8 deletions
|
@ -259,12 +259,27 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
|
|||
m_object_prototype_to_string_function = &object_prototype()->get_without_side_effects(vm.names.toString).as_function();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr inline bool IsTypedArrayConstructor = false;
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||
template<> \
|
||||
constexpr inline bool IsTypedArrayConstructor<ConstructorName> = true;
|
||||
JS_ENUMERATE_TYPED_ARRAYS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE_INNER(ClassName, snake_name, PrototypeName, ConstructorName, Namespace, snake_namespace) \
|
||||
void Intrinsics::initialize_##snake_namespace##snake_name() \
|
||||
{ \
|
||||
auto& vm = this->vm(); \
|
||||
m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, m_realm); \
|
||||
m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm); \
|
||||
\
|
||||
if constexpr (IsTypedArrayConstructor<Namespace::ConstructorName>) { \
|
||||
m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, *typed_array_prototype()); \
|
||||
m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm, *typed_array_constructor()); \
|
||||
} else { \
|
||||
m_##snake_namespace##snake_name##_prototype = heap().allocate<Namespace::PrototypeName>(m_realm, m_realm); \
|
||||
m_##snake_namespace##snake_name##_constructor = heap().allocate<Namespace::ConstructorName>(m_realm, m_realm); \
|
||||
} \
|
||||
\
|
||||
/* FIXME: Add these special cases to JS_ENUMERATE_NATIVE_OBJECTS */ \
|
||||
if constexpr (IsSame<Namespace::ConstructorName, BigIntConstructor>) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue