LibJS: Set empty prototype for console object

This commit is contained in:
Gasim Gasimzada 2024-08-08 20:21:06 +02:00 committed by Tim Ledbetter
parent d6303c9da9
commit 4a42c97f4d
Notes: github-actions[bot] 2024-08-12 16:21:57 +00:00
6 changed files with 87 additions and 1 deletions

View file

@ -0,0 +1,2 @@
0
Prototype of console prototype is Object.prototype

View file

@ -0,0 +1,15 @@
<script src="../include.js"></script>
<script>
test(() => {
const p1 = Object.getPrototypeOf(console)
const p2 = Object.getPrototypeOf(p1)
println(Object.getOwnPropertyNames(p1).length)
if (p2 == Object.prototype) {
println("Prototype of console prototype is Object.prototype")
} else {
println("Prototype of console prototype is NOT Object.prototype")
}
});
</script>

View file

@ -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

View file

@ -8,14 +8,20 @@
#include <LibJS/Console.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibJS/Runtime/ConsoleObjectPrototype.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS {
JS_DEFINE_ALLOCATOR(ConsoleObject);
static NonnullGCPtr<ConsoleObjectPrototype> create_console_prototype(Realm& realm)
{
return realm.heap().allocate<ConsoleObjectPrototype>(realm, realm);
}
ConsoleObject::ConsoleObject(Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, create_console_prototype(realm))
{
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024, Gasim Gasimzada <gasim@gasimzada.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ConsoleObjectPrototype.h"
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Accessor.h>
#include <LibJS/Runtime/BooleanObject.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Date.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/NumberObject.h>
#include <LibJS/Runtime/ObjectPrototype.h>
#include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/StringObject.h>
#include <LibJS/Runtime/Value.h>
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);
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2024, Gasim Gasimzada <gasim@gasimzada.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Object.h>
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&);
};
}