diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-21 00:55:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-21 15:16:48 +0200 |
commit | e3e9749d884813d886d8b9c4fe5417ce88238b1e (patch) | |
tree | ff47fedaff60f04fa324b10d2ddbb166e3fa2e07 /Libraries/LibWeb | |
parent | 2d503b20da1c6ba157060303c2e6ebbba31e0c68 (diff) | |
download | serenity-e3e9749d884813d886d8b9c4fe5417ce88238b1e.zip |
LibWeb: Let various functions throw if not enough arguments
...instead of handing out null / undefined / empty values.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/Bindings/DocumentWrapper.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/EventTargetWrapper.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/WindowObject.cpp | 10 |
3 files changed, 9 insertions, 8 deletions
diff --git a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp index 02431720da..13381d82a7 100644 --- a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp +++ b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp @@ -76,7 +76,7 @@ JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter) if (!document) return {}; if (!interpreter.argument_count()) - return JS::js_null(); + return interpreter.throw_exception<JS::TypeError>("getElementById() needs one argument"); auto id = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; @@ -92,7 +92,7 @@ JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter) if (!document) return {}; if (!interpreter.argument_count()) - return JS::js_null(); + return interpreter.throw_exception<JS::TypeError>("querySelectorAll() needs one argument"); auto selector = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; diff --git a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp index b34dbb4e74..9157e19cb3 100644 --- a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp +++ b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp @@ -27,6 +27,7 @@ #include <AK/FlyString.h> #include <AK/Function.h> #include <LibJS/Interpreter.h> +#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Function.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibWeb/Bindings/EventListenerWrapper.h> @@ -54,7 +55,7 @@ JS::Value EventTargetWrapper::add_event_listener(JS::Interpreter& interpreter) if (!this_object) return {}; if (interpreter.argument_count() < 2) - return JS::js_undefined(); + return interpreter.throw_exception<JS::TypeError>("addEventListener() needs two arguments"); auto event_name = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index b0a00dac16..7f020fc6e3 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -128,8 +128,8 @@ JS::Value WindowObject::set_interval(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - if (interpreter.argument_count() < 2) - return {}; + if (!interpreter.argument_count()) + return interpreter.throw_exception<JS::TypeError>("setInterval() needs at least one argument"); auto* callback_object = interpreter.argument(0).to_object(interpreter); if (!callback_object) return {}; @@ -148,7 +148,7 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter) if (!impl) return {}; if (!interpreter.argument_count()) - return {}; + return interpreter.throw_exception<JS::TypeError>("setTimeout() needs at least one argument"); auto* callback_object = interpreter.argument(0).to_object(interpreter); if (!callback_object) return {}; @@ -172,7 +172,7 @@ JS::Value WindowObject::request_animation_frame(JS::Interpreter& interpreter) if (!impl) return {}; if (!interpreter.argument_count()) - return {}; + return interpreter.throw_exception<JS::TypeError>("requestAnimationFrame() needs one argument"); auto* callback_object = interpreter.argument(0).to_object(interpreter); if (!callback_object) return {}; @@ -187,7 +187,7 @@ JS::Value WindowObject::cancel_animation_frame(JS::Interpreter& interpreter) if (!impl) return {}; if (!interpreter.argument_count()) - return {}; + return interpreter.throw_exception<JS::TypeError>("cancelAnimationFrame() needs one argument"); auto id = interpreter.argument(0).to_i32(interpreter); if (interpreter.exception()) return {}; |