Skip to content

Commit

Permalink
LibJS: Add Object::has_property()
Browse files Browse the repository at this point in the history
Like Object::has_own_property() but going down the prototype chain.
  • Loading branch information
linusg authored and awesomekling committed May 1, 2020
1 parent 4cdd802 commit 62671be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Libraries/LibJS/Runtime/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ void Object::visit_children(Cell::Visitor& visitor)
visitor.visit(value);
}

bool Object::has_property(const FlyString& property_name) const
{
const Object* object = this;
while (object) {
if (object->has_own_property(property_name))
return true;
object = object->prototype();
}
return false;
}

bool Object::has_own_property(const FlyString& property_name) const
{
bool ok;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibJS/Runtime/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class Object : public Cell {
void set_prototype(Object*);
bool has_prototype(const Object* prototype) const;

bool has_property(const FlyString& property_name) const;
bool has_own_property(const FlyString& property_name) const;

enum class PreferredType {
Default,
String,
Expand Down

0 comments on commit 62671be

Please sign in to comment.