diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h index e20fccce48..a89d12157f 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h @@ -136,7 +136,6 @@ M(ReferenceUnresolvable, "Unresolvable reference") \ M(ReflectArgumentMustBeAFunction, "First argument of Reflect.{}() must be a function") \ M(ReflectArgumentMustBeAnObject, "First argument of Reflect.{}() must be an object") \ - M(ReflectBadArgumentsList, "Arguments list must be an object") \ M(ReflectBadNewTarget, "Optional third argument of Reflect.construct() must be a constructor") \ M(ReflectBadDescriptorArgument, "Descriptor argument is not an object") \ M(RegExpCompileError, "RegExp compile error: {}") \ diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index 704ca31f2e..04d17be774 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -36,25 +36,6 @@ static Function* get_target_function_from(GlobalObject& global_object, const Str return &target.as_function(); } -static void prepare_arguments_list(GlobalObject& global_object, Value value, MarkedValueList& arguments) -{ - auto& vm = global_object.vm(); - if (!value.is_object()) { - vm.throw_exception(global_object, ErrorType::ReflectBadArgumentsList); - return; - } - auto& arguments_list = value.as_object(); - auto length = length_of_array_like(global_object, arguments_list); - if (vm.exception()) - return; - for (size_t i = 0; i < length; ++i) { - auto element = arguments_list.get(String::number(i)); - if (vm.exception()) - return; - arguments.append(element.value_or(js_undefined())); - } -} - ReflectObject::ReflectObject(GlobalObject& global_object) : Object(*global_object.object_prototype()) { @@ -91,8 +72,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::apply) if (!target) return {}; auto this_arg = vm.argument(1); - MarkedValueList arguments(vm.heap()); - prepare_arguments_list(global_object, vm.argument(2), arguments); + auto arguments = create_list_from_array_like(global_object, vm.argument(2)); if (vm.exception()) return {}; return vm.call(*target, this_arg, move(arguments)); @@ -103,8 +83,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::construct) auto* target = get_target_function_from(global_object, "construct"); if (!target) return {}; - MarkedValueList arguments(vm.heap()); - prepare_arguments_list(global_object, vm.argument(1), arguments); + auto arguments = create_list_from_array_like(global_object, vm.argument(1)); if (vm.exception()) return {}; auto* new_target = target; diff --git a/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js b/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js index 7e6a67d16d..504a95bba0 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.apply.js @@ -18,7 +18,7 @@ describe("errors", () => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { expect(() => { Reflect.apply(() => {}, undefined, value); - }).toThrowWithMessage(TypeError, "Arguments list must be an object"); + }).toThrowWithMessage(TypeError, `${value} is not an object`); }); }); }); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js b/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js index a14a016ee0..ddd4bd112d 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Reflect/Reflect.construct.js @@ -18,7 +18,7 @@ describe("errors", () => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { expect(() => { Reflect.construct(() => {}, value); - }).toThrowWithMessage(TypeError, "Arguments list must be an object"); + }).toThrowWithMessage(TypeError, `${value} is not an object`); }); });