diff --git a/Ladybird/ConsoleClient.h b/Ladybird/ConsoleClient.h new file mode 100644 index 0000000000..54d32a2173 --- /dev/null +++ b/Ladybird/ConsoleClient.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022, Brandon Scott + * Copyright (c) 2020, Hunter Salyer + * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#define AK_DONT_REPLACE_STD + +#include "ConsoleGlobalObject.h" +#include +#include +#include +#include + +class WebView; + +namespace Ladybird { + +class ConsoleClient final : public JS::ConsoleClient { +public: + ConsoleClient(JS::Console&, WeakPtr, WebView&); + + void handle_input(String const& js_source); + void send_messages(i32 start_index); + +private: + virtual void clear() override; + virtual JS::ThrowCompletionOr printer(JS::Console::LogLevel log_level, PrinterArguments) override; + + WebView& m_view; + + WeakPtr m_interpreter; + JS::Handle m_console_global_object; + + void clear_output(); + void print_html(String const& line); + void begin_group(String const& label, bool start_expanded); + virtual void end_group() override; + + struct ConsoleOutput { + enum class Type { + HTML, + Clear, + BeginGroup, + BeginGroupCollapsed, + EndGroup, + }; + Type type; + String data; + }; + Vector m_message_log; +}; + +} diff --git a/Ladybird/ConsoleGlobalObject.h b/Ladybird/ConsoleGlobalObject.h new file mode 100644 index 0000000000..b289b4164f --- /dev/null +++ b/Ladybird/ConsoleGlobalObject.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#define AK_DONT_REPLACE_STD + +#include +#include +#include + +namespace Web::Bindings { +class WindowObject; +} + +namespace Ladybird { + +class ConsoleGlobalObject final : public JS::GlobalObject { + JS_OBJECT(ConsoleGlobalObject, JS::GlobalObject); + +public: + ConsoleGlobalObject(Web::Bindings::WindowObject&); + virtual ~ConsoleGlobalObject() override = default; + + virtual JS::ThrowCompletionOr internal_get_prototype_of() const override; + virtual JS::ThrowCompletionOr internal_set_prototype_of(Object* prototype) override; + virtual JS::ThrowCompletionOr internal_is_extensible() const override; + virtual JS::ThrowCompletionOr internal_prevent_extensions() override; + virtual JS::ThrowCompletionOr> internal_get_own_property(JS::PropertyKey const& name) const override; + virtual JS::ThrowCompletionOr internal_define_own_property(JS::PropertyKey const& name, JS::PropertyDescriptor const& descriptor) override; + virtual JS::ThrowCompletionOr internal_has_property(JS::PropertyKey const& name) const override; + virtual JS::ThrowCompletionOr internal_get(JS::PropertyKey const&, JS::Value) const override; + virtual JS::ThrowCompletionOr internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override; + virtual JS::ThrowCompletionOr internal_delete(JS::PropertyKey const& name) override; + virtual JS::ThrowCompletionOr> internal_own_property_keys() const override; + + virtual void initialize_global_object() override; + +private: + virtual void visit_edges(Visitor&) override; + + // Because $0 is not a nice C++ function name + JS_DECLARE_NATIVE_FUNCTION(inspected_node_getter); + + Web::Bindings::WindowObject* m_window_object; +}; + +}