From 1bff65c5913f21644ae1c5a7f25064d4995bf6fc Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 2 Dec 2020 09:39:20 +0000 Subject: LibJS: Add ErrorType::ConstructorWithoutNew ...and use it in Proxy::call(), rather than having a specific error type just for that. --- Libraries/LibJS/Runtime/ErrorTypes.h | 2 +- Libraries/LibJS/Runtime/ProxyConstructor.cpp | 3 ++- Libraries/LibJS/Tests/builtins/Proxy/Proxy.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'Libraries/LibJS') diff --git a/Libraries/LibJS/Runtime/ErrorTypes.h b/Libraries/LibJS/Runtime/ErrorTypes.h index 295fc647d3..dd83ac3058 100644 --- a/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Libraries/LibJS/Runtime/ErrorTypes.h @@ -39,6 +39,7 @@ M(ClassConstructorWithoutNew, "Class constructor {} must be called with 'new'") \ M(ClassIsAbstract, "Abstract class {} cannot be constructed directly") \ M(ClassDoesNotExtendAConstructorOrNull, "Class extends value {} is not a constructor or null") \ + M(ConstructorWithoutNew, "{} constructor must be called with 'new'") \ M(Convert, "Cannot convert {} to {}") \ M(ConvertUndefinedToObject, "Cannot convert undefined to object") \ M(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \ @@ -73,7 +74,6 @@ M(ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, \ "Object prototype must not be {} on a super property access") \ M(ObjectPrototypeWrongType, "Prototype must be an object or null") \ - M(ProxyCallWithNew, "Proxy must be called with the 'new' operator") \ M(ProxyConstructBadReturnType, "Proxy handler's construct trap violates invariant: must return " \ "an object") \ M(ProxyConstructorBadType, "Expected {} argument of Proxy constructor to be object, got {}") \ diff --git a/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Libraries/LibJS/Runtime/ProxyConstructor.cpp index 53515ccbe1..f83c5f7727 100644 --- a/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -50,7 +50,8 @@ ProxyConstructor::~ProxyConstructor() Value ProxyConstructor::call() { - vm().throw_exception(global_object(), ErrorType::ProxyCallWithNew); + auto& vm = this->vm(); + vm.throw_exception(global_object(), ErrorType::ConstructorWithoutNew, vm.names.Proxy); return {}; } diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js index 67515ae1ee..9e336c2694 100644 --- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js +++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js @@ -33,5 +33,5 @@ test("constructor requires objects", () => { test("constructor must be invoked with 'new'", () => { expect(() => { Proxy({}, {}); - }).toThrowWithMessage(TypeError, "Proxy must be called with the 'new' operator"); + }).toThrowWithMessage(TypeError, "Proxy constructor must be called with 'new'"); }); -- cgit v1.2.3