diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 5089300acc..34ee9e91ef 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -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; diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index dfcc2ea93d..c8f36eb3c2 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/Libraries/LibJS/Runtime/Object.h @@ -96,7 +96,9 @@ public: 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,