summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-07-05 02:40:15 +0300
committerLinus Groh <mail@linusgroh.de>2021-07-05 12:16:24 +0100
commit56335dab6c4639065183524a3432dcf334fa5c7e (patch)
tree4e4a253a606d8bbdff8e5e4d9851256378ee4a9f /Userland/Libraries/LibJS
parent9cae827f0797a48e916d697664b1e3323e5f9966 (diff)
downloadserenity-56335dab6c4639065183524a3432dcf334fa5c7e.zip
LibJS: Use the GetPrototypeFromConstructor AO for TypedArrays creation
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.cpp19
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
index efd5a145e7..5a2a836aee 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
@@ -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
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h
index c0db745a3e..d3bdb90690 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.h
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h
@@ -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; \