mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:47:35 +00:00
LibJS: Add the TypedArray.prototype[Symbol.toString] getter accessor
This commit is contained in:
parent
c5073cb287
commit
2922a6c053
4 changed files with 22 additions and 1 deletions
|
@ -200,6 +200,11 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
||||||
} \
|
} \
|
||||||
ClassName::~ClassName() { } \
|
ClassName::~ClassName() { } \
|
||||||
\
|
\
|
||||||
|
String ClassName::element_name() const \
|
||||||
|
{ \
|
||||||
|
return vm().names.ClassName.as_string(); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
PrototypeName::PrototypeName(GlobalObject& global_object) \
|
PrototypeName::PrototypeName(GlobalObject& global_object) \
|
||||||
: Object(*global_object.typed_array_prototype()) \
|
: 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; }
|
void set_viewed_array_buffer(ArrayBuffer* array_buffer) { m_viewed_array_buffer = array_buffer; }
|
||||||
|
|
||||||
virtual size_t element_size() const = 0;
|
virtual size_t element_size() const = 0;
|
||||||
|
virtual String element_name() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit TypedArrayBase(Object& prototype)
|
explicit TypedArrayBase(Object& prototype)
|
||||||
|
@ -151,6 +152,7 @@ private:
|
||||||
virtual ~ClassName(); \
|
virtual ~ClassName(); \
|
||||||
static ClassName* create(GlobalObject&, u32 length); \
|
static ClassName* create(GlobalObject&, u32 length); \
|
||||||
ClassName(u32 length, Object& prototype); \
|
ClassName(u32 length, Object& prototype); \
|
||||||
|
virtual String element_name() const override; \
|
||||||
}; \
|
}; \
|
||||||
class PrototypeName final : public Object { \
|
class PrototypeName final : public Object { \
|
||||||
JS_OBJECT(PrototypeName, 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.findIndex, find_index, 1, attr);
|
||||||
define_native_function(vm.names.forEach, for_each, 1, attr);
|
define_native_function(vm.names.forEach, for_each, 1, attr);
|
||||||
define_native_function(vm.names.some, some, 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()
|
TypedArrayPrototype::~TypedArrayPrototype()
|
||||||
|
@ -232,4 +234,16 @@ JS_DEFINE_NATIVE_GETTER(TypedArrayPrototype::byte_offset_getter)
|
||||||
return Value(typed_array->byte_offset());
|
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(buffer_getter);
|
||||||
JS_DECLARE_NATIVE_GETTER(byte_length_getter);
|
JS_DECLARE_NATIVE_GETTER(byte_length_getter);
|
||||||
JS_DECLARE_NATIVE_GETTER(byte_offset_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(at);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(every);
|
JS_DECLARE_NATIVE_FUNCTION(every);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(find);
|
JS_DECLARE_NATIVE_FUNCTION(find);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue