mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
LibJS: Expose BYTES_PER_ELEMENT on each TypedArray
This commit is contained in:
parent
7d12f49e74
commit
6f1688279a
2 changed files with 20 additions and 0 deletions
|
@ -194,6 +194,8 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
||||||
PrototypeName::PrototypeName(GlobalObject& global_object) \
|
PrototypeName::PrototypeName(GlobalObject& global_object) \
|
||||||
: Object(*global_object.typed_array_prototype()) \
|
: Object(*global_object.typed_array_prototype()) \
|
||||||
{ \
|
{ \
|
||||||
|
auto& vm = this->vm(); \
|
||||||
|
define_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \
|
||||||
} \
|
} \
|
||||||
PrototypeName::~PrototypeName() { } \
|
PrototypeName::~PrototypeName() { } \
|
||||||
\
|
\
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Update when more typed arrays get added
|
||||||
|
const TYPED_ARRAYS = [
|
||||||
|
{ array: Uint8Array, expected: 1 },
|
||||||
|
{ array: Uint16Array, expected: 2 },
|
||||||
|
{ array: Uint32Array, expected: 4 },
|
||||||
|
{ array: Int8Array, expected: 1 },
|
||||||
|
{ array: Int16Array, expected: 2 },
|
||||||
|
{ array: Int32Array, expected: 4 },
|
||||||
|
{ array: Float32Array, expected: 4 },
|
||||||
|
{ array: Float64Array, expected: 8 },
|
||||||
|
];
|
||||||
|
|
||||||
|
test("basic functionality", () => {
|
||||||
|
TYPED_ARRAYS.forEach(T => {
|
||||||
|
const typedArray = new T.array();
|
||||||
|
expect(typedArray.BYTES_PER_ELEMENT).toBe(T.expected);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue