ladybird/Userland/Libraries/LibJS/Runtime/PropertyAttributes.cpp
davidot 733e8472fa LibJS: Make put_own_property_by_index closer to spec
Most of the code is taken from put_own_property however the attributes
  need to be handled slightly differently it seems
2021-06-22 20:49:28 +01:00

51 lines
1.1 KiB
C++

/*
* Copyright (c) 2021, David Tuin <david.tuin@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "PropertyAttributes.h"
namespace JS {
PropertyAttributes PropertyAttributes::overwrite(PropertyAttributes attr) const
{
PropertyAttributes combined = m_bits;
if (attr.has_configurable()) {
if (attr.is_configurable()) {
combined.set_configurable();
} else {
combined.m_bits &= ~Attribute::Configurable;
}
combined.set_has_configurable();
}
if (attr.has_enumerable()) {
if (attr.is_enumerable()) {
combined.set_enumerable();
} else {
combined.m_bits &= ~Attribute::Enumerable;
}
combined.set_has_configurable();
}
if (attr.has_writable()) {
if (attr.is_writable()) {
combined.set_writable();
} else {
combined.m_bits &= ~Attribute::Writable;
}
combined.set_has_writable();
}
if (attr.has_getter()) {
combined.set_has_getter();
}
if (attr.has_setter()) {
combined.set_has_setter();
}
return combined;
}
}