1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:57:44 +00:00

LibJS: Expose TypedArray.prototype.buffer

This commit is contained in:
Luke 2021-05-21 21:26:18 +01:00 committed by Linus Groh
parent 6f1688279a
commit 8004a2dc77
4 changed files with 45 additions and 0 deletions

View file

@ -57,6 +57,7 @@ namespace JS {
P(atan2) \
P(atanh) \
P(bind) \
P(buffer) \
P(byteLength) \
P(call) \
P(callee) \

View file

@ -23,6 +23,7 @@ void TypedArrayPrototype::initialize(GlobalObject& object)
// FIXME: This should be an accessor property
define_native_property(vm.names.length, length_getter, nullptr, Attribute::Configurable);
define_native_property(vm.names.buffer, buffer_getter, nullptr, Attribute::Configurable);
define_native_function(vm.names.at, at, 1, attr);
}
@ -73,4 +74,15 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::at)
return typed_array->get(index.value());
}
// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.buffer
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::buffer_getter)
{
auto typed_array = typed_array_from(vm, global_object);
if (!typed_array)
return {};
auto* array_buffer = typed_array->viewed_array_buffer();
VERIFY(array_buffer);
return Value(array_buffer);
}
}

View file

@ -20,6 +20,7 @@ public:
private:
JS_DECLARE_NATIVE_GETTER(length_getter);
JS_DECLARE_NATIVE_GETTER(buffer_getter);
JS_DECLARE_NATIVE_FUNCTION(at);
};