LibJS: Set empty prototype for console object
This commit is contained in:
parent
d6303c9da9
commit
4a42c97f4d
Notes:
github-actions[bot]
2024-08-12 16:21:57 +00:00
Author: https://github.com/GasimGasimzada Commit: https://github.com/LadybirdBrowser/ladybird/commit/4a42c97f4d3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1014 Reviewed-by: https://github.com/tcl3 ✅
6 changed files with 87 additions and 1 deletions
2
Tests/LibWeb/Text/expected/console/console-prototype.txt
Normal file
2
Tests/LibWeb/Text/expected/console/console-prototype.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
0
|
||||
Prototype of console prototype is Object.prototype
|
15
Tests/LibWeb/Text/input/console/console-prototype.html
Normal file
15
Tests/LibWeb/Text/input/console/console-prototype.html
Normal 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>
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
37
Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.cpp
Normal file
37
Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.cpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
25
Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.h
Normal file
25
Userland/Libraries/LibJS/Runtime/ConsoleObjectPrototype.h
Normal 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&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue