1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

Ladybird: Add files I forgot to commit :^)

This commit is contained in:
Andreas Kling 2022-07-17 19:37:02 +02:00 committed by Andrew Kaster
parent 79ce12a363
commit 45c6a8c479
2 changed files with 111 additions and 0 deletions

59
Ladybird/ConsoleClient.h Normal file
View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2022, Brandon Scott <xeon.productions@gmail.com>
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#define AK_DONT_REPLACE_STD
#include "ConsoleGlobalObject.h"
#include <AK/WeakPtr.h>
#include <LibJS/Console.h>
#include <LibJS/Forward.h>
#include <LibWeb/Forward.h>
class WebView;
namespace Ladybird {
class ConsoleClient final : public JS::ConsoleClient {
public:
ConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, WebView&);
void handle_input(String const& js_source);
void send_messages(i32 start_index);
private:
virtual void clear() override;
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
WebView& m_view;
WeakPtr<JS::Interpreter> m_interpreter;
JS::Handle<ConsoleGlobalObject> 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<ConsoleOutput> m_message_log;
};
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#define AK_DONT_REPLACE_STD
#include <LibJS/Forward.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GlobalObject.h>
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<Object*> internal_get_prototype_of() const override;
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const override;
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const& name) const override;
virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyKey const& name, JS::PropertyDescriptor const& descriptor) override;
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyKey const& name) const override;
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value) const override;
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& name) override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> 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;
};
}