mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:47:35 +00:00
LibJS: Use the GetPrototypeFromConstructor AO for TypedArrays creation
This commit is contained in:
parent
9cae827f07
commit
56335dab6c
2 changed files with 16 additions and 4 deletions
|
@ -197,6 +197,15 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
}
|
||||
|
||||
#define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
|
||||
ClassName* ClassName::create(GlobalObject& global_object, u32 length, FunctionObject& new_target) \
|
||||
{ \
|
||||
auto& vm = global_object.vm(); \
|
||||
auto* prototype = get_prototype_from_constructor(global_object, new_target, &GlobalObject::snake_name##_prototype); \
|
||||
if (vm.exception()) \
|
||||
return {}; \
|
||||
return global_object.heap().allocate<ClassName>(global_object, length, *prototype); \
|
||||
} \
|
||||
\
|
||||
ClassName* ClassName::create(GlobalObject& global_object, u32 length) \
|
||||
{ \
|
||||
return global_object.heap().allocate<ClassName>(global_object, length, *global_object.snake_name##_prototype()); \
|
||||
|
@ -257,15 +266,17 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
} \
|
||||
\
|
||||
/* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \
|
||||
Value ConstructorName::construct(FunctionObject&) \
|
||||
Value ConstructorName::construct(FunctionObject& new_target) \
|
||||
{ \
|
||||
auto& vm = this->vm(); \
|
||||
if (vm.argument_count() == 0) \
|
||||
return ClassName::create(global_object(), 0); \
|
||||
return ClassName::create(global_object(), 0, new_target); \
|
||||
\
|
||||
auto first_argument = vm.argument(0); \
|
||||
if (first_argument.is_object()) { \
|
||||
auto* typed_array = ClassName::create(global_object(), 0); \
|
||||
auto* typed_array = ClassName::create(global_object(), 0, new_target); \
|
||||
if (vm.exception()) \
|
||||
return {}; \
|
||||
if (first_argument.as_object().is_typed_array()) { \
|
||||
auto& arg_typed_array = static_cast<TypedArrayBase&>(first_argument.as_object()); \
|
||||
initialize_typed_array_from_typed_array(global_object(), *typed_array, arg_typed_array); \
|
||||
|
@ -310,7 +321,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
vm.throw_exception<RangeError>(global_object(), ErrorType::InvalidLength, "typed array"); \
|
||||
return {}; \
|
||||
} \
|
||||
return ClassName::create(global_object(), array_length); \
|
||||
return ClassName::create(global_object(), array_length, new_target); \
|
||||
}
|
||||
|
||||
#undef __JS_ENUMERATE
|
||||
|
|
|
@ -494,6 +494,7 @@ private:
|
|||
\
|
||||
public: \
|
||||
virtual ~ClassName(); \
|
||||
static ClassName* create(GlobalObject&, u32 length, FunctionObject& new_target); \
|
||||
static ClassName* create(GlobalObject&, u32 length); \
|
||||
ClassName(u32 length, Object& prototype); \
|
||||
virtual String element_name() const override; \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue