diff --git a/Tests/LibWeb/Text/expected/console/console-prototype.txt b/Tests/LibWeb/Text/expected/console/console-prototype.txt new file mode 100644 index 00000000000..9455e4442ee --- /dev/null +++ b/Tests/LibWeb/Text/expected/console/console-prototype.txt @@ -0,0 +1,2 @@ +0 +Prototype of console prototype is Object.prototype diff --git a/Tests/LibWeb/Text/input/console/console-prototype.html b/Tests/LibWeb/Text/input/console/console-prototype.html new file mode 100644 index 00000000000..d1c1dc1bf5e --- /dev/null +++ b/Tests/LibWeb/Text/input/console/console-prototype.html @@ -0,0 +1,15 @@ + + diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 82bb1dbfe99..f1d0bf40d63 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -68,6 +68,7 @@ set(SOURCES Runtime/BooleanPrototype.cpp Runtime/BoundFunction.cpp Runtime/Completion.cpp + Runtime/ConsoleObjectPrototype.cpp Runtime/ConsoleObject.cpp Runtime/DataView.cpp Runtime/DataViewConstructor.cpp diff --git a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp index 468168adf51..fdb965ae4f5 100644 --- a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -8,14 +8,20 @@ #include #include +#include #include namespace JS { JS_DEFINE_ALLOCATOR(ConsoleObject); +static NonnullGCPtr create_console_prototype(Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} + ConsoleObject::ConsoleObject(Realm& realm) - : Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype()) + : Object(ConstructWithPrototypeTag::Tag, create_console_prototype(realm)) { } diff --git a/Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.cpp new file mode 100644 index 00000000000..a403e838340 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024, Gasim Gasimzada + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "ConsoleObjectPrototype.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace JS { + +JS_DEFINE_ALLOCATOR(ConsoleObjectPrototype); + +ConsoleObjectPrototype::ConsoleObjectPrototype(JS::Realm& realm) + : Object(JS::Object::ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype()) +{ +} + +void ConsoleObjectPrototype::initialize(JS::Realm& realm) +{ + Base::initialize(realm); +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.h b/Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.h new file mode 100644 index 00000000000..e1b4a05c1a7 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, Gasim Gasimzada + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace JS { + +class ConsoleObjectPrototype final : public Object { + JS_OBJECT(ConsoleObjectPrototype, Object); + JS_DECLARE_ALLOCATOR(ConsoleObjectPrototype); + +public: + virtual void initialize(JS::Realm&) override; + virtual ~ConsoleObjectPrototype() override = default; + +private: + explicit ConsoleObjectPrototype(JS::Realm&); +}; + +}