mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 09:18:52 +00:00
LibJS: Add ObjectPrototype and implement hasOwnProperty()
All Objects will now have ObjectPrototype as their prototype, unless overridden.
This commit is contained in:
parent
f1f14945cf
commit
23b1d97b0d
Notes:
sideshowbarker
2024-07-19 08:17:46 +09:00
Author: https://github.com/awesomekling
Commit: 23b1d97b0d
8 changed files with 114 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/Heap.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/NativeFunction.h>
|
||||
#include <LibJS/Object.h>
|
||||
#include <LibJS/Value.h>
|
||||
|
@ -34,6 +35,7 @@ namespace JS {
|
|||
|
||||
Object::Object()
|
||||
{
|
||||
set_prototype(interpreter().object_prototype());
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
|
@ -44,6 +46,7 @@ Value Object::get(String property_name) const
|
|||
{
|
||||
const Object* object = this;
|
||||
while (object) {
|
||||
dbg() << "Object::get() trying '" << property_name << "' in " << object->class_name();
|
||||
auto value = object->m_properties.get(property_name);
|
||||
if (value.has_value())
|
||||
return value.value();
|
||||
|
@ -71,4 +74,9 @@ void Object::visit_children(Cell::Visitor& visitor)
|
|||
visitor.visit(it.value);
|
||||
}
|
||||
|
||||
bool Object::has_own_property(const String& property_name) const
|
||||
{
|
||||
return m_properties.get(property_name).has_value();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue