From 2d503b20da1c6ba157060303c2e6ebbba31e0c68 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 21 May 2020 00:48:12 +0100 Subject: [PATCH] LibWeb: Embrace Interpreter::{argument_count(), argument(index)} --- .../CanvasRenderingContext2DWrapper.cpp | 49 ++++++++----------- Libraries/LibWeb/Bindings/DocumentWrapper.cpp | 10 ++-- .../LibWeb/Bindings/EventTargetWrapper.cpp | 12 ++--- .../Bindings/HTMLCanvasElementWrapper.cpp | 2 +- Libraries/LibWeb/Bindings/WindowObject.cpp | 24 ++++----- 5 files changed, 42 insertions(+), 55 deletions(-) diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp index eb99184b65d..024e37f3634 100644 --- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp +++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp @@ -90,18 +90,17 @@ JS::Value CanvasRenderingContext2DWrapper::fill_rect(JS::Interpreter& interprete auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() >= 4) { - auto x = arguments[0].to_double(interpreter); + if (interpreter.argument_count() >= 4) { + auto x = interpreter.argument(0).to_double(interpreter); if (interpreter.exception()) return {}; - auto y = arguments[1].to_double(interpreter); + auto y = interpreter.argument(1).to_double(interpreter); if (interpreter.exception()) return {}; - auto width = arguments[2].to_double(interpreter); + auto width = interpreter.argument(2).to_double(interpreter); if (interpreter.exception()) return {}; - auto height = arguments[3].to_double(interpreter); + auto height = interpreter.argument(3).to_double(interpreter); if (interpreter.exception()) return {}; impl->fill_rect(x, y, width, height); @@ -114,19 +113,17 @@ JS::Value CanvasRenderingContext2DWrapper::stroke_rect(JS::Interpreter& interpre auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() >= 4) { - - auto x = arguments[0].to_double(interpreter); + if (interpreter.argument_count() >= 4) { + auto x = interpreter.argument(0).to_double(interpreter); if (interpreter.exception()) return {}; - auto y = arguments[1].to_double(interpreter); + auto y = interpreter.argument(1).to_double(interpreter); if (interpreter.exception()) return {}; - auto width = arguments[2].to_double(interpreter); + auto width = interpreter.argument(2).to_double(interpreter); if (interpreter.exception()) return {}; - auto height = arguments[3].to_double(interpreter); + auto height = interpreter.argument(3).to_double(interpreter); if (interpreter.exception()) return {}; impl->stroke_rect(x, y, width, height); @@ -139,20 +136,18 @@ JS::Value CanvasRenderingContext2DWrapper::draw_image(JS::Interpreter& interpret auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 3) - return interpreter.throw_exception("drawImage() needs more arguments"); - - auto* image_argument = arguments[0].to_object(interpreter); + if (interpreter.argument_count() < 3) + return interpreter.throw_exception("drawImage() needs three arguments"); + auto* image_argument = interpreter.argument(0).to_object(interpreter); if (!image_argument) return {}; if (StringView(image_argument->class_name()) != "HTMLImageElementWrapper") return interpreter.throw_exception(String::format("Image is not an HTMLImageElement, it's an %s", image_argument->class_name())); - auto x = arguments[1].to_double(interpreter); + auto x = interpreter.argument(1).to_double(interpreter); if (interpreter.exception()) return {}; - auto y = arguments[2].to_double(interpreter); + auto y = interpreter.argument(2).to_double(interpreter); if (interpreter.exception()) return {}; impl->draw_image(static_cast(*image_argument).node(), x, y); @@ -164,12 +159,11 @@ JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() >= 2) { - auto sx = arguments[0].to_double(interpreter); + if (interpreter.argument_count() >= 2) { + auto sx = interpreter.argument(0).to_double(interpreter); if (interpreter.exception()) return {}; - auto sy = arguments[1].to_double(interpreter); + auto sy = interpreter.argument(1).to_double(interpreter); if (interpreter.exception()) return {}; impl->scale(sx, sy); @@ -182,12 +176,11 @@ JS::Value CanvasRenderingContext2DWrapper::translate(JS::Interpreter& interprete auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() >= 2) { - auto tx = arguments[0].to_double(interpreter); + if (interpreter.argument_count() >= 2) { + auto tx = interpreter.argument(0).to_double(interpreter); if (interpreter.exception()) return {}; - auto ty = arguments[1].to_double(interpreter); + auto ty = interpreter.argument(1).to_double(interpreter); if (interpreter.exception()) return {}; impl->translate(tx, ty); diff --git a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp index fc47502bc1e..02431720da1 100644 --- a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp +++ b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp @@ -75,10 +75,9 @@ JS::Value DocumentWrapper::get_element_by_id(JS::Interpreter& interpreter) auto* document = document_from(interpreter); if (!document) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.is_empty()) + if (!interpreter.argument_count()) return JS::js_null(); - auto id = arguments[0].to_string(interpreter); + auto id = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; auto* element = document->get_element_by_id(id); @@ -92,10 +91,9 @@ JS::Value DocumentWrapper::query_selector_all(JS::Interpreter& interpreter) auto* document = document_from(interpreter); if (!document) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.is_empty()) + if (!interpreter.argument_count()) return JS::js_null(); - auto selector = arguments[0].to_string(interpreter); + auto selector = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; auto elements = document->query_selector_all(selector); diff --git a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp index 879c03dbb6d..b34dbb4e742 100644 --- a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp +++ b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp @@ -53,15 +53,15 @@ JS::Value EventTargetWrapper::add_event_listener(JS::Interpreter& interpreter) auto* this_object = interpreter.this_value().to_object(interpreter); if (!this_object) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 2) + if (interpreter.argument_count() < 2) return JS::js_undefined(); - auto event_name = arguments[0].to_string(interpreter); + auto event_name = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; - ASSERT(arguments[1].is_object()); - ASSERT(arguments[1].as_object().is_function()); - auto& function = static_cast(const_cast(arguments[1].as_object())); + auto callback = interpreter.argument(1); + ASSERT(callback.is_object()); + ASSERT(callback.as_object().is_function()); + auto& function = callback.as_function(); auto listener = adopt(*new EventListener(JS::make_handle(&function))); static_cast(this_object)->impl().add_event_listener(event_name, move(listener)); return JS::js_undefined(); diff --git a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp index 8f586aa0ed2..8237c5fdc3d 100644 --- a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp +++ b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp @@ -74,7 +74,7 @@ JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - auto context_type = interpreter.call_frame().arguments[0].to_string(interpreter); + auto context_type = interpreter.argument(0).to_string(interpreter); if (interpreter.exception()) return {}; if (context_type != "2d") diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index 659229c46a2..b0a00dac160 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -128,15 +128,14 @@ JS::Value WindowObject::set_interval(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 2) + if (interpreter.argument_count() < 2) return {}; - auto* callback_object = arguments[0].to_object(interpreter); + auto* callback_object = interpreter.argument(0).to_object(interpreter); if (!callback_object) return {}; if (!callback_object->is_function()) return interpreter.throw_exception("Not a function"); - auto interval = arguments[1].to_i32(interpreter); + auto interval = interpreter.argument(1).to_i32(interpreter); if (interpreter.exception()) return {}; impl->set_interval(*static_cast(callback_object), interval); @@ -148,10 +147,9 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 1) + if (!interpreter.argument_count()) return {}; - auto* callback_object = arguments[0].to_object(interpreter); + auto* callback_object = interpreter.argument(0).to_object(interpreter); if (!callback_object) return {}; if (!callback_object->is_function()) @@ -159,7 +157,7 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter) i32 interval = 0; if (interpreter.argument_count() >= 2) { - interval = arguments[1].to_i32(interpreter); + interval = interpreter.argument(1).to_i32(interpreter); if (interpreter.exception()) return {}; } @@ -173,10 +171,9 @@ JS::Value WindowObject::request_animation_frame(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 1) + if (!interpreter.argument_count()) return {}; - auto* callback_object = arguments[0].to_object(interpreter); + auto* callback_object = interpreter.argument(0).to_object(interpreter); if (!callback_object) return {}; if (!callback_object->is_function()) @@ -189,10 +186,9 @@ JS::Value WindowObject::cancel_animation_frame(JS::Interpreter& interpreter) auto* impl = impl_from(interpreter); if (!impl) return {}; - auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 1) + if (!interpreter.argument_count()) return {}; - auto id = arguments[0].to_i32(interpreter); + auto id = interpreter.argument(0).to_i32(interpreter); if (interpreter.exception()) return {}; impl->cancel_animation_frame(id);