From d7750999b3b1c5edefe6a70d00ae934045cdf562 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 27 Jun 2021 20:57:39 +0100 Subject: [PATCH] LibJS: Implement the TypedArray [[ContentType]] internal slot --- Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 4 ++++ Userland/Libraries/LibJS/Runtime/TypedArray.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 8a2f0ee895..f42bc1fa3b 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -204,6 +204,10 @@ void TypedArrayBase::visit_edges(Visitor& visitor) ClassName::ClassName(u32 length, Object& prototype) \ : TypedArray(length, prototype) \ { \ + if constexpr (StringView { #ClassName }.is_one_of("BigInt64Array", "BigUint64Array")) \ + m_content_type = ContentType::BigInt; \ + else \ + m_content_type = ContentType::Number; \ } \ \ ClassName::~ClassName() { } \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index c84a5cbe69..0ea87b77d5 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -17,9 +17,15 @@ class TypedArrayBase : public Object { JS_OBJECT(TypedArrayBase, Object); public: + enum class ContentType { + BigInt, + Number, + }; + u32 array_length() const { return m_array_length; } u32 byte_length() const { return m_byte_length; } u32 byte_offset() const { return m_byte_offset; } + ContentType content_type() const { return m_content_type; } ArrayBuffer* viewed_array_buffer() const { return m_viewed_array_buffer; } void set_array_length(u32 length) { m_array_length = length; } @@ -39,6 +45,7 @@ protected: u32 m_array_length { 0 }; u32 m_byte_length { 0 }; u32 m_byte_offset { 0 }; + ContentType m_content_type { ContentType::Number }; ArrayBuffer* m_viewed_array_buffer { nullptr }; private: