mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 18:35:06 +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
63 changed files with 439 additions and 223 deletions
|
@ -137,12 +137,12 @@ JS::Value CanvasRenderingContext2DWrapper::draw_image(JS::Interpreter& interpret
|
|||
if (!impl)
|
||||
return {};
|
||||
if (interpreter.argument_count() < 3)
|
||||
return interpreter.throw_exception<JS::TypeError>("drawImage() needs three arguments");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::DrawImageArgumentCount);
|
||||
auto* image_argument = interpreter.argument(0).to_object(interpreter);
|
||||
if (!image_argument)
|
||||
return {};
|
||||
if (StringView(image_argument->class_name()) != "HTMLImageElementWrapper")
|
||||
return interpreter.throw_exception<JS::TypeError>(String::format("Image is not an HTMLImageElement, it's an %s", image_argument->class_name()));
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::ImageIsAn, image_argument->class_name());
|
||||
|
||||
auto x = interpreter.argument(1).to_double(interpreter);
|
||||
if (interpreter.exception())
|
||||
|
@ -288,10 +288,10 @@ JS::Value CanvasRenderingContext2DWrapper::fill(JS::Interpreter& interpreter)
|
|||
if (winding_name == "evenodd") {
|
||||
winding = Gfx::Painter::WindingRule::EvenOdd;
|
||||
} else if (winding_name != "nonzero") {
|
||||
return interpreter.throw_exception<JS::TypeError>("fill winding rule must be either 'nonzero' or 'evenodd'");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::FillBadWindingRule);
|
||||
}
|
||||
} else {
|
||||
return interpreter.throw_exception<JS::TypeError>("fill called with non-string");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::FillNonString);
|
||||
}
|
||||
} else {
|
||||
// FIXME: Path2D object
|
||||
|
@ -378,7 +378,7 @@ JS::Value CanvasRenderingContext2DWrapper::put_image_data(JS::Interpreter& inter
|
|||
return {};
|
||||
|
||||
if (StringView(image_data_object->class_name()) != "ImageDataWrapper") {
|
||||
return interpreter.throw_exception<JS::TypeError>("putImageData called with non-ImageData");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::PutImageDataBadCall);
|
||||
}
|
||||
|
||||
auto& image_data = static_cast<ImageDataWrapper*>(image_data_object)->impl();
|
||||
|
|
|
@ -66,7 +66,7 @@ static Document* document_from(JS::Interpreter& interpreter)
|
|||
if (!this_object)
|
||||
return {};
|
||||
if (StringView("DocumentWrapper") != this_object->class_name()) {
|
||||
interpreter.throw_exception<JS::TypeError>("That's not a DocumentWrapper, bro.");
|
||||
interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, "DocumentWrapper");
|
||||
return {};
|
||||
}
|
||||
return &static_cast<DocumentWrapper*>(this_object)->node();
|
||||
|
@ -78,7 +78,7 @@ JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter)
|
|||
if (!document)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("getElementById() needs one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountOne, "getElementById");
|
||||
auto id = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
@ -94,7 +94,7 @@ JS::Value DocumentWrapper::query_selector(JS::Interpreter& interpreter)
|
|||
if (!document)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("querySelector() needs one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountOne, "querySelector");
|
||||
auto selector = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
@ -111,7 +111,7 @@ JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter)
|
|||
if (!document)
|
||||
return {};
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("querySelectorAll() needs one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountOne, "querySelectorAll");
|
||||
auto selector = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
|
|
@ -79,7 +79,7 @@ JS::Value ElementWrapper::get_attribute(JS::Interpreter& interpreter)
|
|||
return {};
|
||||
|
||||
if (interpreter.argument_count() < 1)
|
||||
return interpreter.throw_exception<JS::TypeError>("getAttribute() needs one argument");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountOne, "getAttribute");
|
||||
|
||||
auto attribute_name = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
|
@ -99,7 +99,7 @@ JS::Value ElementWrapper::set_attribute(JS::Interpreter& interpreter)
|
|||
return {};
|
||||
|
||||
if (interpreter.argument_count() < 2)
|
||||
return interpreter.throw_exception<JS::TypeError>("setAttribute() needs two arguments");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountMany, "setAttribute", "two");
|
||||
|
||||
auto attribute_name = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
|
|
|
@ -55,7 +55,7 @@ JS::Value EventTargetWrapper::add_event_listener(JS::Interpreter& interpreter)
|
|||
if (!this_object)
|
||||
return {};
|
||||
if (interpreter.argument_count() < 2)
|
||||
return interpreter.throw_exception<JS::TypeError>("addEventListener() needs two arguments");
|
||||
return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::BadArgCountMany, "addEventListener", "two");
|
||||
auto event_name = interpreter.argument(0).to_string(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
|
|
|
@ -61,7 +61,7 @@ static ImageData* impl_from(JS::Interpreter& interpreter)
|
|||
return nullptr;
|
||||
}
|
||||
if (StringView("ImageDataWrapper") != this_object->class_name()) {
|
||||
interpreter.throw_exception<JS::TypeError>("That's not an ImageDataWrapper, bro.");
|
||||
interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotAn, "ImageDataWrapper");
|
||||
return nullptr;
|
||||
}
|
||||
return &static_cast<ImageDataWrapper*>(this_object)->impl();
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -60,7 +60,7 @@ static XMLHttpRequest* impl_from(JS::Interpreter& interpreter)
|
|||
if (!this_object)
|
||||
return nullptr;
|
||||
if (StringView("XMLHttpRequestWrapper") != this_object->class_name()) {
|
||||
interpreter.throw_exception<JS::TypeError>("This is not an XMLHttpRequest object");
|
||||
interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, "XMLHttpRequest");
|
||||
return nullptr;
|
||||
}
|
||||
return &static_cast<XMLHttpRequestWrapper*>(this_object)->impl();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue