mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-06 03:02:55 +00:00
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:
parent
9940a7f6de
commit
78155a6668
Notes:
sideshowbarker
2024-07-19 05:43:14 +09:00
Author: https://github.com/mattco98
Commit: 78155a6668
Pull-request: https://github.com/SerenityOS/serenity/pull/2538
Issue: https://github.com/SerenityOS/serenity/issues/1842
63 changed files with 439 additions and 223 deletions
|
@ -88,7 +88,7 @@ static Window* impl_from(JS::Interpreter& interpreter)
|
|||
return nullptr;
|
||||
}
|
||||
if (StringView("WindowObject") != this_object->class_name()) {
|
||||
interpreter.throw_exception<JS::TypeError>("That's not a WindowObject, bro.");
|
||||
interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, "WindowObject");
|
||||
return nullptr;
|
||||
}
|
||||
return &static_cast<WindowObject*>(this_object)->impl();
|
||||
|
@ -129,12 +129,12 @@ JS::Value WindowObject::set_interval(JS::Interpreter& interpreter)
|
|||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("setInterval() needs at least one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "setInterval");
|
||||
auto* callback_object = interpreter.argument(0).to_object(interpreter);
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function())
|
||||
return interpreter.throw_exception<JS::TypeError>("Not a function");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
|
||||
i32 interval = 0;
|
||||
if (interpreter.argument_count() >= 2) {
|
||||
|
@ -155,12 +155,12 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter)
|
|||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("setTimeout() needs at least one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "setTimeout");
|
||||
auto* callback_object = interpreter.argument(0).to_object(interpreter);
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function())
|
||||
return interpreter.throw_exception<JS::TypeError>("Not a function");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
|
||||
i32 interval = 0;
|
||||
if (interpreter.argument_count() >= 2) {
|
||||
|
@ -181,12 +181,12 @@ JS::Value WindowObject::request_animation_frame(JS::Interpreter& interpreter)
|
|||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("requestAnimationFrame() needs one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountOne, "requestAnimationFrame");
|
||||
auto* callback_object = interpreter.argument(0).to_object(interpreter);
|
||||
if (!callback_object)
|
||||
return {};
|
||||
if (!callback_object->is_function())
|
||||
return interpreter.throw_exception<JS::TypeError>("Not a function");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
return JS::Value(impl->request_animation_frame(*static_cast<JS::Function*>(callback_object)));
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ JS::Value WindowObject::cancel_animation_frame(JS::Interpreter& interpreter)
|
|||
if (!impl)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("cancelAnimationFrame() needs one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountOne, "cancelAnimationFrame");
|
||||
auto id = interpreter.argument(0).to_i32(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue