diff options
author | Linus Groh <mail@linusgroh.de> | 2020-12-02 09:39:20 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-02 12:52:31 +0100 |
commit | 1bff65c5913f21644ae1c5a7f25064d4995bf6fc (patch) | |
tree | 880f053f819459e5b3ec78e2f56cfccd431481c5 /Libraries/LibJS | |
parent | 7fb299fe46f7ff569d24ba9383de06d0ff8d2eea (diff) | |
download | serenity-1bff65c5913f21644ae1c5a7f25064d4995bf6fc.zip |
LibJS: Add ErrorType::ConstructorWithoutNew
...and use it in Proxy::call(), rather than having a specific error
type just for that.
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r-- | Libraries/LibJS/Runtime/ErrorTypes.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/ProxyConstructor.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Proxy/Proxy.js | 2 |
3 files changed, 4 insertions, 3 deletions
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<TypeError>(global_object(), ErrorType::ProxyCallWithNew); + auto& vm = this->vm(); + vm.throw_exception<TypeError>(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'"); }); |