1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

LibJS: Add ErrorType::ConstructorWithoutNew

...and use it in Proxy::call(), rather than having a specific error
type just for that.
This commit is contained in:
Linus Groh 2020-12-02 09:39:20 +00:00 committed by Andreas Kling
parent 7fb299fe46
commit 1bff65c591
3 changed files with 4 additions and 3 deletions

View file

@ -39,6 +39,7 @@
M(ClassConstructorWithoutNew, "Class constructor {} must be called with 'new'") \ M(ClassConstructorWithoutNew, "Class constructor {} must be called with 'new'") \
M(ClassIsAbstract, "Abstract class {} cannot be constructed directly") \ M(ClassIsAbstract, "Abstract class {} cannot be constructed directly") \
M(ClassDoesNotExtendAConstructorOrNull, "Class extends value {} is not a constructor or null") \ 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(Convert, "Cannot convert {} to {}") \
M(ConvertUndefinedToObject, "Cannot convert undefined to object") \ M(ConvertUndefinedToObject, "Cannot convert undefined to object") \
M(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \ M(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \
@ -73,7 +74,6 @@
M(ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, \ M(ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, \
"Object prototype must not be {} on a super property access") \ "Object prototype must not be {} on a super property access") \
M(ObjectPrototypeWrongType, "Prototype must be an object or null") \ 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 " \ M(ProxyConstructBadReturnType, "Proxy handler's construct trap violates invariant: must return " \
"an object") \ "an object") \
M(ProxyConstructorBadType, "Expected {} argument of Proxy constructor to be object, got {}") \ M(ProxyConstructorBadType, "Expected {} argument of Proxy constructor to be object, got {}") \

View file

@ -50,7 +50,8 @@ ProxyConstructor::~ProxyConstructor()
Value ProxyConstructor::call() 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 {}; return {};
} }

View file

@ -33,5 +33,5 @@ test("constructor requires objects", () => {
test("constructor must be invoked with 'new'", () => { test("constructor must be invoked with 'new'", () => {
expect(() => { expect(() => {
Proxy({}, {}); Proxy({}, {});
}).toThrowWithMessage(TypeError, "Proxy must be called with the 'new' operator"); }).toThrowWithMessage(TypeError, "Proxy constructor must be called with 'new'");
}); });