From 893978ea891b99a25bd2f34b43a2d83adc9c6e17 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 26 Jun 2022 13:32:15 +0100 Subject: [PATCH] LibJS: Replace enumeration macro in typed_array_species_create() Use the newly added TypedArrayBase::intrinsic_constructor() instead to get the required constructor from the global object. Also add spec comments while we're here. --- .../LibJS/Runtime/TypedArrayPrototype.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 3ddee6207c..1a616ba434 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -141,24 +141,21 @@ static ThrowCompletionOr typed_array_species_create(GlobalObjec { auto& vm = global_object.vm(); - TypedArrayConstructor* typed_array_default_constructor = nullptr; + // 1. Let defaultConstructor be the intrinsic object listed in column one of Table 72 for exemplar.[[TypedArrayName]]. + auto* default_constructor = (global_object.*exemplar.intrinsic_constructor())(); - // FIXME: This kinda sucks. -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, Type) \ - if (is(exemplar)) \ - typed_array_default_constructor = global_object.snake_name##_constructor(); - JS_ENUMERATE_TYPED_ARRAYS -#undef __JS_ENUMERATE - - VERIFY(typed_array_default_constructor); - - auto* constructor = TRY(species_constructor(global_object, exemplar, *typed_array_default_constructor)); + // 2. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + auto* constructor = TRY(species_constructor(global_object, exemplar, *default_constructor)); + // 3. Let result be ? TypedArrayCreate(constructor, argumentList). auto* result = TRY(typed_array_create(global_object, *constructor, move(arguments))); + // 4. Assert: result has [[TypedArrayName]] and [[ContentType]] internal slots. + // 5. If result.[[ContentType]] ≠ exemplar.[[ContentType]], throw a TypeError exception. if (result->content_type() != exemplar.content_type()) return vm.throw_completion(global_object, ErrorType::TypedArrayContentTypeMismatch, result->class_name(), exemplar.class_name()); + // 6. Return result. return result; }