mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibJS: Update spec comments testing presence of a field
This is an editorial change in the ECMA-262 spec. See: - https://github.com/tc39/ecma262/commit/497f99a - https://github.com/tc39/ecma262/commit/0b35749
This commit is contained in:
parent
d33fcad87f
commit
cb66474fb5
Notes:
sideshowbarker
2024-07-17 11:24:38 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/cb66474fb5 Pull-request: https://github.com/SerenityOS/serenity/pull/13874 Reviewed-by: https://github.com/IdanHo ✅
4 changed files with 20 additions and 20 deletions
|
@ -284,11 +284,11 @@ bool validate_and_apply_property_descriptor(Object* object, PropertyKey const& p
|
||||||
|
|
||||||
// 5. If current.[[Configurable]] is false, then
|
// 5. If current.[[Configurable]] is false, then
|
||||||
if (!*current->configurable) {
|
if (!*current->configurable) {
|
||||||
// a. If Desc.[[Configurable]] is present and its value is true, return false.
|
// a. If Desc has a [[Configurable]] field and Desc.[[Configurable]] is true, return false.
|
||||||
if (descriptor.configurable.has_value() && *descriptor.configurable)
|
if (descriptor.configurable.has_value() && *descriptor.configurable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// b. If Desc.[[Enumerable]] is present and ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.
|
// b. If Desc has an [[Enumerable]] field and ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.
|
||||||
if (descriptor.enumerable.has_value() && *descriptor.enumerable != *current->enumerable)
|
if (descriptor.enumerable.has_value() && *descriptor.enumerable != *current->enumerable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -298,22 +298,22 @@ bool validate_and_apply_property_descriptor(Object* object, PropertyKey const& p
|
||||||
|
|
||||||
// d. If ! IsAccessorDescriptor(Desc) is true, then
|
// d. If ! IsAccessorDescriptor(Desc) is true, then
|
||||||
if (descriptor.is_accessor_descriptor()) {
|
if (descriptor.is_accessor_descriptor()) {
|
||||||
// i. If Desc.[[Get]] is present and ! SameValue(Desc.[[Get]], current.[[Get]]) is false, return false.
|
// i. If Desc has a [[Get]] field and ! SameValue(Desc.[[Get]], current.[[Get]]) is false, return false.
|
||||||
if (descriptor.get.has_value() && *descriptor.get != *current->get)
|
if (descriptor.get.has_value() && *descriptor.get != *current->get)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// ii. If Desc.[[Set]] is present and ! SameValue(Desc.[[Set]], current.[[Set]]) is false, return false.
|
// ii. If Desc has a [[Set]] field and ! SameValue(Desc.[[Set]], current.[[Set]]) is false, return false.
|
||||||
if (descriptor.set.has_value() && *descriptor.set != *current->set)
|
if (descriptor.set.has_value() && *descriptor.set != *current->set)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// e. Else if current.[[Writable]] is false, then
|
// e. Else if current.[[Writable]] is false, then
|
||||||
// FIXME: `current` is not guaranteed to be a data descriptor at this point and may not have a [[Writable]] field (see https://github.com/tc39/ecma262/issues/2761)
|
// FIXME: `current` is not guaranteed to be a data descriptor at this point and may not have a [[Writable]] field (see https://github.com/tc39/ecma262/issues/2761)
|
||||||
else if (current->is_data_descriptor() && !*current->writable) {
|
else if (current->is_data_descriptor() && !*current->writable) {
|
||||||
// i. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false.
|
// i. If Desc has a [[Writable]] field and Desc.[[Writable]] is true, return false.
|
||||||
if (descriptor.writable.has_value() && *descriptor.writable)
|
if (descriptor.writable.has_value() && *descriptor.writable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// ii. If Desc.[[Value]] is present and ! SameValue(Desc.[[Value]], current.[[Value]]) is false, return false.
|
// ii. If Desc has a [[Value]] field and ! SameValue(Desc.[[Value]], current.[[Value]]) is false, return false.
|
||||||
if (descriptor.value.has_value() && (*descriptor.value != *current->value))
|
if (descriptor.value.has_value() && (*descriptor.value != *current->value))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_define_own_property(PropertyKe
|
||||||
|
|
||||||
// 4. If isMapped is true and IsDataDescriptor(Desc) is true, then
|
// 4. If isMapped is true and IsDataDescriptor(Desc) is true, then
|
||||||
if (is_mapped && descriptor.is_data_descriptor()) {
|
if (is_mapped && descriptor.is_data_descriptor()) {
|
||||||
// a. If Desc.[[Value]] is not present and Desc.[[Writable]] is present and its value is false, then
|
// a. If Desc does not have a [[Value]] field and Desc has a [[Writable]] field, and Desc.[[Writable]] is false, then
|
||||||
if (!descriptor.value.has_value() && descriptor.writable.has_value() && descriptor.writable == false) {
|
if (!descriptor.value.has_value() && descriptor.writable.has_value() && descriptor.writable == false) {
|
||||||
// i. Set newArgDesc to a copy of Desc.
|
// i. Set newArgDesc to a copy of Desc.
|
||||||
new_arg_desc = descriptor;
|
new_arg_desc = descriptor;
|
||||||
|
@ -162,7 +162,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_define_own_property(PropertyKe
|
||||||
// i. Call map.[[Delete]](P).
|
// i. Call map.[[Delete]](P).
|
||||||
MUST(map.internal_delete(property_key));
|
MUST(map.internal_delete(property_key));
|
||||||
} else {
|
} else {
|
||||||
// i. If Desc.[[Value]] is present, then
|
// i. If Desc has a [[Value]] field, then
|
||||||
if (descriptor.value.has_value()) {
|
if (descriptor.value.has_value()) {
|
||||||
// 1. Let setStatus be Set(map, P, Desc.[[Value]], false).
|
// 1. Let setStatus be Set(map, P, Desc.[[Value]], false).
|
||||||
bool set_status = MUST(map.set(property_key, descriptor.value.value(), Object::ShouldThrowExceptions::No));
|
bool set_status = MUST(map.set(property_key, descriptor.value.value(), Object::ShouldThrowExceptions::No));
|
||||||
|
@ -170,7 +170,7 @@ ThrowCompletionOr<bool> ArgumentsObject::internal_define_own_property(PropertyKe
|
||||||
// 2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
|
// 2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
|
||||||
VERIFY(set_status);
|
VERIFY(set_status);
|
||||||
}
|
}
|
||||||
// ii. If Desc.[[Writable]] is present and its value is false, then
|
// ii. If Desc has a [[Writable]] field and Desc.[[Writable]] is false, then
|
||||||
if (descriptor.writable == false) {
|
if (descriptor.writable == false) {
|
||||||
// 1. Call map.[[Delete]](P).
|
// 1. Call map.[[Delete]](P).
|
||||||
MUST(map.internal_delete(property_key));
|
MUST(map.internal_delete(property_key));
|
||||||
|
|
|
@ -56,7 +56,7 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
|
|
||||||
// 1. If Desc.[[Value]] is absent, then
|
// 1. If Desc does not have a [[Value]] field, then
|
||||||
// a. Return OrdinaryDefineOwnProperty(A, "length", Desc).
|
// a. Return OrdinaryDefineOwnProperty(A, "length", Desc).
|
||||||
// 2. Let newLenDesc be a copy of Desc.
|
// 2. Let newLenDesc be a copy of Desc.
|
||||||
// NOTE: Handled by step 16
|
// NOTE: Handled by step 16
|
||||||
|
@ -82,7 +82,7 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
|
||||||
// 12. If oldLenDesc.[[Writable]] is false, return false.
|
// 12. If oldLenDesc.[[Writable]] is false, return false.
|
||||||
// NOTE: Handled by step 16
|
// NOTE: Handled by step 16
|
||||||
|
|
||||||
// 13. If newLenDesc.[[Writable]] is absent or is true, let newWritable be true.
|
// 13. If newLenDesc does not have a [[Writable]] field or newLenDesc.[[Writable]] true, let newWritable be true.
|
||||||
// 14. Else,
|
// 14. Else,
|
||||||
// a. NOTE: Setting the [[Writable]] attribute to false is deferred in case any elements cannot be deleted.
|
// a. NOTE: Setting the [[Writable]] attribute to false is deferred in case any elements cannot be deleted.
|
||||||
// b. Let newWritable be false.
|
// b. Let newWritable be false.
|
||||||
|
@ -97,10 +97,10 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
|
||||||
|
|
||||||
// 10.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ), https://tc39.es/ecma262/#sec-validateandapplypropertydescriptor
|
// 10.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ), https://tc39.es/ecma262/#sec-validateandapplypropertydescriptor
|
||||||
// 5. If current.[[Configurable]] is false, then
|
// 5. If current.[[Configurable]] is false, then
|
||||||
// a. If Desc.[[Configurable]] is present and its value is true, return false.
|
// a. If Desc has a [[Configurable]] field and Desc.[[Configurable]] is true, return false.
|
||||||
if (property_descriptor.configurable.has_value() && *property_descriptor.configurable)
|
if (property_descriptor.configurable.has_value() && *property_descriptor.configurable)
|
||||||
return false;
|
return false;
|
||||||
// b. If Desc.[[Enumerable]] is present and ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.
|
// b. If Desc has an [[Enumerable]] field and ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.
|
||||||
if (property_descriptor.enumerable.has_value() && *property_descriptor.enumerable)
|
if (property_descriptor.enumerable.has_value() && *property_descriptor.enumerable)
|
||||||
return false;
|
return false;
|
||||||
// c. If ! IsGenericDescriptor(Desc) is false and ! SameValue(IsAccessorDescriptor(Desc), IsAccessorDescriptor(current)) is false, return false.
|
// c. If ! IsGenericDescriptor(Desc) is false and ! SameValue(IsAccessorDescriptor(Desc), IsAccessorDescriptor(current)) is false, return false.
|
||||||
|
@ -109,10 +109,10 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
|
||||||
// NOTE: Step d. doesn't apply here.
|
// NOTE: Step d. doesn't apply here.
|
||||||
// e. Else if current.[[Writable]] is false, then
|
// e. Else if current.[[Writable]] is false, then
|
||||||
if (!m_length_writable) {
|
if (!m_length_writable) {
|
||||||
// i. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false.
|
// i. If Desc has a [[Writable]] field and Desc.[[Writable]] is true, return false.
|
||||||
if (property_descriptor.writable.has_value() && *property_descriptor.writable)
|
if (property_descriptor.writable.has_value() && *property_descriptor.writable)
|
||||||
return false;
|
return false;
|
||||||
// ii. If Desc.[[Value]] is present and ! SameValue(Desc.[[Value]], current.[[Value]]) is false, return false.
|
// ii. If Desc has a [[Value]] field and SameValue(Desc.[[Value]], current.[[Value]]) is false, return false.
|
||||||
if (new_length != indexed_properties().array_like_size())
|
if (new_length != indexed_properties().array_like_size())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -18,7 +18,7 @@ bool PropertyDescriptor::is_accessor_descriptor() const
|
||||||
{
|
{
|
||||||
// 1. If Desc is undefined, return false.
|
// 1. If Desc is undefined, return false.
|
||||||
|
|
||||||
// 2. If both Desc.[[Get]] and Desc.[[Set]] are absent, return false.
|
// 2. If Desc does not have a [[Get]] field and Desc does not have a [[Set]] field, return false.
|
||||||
if (!get.has_value() && !set.has_value())
|
if (!get.has_value() && !set.has_value())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ bool PropertyDescriptor::is_data_descriptor() const
|
||||||
{
|
{
|
||||||
// 1. If Desc is undefined, return false.
|
// 1. If Desc is undefined, return false.
|
||||||
|
|
||||||
// 2. If both Desc.[[Value]] and Desc.[[Writable]] are absent, return false.
|
// 2. If Desc does not have a [[Value]] field and Desc does not have a [[Writable]] field, return false.
|
||||||
if (!value.has_value() && !writable.has_value())
|
if (!value.has_value() && !writable.has_value())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -168,9 +168,9 @@ ThrowCompletionOr<PropertyDescriptor> to_property_descriptor(GlobalObject& globa
|
||||||
descriptor.set = setter.is_function() ? &setter.as_function() : nullptr;
|
descriptor.set = setter.is_function() ? &setter.as_function() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 15. If desc.[[Get]] is present or desc.[[Set]] is present, then
|
// 15. If desc has a [[Get]] field or desc has a [[Set]] field, then
|
||||||
if (descriptor.get.has_value() || descriptor.set.has_value()) {
|
if (descriptor.get.has_value() || descriptor.set.has_value()) {
|
||||||
// a. If desc.[[Value]] is present or desc.[[Writable]] is present, throw a TypeError exception.
|
// a. If desc has a [[Value]] field or desc has a [[Writable]] field, throw a TypeError exception.
|
||||||
if (descriptor.value.has_value() || descriptor.writable.has_value())
|
if (descriptor.value.has_value() || descriptor.writable.has_value())
|
||||||
return vm.throw_completion<TypeError>(global_object, ErrorType::AccessorValueOrWritable);
|
return vm.throw_completion<TypeError>(global_object, ErrorType::AccessorValueOrWritable);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue