1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 05:27:35 +00:00

LibJS: Oops, "instanceof" was backwards!

Fix the "instanceof" operator to check if the constructor's prototype
property occurs anywhere in the prototype chain of the instance object.

This patch also adds Object.setPrototypeOf() to make it possible to
create a test for this bug.

Thanks to DexesTTP for pointing this out! :^)
This commit is contained in:
Andreas Kling 2020-03-28 19:48:12 +01:00
parent e5ebdb9bca
commit 82ca7ae1f8
5 changed files with 53 additions and 17 deletions

View file

@ -44,6 +44,15 @@ Object::~Object()
{
}
bool Object::has_prototype(const Object* prototype) const
{
for (auto* object = m_prototype; object; object = object->prototype()) {
if (object == prototype)
return true;
}
return false;
}
Optional<Value> Object::get_own_property(const Object& this_object, const FlyString& property_name) const
{
auto value_here = m_properties.get(property_name);