mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibJS: Add the TypedArray.prototype[Symbol.toString] getter accessor
This commit is contained in:
parent
c5073cb287
commit
2922a6c053
Notes:
sideshowbarker
2024-07-18 12:03:45 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/2922a6c0531 Pull-request: https://github.com/SerenityOS/serenity/pull/8114
|
@ -200,6 +200,11 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
} \
|
||||
ClassName::~ClassName() { } \
|
||||
\
|
||||
String ClassName::element_name() const \
|
||||
{ \
|
||||
return vm().names.ClassName.as_string(); \
|
||||
} \
|
||||
\
|
||||
PrototypeName::PrototypeName(GlobalObject& global_object) \
|
||||
: Object(*global_object.typed_array_prototype()) \
|
||||
{ \
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
void set_viewed_array_buffer(ArrayBuffer* array_buffer) { m_viewed_array_buffer = array_buffer; }
|
||||
|
||||
virtual size_t element_size() const = 0;
|
||||
virtual String element_name() const = 0;
|
||||
|
||||
protected:
|
||||
explicit TypedArrayBase(Object& prototype)
|
||||
|
@ -151,6 +152,7 @@ private:
|
|||
virtual ~ClassName(); \
|
||||
static ClassName* create(GlobalObject&, u32 length); \
|
||||
ClassName(u32 length, Object& prototype); \
|
||||
virtual String element_name() const override; \
|
||||
}; \
|
||||
class PrototypeName final : public Object { \
|
||||
JS_OBJECT(PrototypeName, Object); \
|
||||
|
|
|
@ -32,6 +32,8 @@ void TypedArrayPrototype::initialize(GlobalObject& object)
|
|||
define_native_function(vm.names.findIndex, find_index, 1, attr);
|
||||
define_native_function(vm.names.forEach, for_each, 1, attr);
|
||||
define_native_function(vm.names.some, some, 1, attr);
|
||||
|
||||
define_native_accessor(vm.well_known_symbol_to_string_tag(), to_string_tag_getter, nullptr, Attribute::Configurable);
|
||||
}
|
||||
|
||||
TypedArrayPrototype::~TypedArrayPrototype()
|
||||
|
@ -232,4 +234,16 @@ JS_DEFINE_NATIVE_GETTER(TypedArrayPrototype::byte_offset_getter)
|
|||
return Value(typed_array->byte_offset());
|
||||
}
|
||||
|
||||
// 23.2.3.32 get %TypedArray%.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
|
||||
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::to_string_tag_getter)
|
||||
{
|
||||
auto this_value = vm.this_value(global_object);
|
||||
if (!this_value.is_object())
|
||||
return js_undefined();
|
||||
auto& this_object = this_value.as_object();
|
||||
if (!this_object.is_typed_array())
|
||||
return js_undefined();
|
||||
return js_string(vm, static_cast<TypedArrayBase&>(this_object).element_name());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ private:
|
|||
JS_DECLARE_NATIVE_GETTER(buffer_getter);
|
||||
JS_DECLARE_NATIVE_GETTER(byte_length_getter);
|
||||
JS_DECLARE_NATIVE_GETTER(byte_offset_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string_tag_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(at);
|
||||
JS_DECLARE_NATIVE_FUNCTION(every);
|
||||
JS_DECLARE_NATIVE_FUNCTION(find);
|
||||
|
|
Loading…
Reference in a new issue