1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:27:43 +00:00

LibJS: Convert ordinary_set_with_own_descriptor() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-03 19:57:29 +01:00
parent 3b59a4577d
commit 2f42675ebd
3 changed files with 10 additions and 18 deletions

View file

@ -2064,10 +2064,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_set(JS::PropertyName const& p
// 3. Perform ? OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc). // 3. Perform ? OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
// NOTE: The spec says "perform" instead of "return", meaning nothing will be returned on this path according to the spec, which isn't possible to do. // NOTE: The spec says "perform" instead of "return", meaning nothing will be returned on this path according to the spec, which isn't possible to do.
// Let's treat it as though it says "return" instead of "perform". // Let's treat it as though it says "return" instead of "perform".
auto result = ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor); return ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor);
if (auto* exception = vm.exception())
return JS::throw_completion(exception->value());
return result;
} }
)~~~"); )~~~");

View file

@ -686,14 +686,11 @@ ThrowCompletionOr<bool> Object::internal_set(PropertyName const& property_name,
auto own_descriptor = TRY(internal_get_own_property(property_name)); auto own_descriptor = TRY(internal_get_own_property(property_name));
// 3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc). // 3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
auto success = ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor); return ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
return success;
} }
// 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ), https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor // 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ), https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name, Value value, Value receiver, Optional<PropertyDescriptor> own_descriptor) ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyName const& property_name, Value value, Value receiver, Optional<PropertyDescriptor> own_descriptor)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
@ -703,12 +700,12 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
// 2. If ownDesc is undefined, then // 2. If ownDesc is undefined, then
if (!own_descriptor.has_value()) { if (!own_descriptor.has_value()) {
// a. Let parent be ? O.[[GetPrototypeOf]](). // a. Let parent be ? O.[[GetPrototypeOf]]().
auto* parent = TRY_OR_DISCARD(internal_get_prototype_of()); auto* parent = TRY(internal_get_prototype_of());
// b. If parent is not null, then // b. If parent is not null, then
if (parent) { if (parent) {
// i. Return ? parent.[[Set]](P, V, Receiver). // i. Return ? parent.[[Set]](P, V, Receiver).
return TRY_OR_DISCARD(parent->internal_set(property_name, value, receiver)); return TRY(parent->internal_set(property_name, value, receiver));
} }
// c. Else, // c. Else,
else { else {
@ -733,7 +730,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
return false; return false;
// c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). // c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
auto existing_descriptor = TRY_OR_DISCARD(receiver.as_object().internal_get_own_property(property_name)); auto existing_descriptor = TRY(receiver.as_object().internal_get_own_property(property_name));
// d. If existingDescriptor is not undefined, then // d. If existingDescriptor is not undefined, then
if (existing_descriptor.has_value()) { if (existing_descriptor.has_value()) {
@ -749,7 +746,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
auto value_descriptor = PropertyDescriptor { .value = value }; auto value_descriptor = PropertyDescriptor { .value = value };
// iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). // iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
return TRY_OR_DISCARD(receiver.as_object().internal_define_own_property(property_name, value_descriptor)); return TRY(receiver.as_object().internal_define_own_property(property_name, value_descriptor));
} }
// e. Else, // e. Else,
else { else {
@ -757,7 +754,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
VERIFY(!receiver.as_object().storage_has(property_name)); VERIFY(!receiver.as_object().storage_has(property_name));
// ii. Return ? CreateDataProperty(Receiver, P, V). // ii. Return ? CreateDataProperty(Receiver, P, V).
return TRY_OR_DISCARD(receiver.as_object().create_data_property(property_name, value)); return TRY(receiver.as_object().create_data_property(property_name, value));
} }
} }
@ -772,9 +769,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
return false; return false;
// 7. Perform ? Call(setter, Receiver, « V »). // 7. Perform ? Call(setter, Receiver, « V »).
(void)vm.call(*setter, receiver, value); (void)TRY(vm.call(*setter, receiver, value));
if (vm.exception())
return {};
// 8. Return true. // 8. Return true.
return true; return true;

View file

@ -104,7 +104,7 @@ public:
virtual ThrowCompletionOr<bool> internal_delete(PropertyName const&); virtual ThrowCompletionOr<bool> internal_delete(PropertyName const&);
virtual ThrowCompletionOr<MarkedValueList> internal_own_property_keys() const; virtual ThrowCompletionOr<MarkedValueList> internal_own_property_keys() const;
bool ordinary_set_with_own_descriptor(PropertyName const&, Value, Value, Optional<PropertyDescriptor>); ThrowCompletionOr<bool> ordinary_set_with_own_descriptor(PropertyName const&, Value, Value, Optional<PropertyDescriptor>);
// 10.4.7 Immutable Prototype Exotic Objects, https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects // 10.4.7 Immutable Prototype Exotic Objects, https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects