From e39dd65cf0309a2d505d5bbe1270730cc812ec2e Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 8 Jun 2021 21:46:45 +0100 Subject: [PATCH] LibJS: Remove Proxy() argument count check Let's just treat missing arguments as undefined and throw with 'target/handler must be object' - this is more JavaScript-y. --- Userland/Libraries/LibJS/Runtime/ErrorTypes.h | 1 - Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp | 5 ----- Userland/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js | 10 ++++++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h index e353ae36ef..e20fccce48 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h @@ -128,7 +128,6 @@ M(ProxySetPrototypeOfNonExtensible, "Proxy handler's setPrototypeOf trap violates " \ "invariant: the argument must match the prototype of the target if the " \ "target is non-extensible") \ - M(ProxyTwoArguments, "Proxy constructor requires at least two arguments") \ M(ReduceNoInitial, "Reduce of empty array with no initial value") \ M(ReferenceNullishDeleteProperty, "Cannot delete property '{}' of {}") \ M(ReferenceNullishGetProperty, "Cannot get property '{}' of {}") \ diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp index f0e53ca337..7c8b17e704 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -38,11 +38,6 @@ Value ProxyConstructor::call() Value ProxyConstructor::construct(Function&) { auto& vm = this->vm(); - if (vm.argument_count() < 2) { - vm.throw_exception(global_object(), ErrorType::ProxyTwoArguments); - return {}; - } - auto target = vm.argument(0); auto handler = vm.argument(1); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js b/Userland/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js index 9e336c2694..0582db348e 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js @@ -7,11 +7,17 @@ test("constructs properly", () => { test("constructor argument count", () => { expect(() => { new Proxy(); - }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments"); + }).toThrowWithMessage( + TypeError, + "Expected target argument of Proxy constructor to be object, got undefined" + ); expect(() => { new Proxy({}); - }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments"); + }).toThrowWithMessage( + TypeError, + "Expected handler argument of Proxy constructor to be object, got undefined" + ); }); test("constructor requires objects", () => {