LibJS: Consolidate error messages into ErrorTypes.h

Now, exceptions can be thrown with
interpreter.throw_exception<T>(ErrorType:TYPE, "format", "args",
"here").
This commit is contained in:
Matthew Olsson 2020-06-09 22:48:01 -07:00 committed by Andreas Kling
parent 9940a7f6de
commit 78155a6668
Notes: sideshowbarker 2024-07-19 05:43:14 +09:00
63 changed files with 439 additions and 223 deletions

View file

@ -46,21 +46,21 @@ ProxyConstructor::~ProxyConstructor()
Value ProxyConstructor::call(Interpreter& interpreter)
{
return interpreter.throw_exception<TypeError>("Proxy must be called with the \"new\" operator");
return interpreter.throw_exception<TypeError>(ErrorType::ProxyCallWithNew);
}
Value ProxyConstructor::construct(Interpreter& interpreter)
{
if (interpreter.argument_count() < 2)
return interpreter.throw_exception<TypeError>("Proxy requires at least two arguments");
return interpreter.throw_exception<TypeError>(ErrorType::ProxyTwoArguments);
auto target = interpreter.argument(0);
auto handler = interpreter.argument(1);
if (!target.is_object())
return interpreter.throw_exception<TypeError>(String::format("Expected target argument of Proxy constructor to be object, got %s", target.to_string_without_side_effects().characters()));
return interpreter.throw_exception<TypeError>(ErrorType::ProxyConstructorBadType, "target", target.to_string_without_side_effects().characters());
if (!handler.is_object())
return interpreter.throw_exception<TypeError>(String::format("Expected handler argument of Proxy constructor to be object, got %s", handler.to_string_without_side_effects().characters()));
return interpreter.throw_exception<TypeError>(ErrorType::ProxyConstructorBadType, "handler", handler.to_string_without_side_effects().characters());
return ProxyObject::create(global_object(), target.as_object(), handler.as_object());
}