summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-07-11 10:37:11 -0400
committerLinus Groh <mail@linusgroh.de>2021-07-14 20:44:42 +0100
commit4f8f79c5ca1c564cc180d8400219204f11dbf19a (patch)
treebdb06f9fba8e3b299732e32e127586041bb2c3df /Userland/Libraries
parentf4ea6b182404e510d05ebd1e36c4160660d1ef1a (diff)
downloadserenity-4f8f79c5ca1c564cc180d8400219204f11dbf19a.zip
LibJS: Add some TypedArray abstractions for querying underlying type
IsUnclampedIntegerElementType and IsBigIntElementType.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h
index fb501170e1..2a32799a9d 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.h
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h
@@ -40,6 +40,10 @@ public:
virtual size_t element_size() const = 0;
virtual String element_name() const = 0;
+ // 25.1.2.6 IsUnclampedIntegerElementType ( type ), https://tc39.es/ecma262/#sec-isunclampedintegerelementtype
+ virtual bool is_unclamped_integer_element_type() const = 0;
+ // 25.1.2.7 IsBigIntElementType ( type ), https://tc39.es/ecma262/#sec-isbigintelementtype
+ virtual bool is_bigint_element_type() const = 0;
// 25.1.2.10 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isTypedArray, order [ , isLittleEndian ] ), https://tc39.es/ecma262/#sec-getvaluefrombuffer
virtual Value get_value_from_buffer(size_t byte_index, ArrayBuffer::Order, bool is_little_endian = true) const = 0;
// 25.1.2.12 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ), https://tc39.es/ecma262/#sec-setvalueinbuffer
@@ -438,6 +442,18 @@ public:
virtual size_t element_size() const override { return sizeof(UnderlyingBufferDataType); };
+ bool is_unclamped_integer_element_type() const override
+ {
+ constexpr bool is_unclamped_integer = IsSame<T, i8> || IsSame<T, u8> || IsSame<T, i16> || IsSame<T, u16> || IsSame<T, i32> || IsSame<T, u32>;
+ return is_unclamped_integer;
+ }
+
+ bool is_bigint_element_type() const override
+ {
+ constexpr bool is_bigint = IsSame<T, i64> || IsSame<T, u64>;
+ return is_bigint;
+ }
+
Value get_value_from_buffer(size_t byte_index, ArrayBuffer::Order order, bool is_little_endian = true) const override { return viewed_array_buffer()->template get_value<T>(byte_index, true, order, is_little_endian); }
void set_value_in_buffer(size_t byte_index, Value value, ArrayBuffer::Order order, bool is_little_endian = true) override { viewed_array_buffer()->template set_value<T>(byte_index, value, true, order, is_little_endian); }
Value get_modify_set_value_in_buffer(size_t byte_index, Value value, ReadWriteModifyFunction operation, bool is_little_endian = true) override { return viewed_array_buffer()->template get_modify_set_value<T>(byte_index, value, move(operation), is_little_endian); }