1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

Everywhere: Rename JS::PropertyKey variables from property_{name => key}

PropertyKey used to be called PropertyName, but got renamed. Let's
update all the variables of this type as well.
This commit is contained in:
Linus Groh 2022-02-06 15:59:04 +00:00
parent 3e6aaa3520
commit 6f20f49b21
25 changed files with 435 additions and 435 deletions

View file

@ -77,21 +77,21 @@ ThrowCompletionOr<bool> Object::is_extensible() const
// 7.3 Operations on Objects, https://tc39.es/ecma262/#sec-operations-on-objects
// 7.3.2 Get ( O, P ), https://tc39.es/ecma262/#sec-get-o-p
ThrowCompletionOr<Value> Object::get(PropertyKey const& property_name) const
ThrowCompletionOr<Value> Object::get(PropertyKey const& property_key) const
{
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Return ? O.[[Get]](P, O).
return TRY(internal_get(property_name, this));
return TRY(internal_get(property_key, this));
}
// NOTE: 7.3.3 GetV ( V, P ) is implemented as Value::get().
// 7.3.4 Set ( O, P, V, Throw ), https://tc39.es/ecma262/#sec-set-o-p-v-throw
ThrowCompletionOr<bool> Object::set(PropertyKey const& property_name, Value value, ShouldThrowExceptions throw_exceptions)
ThrowCompletionOr<bool> Object::set(PropertyKey const& property_key, Value value, ShouldThrowExceptions throw_exceptions)
{
VERIFY(!value.is_empty());
auto& vm = this->vm();
@ -99,12 +99,12 @@ ThrowCompletionOr<bool> Object::set(PropertyKey const& property_name, Value valu
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Assert: Type(Throw) is Boolean.
// 4. Let success be ? O.[[Set]](P, V, O).
auto success = TRY(internal_set(property_name, value, this));
auto success = TRY(internal_set(property_key, value, this));
// 5. If success is false and Throw is true, throw a TypeError exception.
if (!success && throw_exceptions == ShouldThrowExceptions::Yes) {
@ -117,12 +117,12 @@ ThrowCompletionOr<bool> Object::set(PropertyKey const& property_name, Value valu
}
// 7.3.5 CreateDataProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createdataproperty
ThrowCompletionOr<bool> Object::create_data_property(PropertyKey const& property_name, Value value)
ThrowCompletionOr<bool> Object::create_data_property(PropertyKey const& property_key, Value value)
{
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
auto new_descriptor = PropertyDescriptor {
@ -133,18 +133,18 @@ ThrowCompletionOr<bool> Object::create_data_property(PropertyKey const& property
};
// 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
return internal_define_own_property(property_name, new_descriptor);
return internal_define_own_property(property_key, new_descriptor);
}
// 7.3.6 CreateMethodProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createmethodproperty
ThrowCompletionOr<bool> Object::create_method_property(PropertyKey const& property_name, Value value)
ThrowCompletionOr<bool> Object::create_method_property(PropertyKey const& property_key, Value value)
{
VERIFY(!value.is_empty());
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
auto new_descriptor = PropertyDescriptor {
@ -155,11 +155,11 @@ ThrowCompletionOr<bool> Object::create_method_property(PropertyKey const& proper
};
// 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
return internal_define_own_property(property_name, new_descriptor);
return internal_define_own_property(property_key, new_descriptor);
}
// 7.3.7 CreateDataPropertyOrThrow ( O, P, V ), https://tc39.es/ecma262/#sec-createdatapropertyorthrow
ThrowCompletionOr<bool> Object::create_data_property_or_throw(PropertyKey const& property_name, Value value)
ThrowCompletionOr<bool> Object::create_data_property_or_throw(PropertyKey const& property_key, Value value)
{
VERIFY(!value.is_empty());
auto& vm = this->vm();
@ -167,10 +167,10 @@ ThrowCompletionOr<bool> Object::create_data_property_or_throw(PropertyKey const&
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Let success be ? CreateDataProperty(O, P, V).
auto success = TRY(create_data_property(property_name, value));
auto success = TRY(create_data_property(property_key, value));
// 4. If success is false, throw a TypeError exception.
if (!success) {
@ -183,30 +183,30 @@ ThrowCompletionOr<bool> Object::create_data_property_or_throw(PropertyKey const&
}
// 7.3.8 CreateNonEnumerableDataPropertyOrThrow ( O, P, V ), https://tc39.es/ecma262/#sec-createnonenumerabledatapropertyorthrow
ThrowCompletionOr<bool> Object::create_non_enumerable_data_property_or_throw(PropertyKey const& property_name, Value value)
ThrowCompletionOr<bool> Object::create_non_enumerable_data_property_or_throw(PropertyKey const& property_key, Value value)
{
VERIFY(!value.is_empty());
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 1. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
auto new_description = PropertyDescriptor { .value = value, .writable = true, .enumerable = false, .configurable = true };
// 2. Return ? DefinePropertyOrThrow(O, P, newDesc).
return define_property_or_throw(property_name, new_description);
return define_property_or_throw(property_key, new_description);
}
// 7.3.9 DefinePropertyOrThrow ( O, P, desc ), https://tc39.es/ecma262/#sec-definepropertyorthrow
ThrowCompletionOr<bool> Object::define_property_or_throw(PropertyKey const& property_name, PropertyDescriptor const& property_descriptor)
ThrowCompletionOr<bool> Object::define_property_or_throw(PropertyKey const& property_key, PropertyDescriptor const& property_descriptor)
{
auto& vm = this->vm();
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Let success be ? O.[[DefineOwnProperty]](P, desc).
auto success = TRY(internal_define_own_property(property_name, property_descriptor));
auto success = TRY(internal_define_own_property(property_key, property_descriptor));
// 4. If success is false, throw a TypeError exception.
if (!success) {
@ -219,17 +219,17 @@ ThrowCompletionOr<bool> Object::define_property_or_throw(PropertyKey const& prop
}
// 7.3.10 DeletePropertyOrThrow ( O, P ), https://tc39.es/ecma262/#sec-deletepropertyorthrow
ThrowCompletionOr<bool> Object::delete_property_or_throw(PropertyKey const& property_name)
ThrowCompletionOr<bool> Object::delete_property_or_throw(PropertyKey const& property_key)
{
auto& vm = this->vm();
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Let success be ? O.[[Delete]](P).
auto success = TRY(internal_delete(property_name));
auto success = TRY(internal_delete(property_key));
// 4. If success is false, throw a TypeError exception.
if (!success) {
@ -242,27 +242,27 @@ ThrowCompletionOr<bool> Object::delete_property_or_throw(PropertyKey const& prop
}
// 7.3.12 HasProperty ( O, P ), https://tc39.es/ecma262/#sec-hasproperty
ThrowCompletionOr<bool> Object::has_property(PropertyKey const& property_name) const
ThrowCompletionOr<bool> Object::has_property(PropertyKey const& property_key) const
{
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Return ? O.[[HasProperty]](P).
return internal_has_property(property_name);
return internal_has_property(property_key);
}
// 7.3.13 HasOwnProperty ( O, P ), https://tc39.es/ecma262/#sec-hasownproperty
ThrowCompletionOr<bool> Object::has_own_property(PropertyKey const& property_name) const
ThrowCompletionOr<bool> Object::has_own_property(PropertyKey const& property_key) const
{
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 3. Let desc be ? O.[[GetOwnProperty]](P).
auto descriptor = TRY(internal_get_own_property(property_name));
auto descriptor = TRY(internal_get_own_property(property_key));
// 4. If desc is undefined, return false.
if (!descriptor.has_value())
@ -296,10 +296,10 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
if (level == IntegrityLevel::Sealed) {
// a. For each element k of keys, do
for (auto& key : keys) {
auto property_name = MUST(PropertyKey::from_value(global_object, key));
auto property_key = MUST(PropertyKey::from_value(global_object, key));
// i. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }).
TRY(define_property_or_throw(property_name, { .configurable = false }));
TRY(define_property_or_throw(property_key, { .configurable = false }));
}
}
// 7. Else,
@ -308,10 +308,10 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
// b. For each element k of keys, do
for (auto& key : keys) {
auto property_name = MUST(PropertyKey::from_value(global_object, key));
auto property_key = MUST(PropertyKey::from_value(global_object, key));
// i. Let currentDesc be ? O.[[GetOwnProperty]](k).
auto current_descriptor = TRY(internal_get_own_property(property_name));
auto current_descriptor = TRY(internal_get_own_property(property_key));
// ii. If currentDesc is not undefined, then
if (!current_descriptor.has_value())
@ -331,7 +331,7 @@ ThrowCompletionOr<bool> Object::set_integrity_level(IntegrityLevel level)
}
// 3. Perform ? DefinePropertyOrThrow(O, k, desc).
TRY(define_property_or_throw(property_name, descriptor));
TRY(define_property_or_throw(property_key, descriptor));
}
}
@ -360,10 +360,10 @@ ThrowCompletionOr<bool> Object::test_integrity_level(IntegrityLevel level) const
// 7. For each element k of keys, do
for (auto& key : keys) {
auto property_name = MUST(PropertyKey::from_value(global_object(), key));
auto property_key = MUST(PropertyKey::from_value(global_object(), key));
// a. Let currentDesc be ? O.[[GetOwnProperty]](k).
auto current_descriptor = TRY(internal_get_own_property(property_name));
auto current_descriptor = TRY(internal_get_own_property(property_key));
// b. If currentDesc is not undefined, then
if (!current_descriptor.has_value())
@ -405,10 +405,10 @@ ThrowCompletionOr<MarkedValueList> Object::enumerable_own_property_names(Propert
// a. If Type(key) is String, then
if (!key.is_string())
continue;
auto property_name = MUST(PropertyKey::from_value(global_object, key));
auto property_key = MUST(PropertyKey::from_value(global_object, key));
// i. Let desc be ? O.[[GetOwnProperty]](key).
auto descriptor = TRY(internal_get_own_property(property_name));
auto descriptor = TRY(internal_get_own_property(property_key));
// ii. If desc is not undefined and desc.[[Enumerable]] is true, then
if (descriptor.has_value() && *descriptor->enumerable) {
@ -420,7 +420,7 @@ ThrowCompletionOr<MarkedValueList> Object::enumerable_own_property_names(Propert
// 2. Else,
// a. Let value be ? Get(O, key).
auto value = TRY(get(property_name));
auto value = TRY(get(property_key));
// b. If kind is value, append value to properties.
if (kind == PropertyKind::Value) {
@ -560,8 +560,8 @@ ThrowCompletionOr<void> Object::define_field(Variant<PropertyKey, PrivateName> n
if (initializer)
init_value = TRY(call(global_object(), *initializer, this));
if (auto* property_name_ptr = name.get_pointer<PropertyKey>())
TRY(create_data_property_or_throw(*property_name_ptr, init_value));
if (auto* property_key_ptr = name.get_pointer<PropertyKey>())
TRY(create_data_property_or_throw(*property_key_ptr, init_value));
else
TRY(private_field_add(name.get<PrivateName>(), init_value));
@ -641,13 +641,13 @@ ThrowCompletionOr<bool> Object::internal_prevent_extensions()
}
// 10.1.5 [[GetOwnProperty]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-getownproperty-p
ThrowCompletionOr<Optional<PropertyDescriptor>> Object::internal_get_own_property(PropertyKey const& property_name) const
ThrowCompletionOr<Optional<PropertyDescriptor>> Object::internal_get_own_property(PropertyKey const& property_key) const
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 2. If O does not have an own property with key P, return undefined.
auto maybe_storage_entry = storage_get(property_name);
auto maybe_storage_entry = storage_get(property_key);
if (!maybe_storage_entry.has_value())
return Optional<PropertyDescriptor> {};
@ -687,27 +687,27 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Object::internal_get_own_propert
}
// 10.1.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc
ThrowCompletionOr<bool> Object::internal_define_own_property(PropertyKey const& property_name, PropertyDescriptor const& property_descriptor)
ThrowCompletionOr<bool> Object::internal_define_own_property(PropertyKey const& property_key, PropertyDescriptor const& property_descriptor)
{
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 1. Let current be ? O.[[GetOwnProperty]](P).
auto current = TRY(internal_get_own_property(property_name));
auto current = TRY(internal_get_own_property(property_key));
// 2. Let extensible be ? IsExtensible(O).
auto extensible = TRY(is_extensible());
// 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).
return validate_and_apply_property_descriptor(this, property_name, extensible, property_descriptor, current);
return validate_and_apply_property_descriptor(this, property_key, extensible, property_descriptor, current);
}
// 10.1.7 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p
ThrowCompletionOr<bool> Object::internal_has_property(PropertyKey const& property_name) const
ThrowCompletionOr<bool> Object::internal_has_property(PropertyKey const& property_key) const
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 2. Let hasOwn be ? O.[[GetOwnProperty]](P).
auto has_own = TRY(internal_get_own_property(property_name));
auto has_own = TRY(internal_get_own_property(property_key));
// 3. If hasOwn is not undefined, return true.
if (has_own.has_value())
@ -719,7 +719,7 @@ ThrowCompletionOr<bool> Object::internal_has_property(PropertyKey const& propert
// 5. If parent is not null, then
if (parent) {
// a. Return ? parent.[[HasProperty]](P).
return parent->internal_has_property(property_name);
return parent->internal_has_property(property_key);
}
// 6. Return false.
@ -727,15 +727,15 @@ ThrowCompletionOr<bool> Object::internal_has_property(PropertyKey const& propert
}
// 10.1.8 [[Get]] ( P, Receiver ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver
ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_name, Value receiver) const
ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_key, Value receiver) const
{
VERIFY(!receiver.is_empty());
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 2. Let desc be ? O.[[GetOwnProperty]](P).
auto descriptor = TRY(internal_get_own_property(property_name));
auto descriptor = TRY(internal_get_own_property(property_key));
// 3. If desc is undefined, then
if (!descriptor.has_value()) {
@ -747,7 +747,7 @@ ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_name,
return js_undefined();
// c. Return ? parent.[[Get]](P, Receiver).
return parent->internal_get(property_name, receiver);
return parent->internal_get(property_key, receiver);
}
// 4. If IsDataDescriptor(desc) is true, return desc.[[Value]].
@ -769,26 +769,26 @@ ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_name,
}
// 10.1.9 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver
ThrowCompletionOr<bool> Object::internal_set(PropertyKey const& property_name, Value value, Value receiver)
ThrowCompletionOr<bool> Object::internal_set(PropertyKey const& property_key, Value value, Value receiver)
{
VERIFY(!value.is_empty());
VERIFY(!receiver.is_empty());
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 2. Let ownDesc be ? O.[[GetOwnProperty]](P).
auto own_descriptor = TRY(internal_get_own_property(property_name));
auto own_descriptor = TRY(internal_get_own_property(property_key));
// 3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
return ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor);
return ordinary_set_with_own_descriptor(property_key, value, receiver, own_descriptor);
}
// 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ), https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey const& property_name, Value value, Value receiver, Optional<PropertyDescriptor> own_descriptor)
ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey const& property_key, Value value, Value receiver, Optional<PropertyDescriptor> own_descriptor)
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 2. If ownDesc is undefined, then
if (!own_descriptor.has_value()) {
@ -798,7 +798,7 @@ ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey con
// b. If parent is not null, then
if (parent) {
// i. Return ? parent.[[Set]](P, V, Receiver).
return TRY(parent->internal_set(property_name, value, receiver));
return TRY(parent->internal_set(property_key, value, receiver));
}
// c. Else,
else {
@ -823,7 +823,7 @@ ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey con
return false;
// c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
auto existing_descriptor = TRY(receiver.as_object().internal_get_own_property(property_name));
auto existing_descriptor = TRY(receiver.as_object().internal_get_own_property(property_key));
// d. If existingDescriptor is not undefined, then
if (existing_descriptor.has_value()) {
@ -839,15 +839,15 @@ ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey con
auto value_descriptor = PropertyDescriptor { .value = value };
// iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
return TRY(receiver.as_object().internal_define_own_property(property_name, value_descriptor));
return TRY(receiver.as_object().internal_define_own_property(property_key, value_descriptor));
}
// e. Else,
else {
// i. Assert: Receiver does not currently have a property P.
VERIFY(!receiver.as_object().storage_has(property_name));
VERIFY(!receiver.as_object().storage_has(property_key));
// ii. Return ? CreateDataProperty(Receiver, P, V).
return TRY(receiver.as_object().create_data_property(property_name, value));
return TRY(receiver.as_object().create_data_property(property_key, value));
}
}
@ -869,13 +869,13 @@ ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey con
}
// 10.1.10 [[Delete]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-delete-p
ThrowCompletionOr<bool> Object::internal_delete(PropertyKey const& property_name)
ThrowCompletionOr<bool> Object::internal_delete(PropertyKey const& property_key)
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
// 2. Let desc be ? O.[[GetOwnProperty]](P).
auto descriptor = TRY(internal_get_own_property(property_name));
auto descriptor = TRY(internal_get_own_property(property_key));
// 3. If desc is undefined, return true.
if (!descriptor.has_value())
@ -884,7 +884,7 @@ ThrowCompletionOr<bool> Object::internal_delete(PropertyKey const& property_name
// 4. If desc.[[Configurable]] is true, then
if (*descriptor->configurable) {
// a. Remove the own property with name P from O.
storage_delete(property_name);
storage_delete(property_key);
// b. Return true.
return true;
@ -944,21 +944,21 @@ ThrowCompletionOr<bool> Object::set_immutable_prototype(Object* prototype)
return false;
}
Optional<ValueAndAttributes> Object::storage_get(PropertyKey const& property_name) const
Optional<ValueAndAttributes> Object::storage_get(PropertyKey const& property_key) const
{
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
Value value;
PropertyAttributes attributes;
if (property_name.is_number()) {
auto value_and_attributes = m_indexed_properties.get(property_name.as_number());
if (property_key.is_number()) {
auto value_and_attributes = m_indexed_properties.get(property_key.as_number());
if (!value_and_attributes.has_value())
return {};
value = value_and_attributes->value;
attributes = value_and_attributes->attributes;
} else {
auto metadata = shape().lookup(property_name.to_string_or_symbol());
auto metadata = shape().lookup(property_key.to_string_or_symbol());
if (!metadata.has_value())
return {};
value = m_storage[metadata->offset];
@ -967,28 +967,28 @@ Optional<ValueAndAttributes> Object::storage_get(PropertyKey const& property_nam
return ValueAndAttributes { .value = value, .attributes = attributes };
}
bool Object::storage_has(PropertyKey const& property_name) const
bool Object::storage_has(PropertyKey const& property_key) const
{
VERIFY(property_name.is_valid());
if (property_name.is_number())
return m_indexed_properties.has_index(property_name.as_number());
return shape().lookup(property_name.to_string_or_symbol()).has_value();
VERIFY(property_key.is_valid());
if (property_key.is_number())
return m_indexed_properties.has_index(property_key.as_number());
return shape().lookup(property_key.to_string_or_symbol()).has_value();
}
void Object::storage_set(PropertyKey const& property_name, ValueAndAttributes const& value_and_attributes)
void Object::storage_set(PropertyKey const& property_key, ValueAndAttributes const& value_and_attributes)
{
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
auto [value, attributes] = value_and_attributes;
if (property_name.is_number()) {
auto index = property_name.as_number();
if (property_key.is_number()) {
auto index = property_key.as_number();
m_indexed_properties.put(index, value, attributes);
return;
}
auto property_name_string_or_symbol = property_name.to_string_or_symbol();
auto metadata = shape().lookup(property_name_string_or_symbol);
auto property_key_string_or_symbol = property_key.to_string_or_symbol();
auto metadata = shape().lookup(property_key_string_or_symbol);
if (!metadata.has_value()) {
if (!m_shape->is_unique() && shape().property_count() > 100) {
@ -998,9 +998,9 @@ void Object::storage_set(PropertyKey const& property_name, ValueAndAttributes co
}
if (m_shape->is_unique())
m_shape->add_property_to_unique_shape(property_name_string_or_symbol, attributes);
m_shape->add_property_to_unique_shape(property_key_string_or_symbol, attributes);
else
set_shape(*m_shape->create_put_transition(property_name_string_or_symbol, attributes));
set_shape(*m_shape->create_put_transition(property_key_string_or_symbol, attributes));
m_storage.append(value);
return;
@ -1008,28 +1008,28 @@ void Object::storage_set(PropertyKey const& property_name, ValueAndAttributes co
if (attributes != metadata->attributes) {
if (m_shape->is_unique())
m_shape->reconfigure_property_in_unique_shape(property_name_string_or_symbol, attributes);
m_shape->reconfigure_property_in_unique_shape(property_key_string_or_symbol, attributes);
else
set_shape(*m_shape->create_configure_transition(property_name_string_or_symbol, attributes));
set_shape(*m_shape->create_configure_transition(property_key_string_or_symbol, attributes));
}
m_storage[metadata->offset] = value;
}
void Object::storage_delete(PropertyKey const& property_name)
void Object::storage_delete(PropertyKey const& property_key)
{
VERIFY(property_name.is_valid());
VERIFY(storage_has(property_name));
VERIFY(property_key.is_valid());
VERIFY(storage_has(property_key));
if (property_name.is_number())
return m_indexed_properties.remove(property_name.as_number());
if (property_key.is_number())
return m_indexed_properties.remove(property_key.as_number());
auto metadata = shape().lookup(property_name.to_string_or_symbol());
auto metadata = shape().lookup(property_key.to_string_or_symbol());
VERIFY(metadata.has_value());
ensure_shape_is_unique();
shape().remove_property_from_unique_shape(property_name.to_string_or_symbol(), metadata->offset);
shape().remove_property_from_unique_shape(property_key.to_string_or_symbol(), metadata->offset);
m_storage.remove(metadata->offset);
}
@ -1044,43 +1044,43 @@ void Object::set_prototype(Object* new_prototype)
m_shape = shape.create_prototype_transition(new_prototype);
}
void Object::define_native_accessor(PropertyKey const& property_name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> getter, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> setter, PropertyAttributes attribute)
void Object::define_native_accessor(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> getter, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> setter, PropertyAttributes attribute)
{
auto& vm = this->vm();
String formatted_property_name;
if (property_name.is_number()) {
formatted_property_name = property_name.to_string();
} else if (property_name.is_string()) {
formatted_property_name = property_name.as_string();
String formatted_property_key;
if (property_key.is_number()) {
formatted_property_key = property_key.to_string();
} else if (property_key.is_string()) {
formatted_property_key = property_key.as_string();
} else {
formatted_property_name = String::formatted("[{}]", property_name.as_symbol()->description());
formatted_property_key = String::formatted("[{}]", property_key.as_symbol()->description());
}
FunctionObject* getter_function = nullptr;
if (getter) {
auto name = String::formatted("get {}", formatted_property_name);
auto name = String::formatted("get {}", formatted_property_key);
getter_function = NativeFunction::create(global_object(), name, move(getter));
getter_function->define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
getter_function->define_direct_property(vm.names.name, js_string(vm, name), Attribute::Configurable);
}
FunctionObject* setter_function = nullptr;
if (setter) {
auto name = String::formatted("set {}", formatted_property_name);
auto name = String::formatted("set {}", formatted_property_key);
setter_function = NativeFunction::create(global_object(), name, move(setter));
setter_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
setter_function->define_direct_property(vm.names.name, js_string(vm, name), Attribute::Configurable);
}
return define_direct_accessor(property_name, getter_function, setter_function, attribute);
return define_direct_accessor(property_key, getter_function, setter_function, attribute);
}
void Object::define_direct_accessor(PropertyKey const& property_name, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes)
void Object::define_direct_accessor(PropertyKey const& property_key, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes)
{
VERIFY(property_name.is_valid());
VERIFY(property_key.is_valid());
auto existing_property = storage_get(property_name).value_or({}).value;
auto existing_property = storage_get(property_key).value_or({}).value;
auto* accessor = existing_property.is_accessor() ? &existing_property.as_accessor() : nullptr;
if (!accessor) {
accessor = Accessor::create(vm(), getter, setter);
define_direct_property(property_name, accessor, attributes);
define_direct_property(property_key, accessor, attributes);
} else {
if (getter)
accessor->set_getter(getter);
@ -1098,11 +1098,11 @@ void Object::ensure_shape_is_unique()
}
// Simple side-effect free property lookup, following the prototype chain. Non-standard.
Value Object::get_without_side_effects(const PropertyKey& property_name) const
Value Object::get_without_side_effects(const PropertyKey& property_key) const
{
auto* object = this;
while (object) {
auto value_and_attributes = object->storage_get(property_name);
auto value_and_attributes = object->storage_get(property_key);
if (value_and_attributes.has_value())
return value_and_attributes->value;
object = object->prototype();
@ -1110,19 +1110,19 @@ Value Object::get_without_side_effects(const PropertyKey& property_name) const
return {};
}
void Object::define_native_function(PropertyKey const& property_name, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)
void Object::define_native_function(PropertyKey const& property_key, Function<ThrowCompletionOr<Value>(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)
{
auto& vm = this->vm();
String function_name;
if (property_name.is_string()) {
function_name = property_name.as_string();
if (property_key.is_string()) {
function_name = property_key.as_string();
} else {
function_name = String::formatted("[{}]", property_name.as_symbol()->description());
function_name = String::formatted("[{}]", property_key.as_symbol()->description());
}
auto* function = NativeFunction::create(global_object(), function_name, move(native_function));
function->define_direct_property(vm.names.length, Value(length), Attribute::Configurable);
function->define_direct_property(vm.names.name, js_string(vm, function_name), Attribute::Configurable);
define_direct_property(property_name, function, attribute);
define_direct_property(property_key, function, attribute);
}
// 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties
@ -1148,21 +1148,21 @@ ThrowCompletionOr<Object*> Object::define_properties(Value properties)
// 5. For each element nextKey of keys, do
for (auto& next_key : keys) {
auto property_name = MUST(PropertyKey::from_value(global_object, next_key));
auto property_key = MUST(PropertyKey::from_value(global_object, next_key));
// a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
auto property_descriptor = TRY(props->internal_get_own_property(property_name));
auto property_descriptor = TRY(props->internal_get_own_property(property_key));
// b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
if (property_descriptor.has_value() && *property_descriptor->enumerable) {
// i. Let descObj be ? Get(props, nextKey).
auto descriptor_object = TRY(props->get(property_name));
auto descriptor_object = TRY(props->get(property_key));
// ii. Let desc be ? ToPropertyDescriptor(descObj).
auto descriptor = TRY(to_property_descriptor(global_object, descriptor_object));
// iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
descriptors.append({ property_name, descriptor });
descriptors.append({ property_key, descriptor });
}
}