From 2f42675ebd244ed1bf3cd97ff2a6029cbc728226 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 3 Oct 2021 19:57:29 +0100 Subject: [PATCH] LibJS: Convert ordinary_set_with_own_descriptor() to ThrowCompletionOr --- .../LibWeb/WrapperGenerator.cpp | 5 +---- Userland/Libraries/LibJS/Runtime/Object.cpp | 21 +++++++------------ Userland/Libraries/LibJS/Runtime/Object.h | 2 +- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp index 636852dc6b..9436cd6119 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp @@ -2064,10 +2064,7 @@ JS::ThrowCompletionOr @class_name@::internal_set(JS::PropertyName const& p // 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. // 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); - if (auto* exception = vm.exception()) - return JS::throw_completion(exception->value()); - return result; + return ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor); } )~~~"); diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index c58db078bf..ebcc50e05e 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -686,14 +686,11 @@ ThrowCompletionOr Object::internal_set(PropertyName const& property_name, auto own_descriptor = TRY(internal_get_own_property(property_name)); // 3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc). - auto success = ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); - return success; + return ordinary_set_with_own_descriptor(property_name, value, receiver, own_descriptor); } // 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 own_descriptor) +ThrowCompletionOr Object::ordinary_set_with_own_descriptor(PropertyName const& property_name, Value value, Value receiver, Optional own_descriptor) { 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 if (!own_descriptor.has_value()) { // 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 if (parent) { // 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, else { @@ -733,7 +730,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name, return false; // 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 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 }; // 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, else { @@ -757,7 +754,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name, VERIFY(!receiver.as_object().storage_has(property_name)); // 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; // 7. Perform ? Call(setter, Receiver, « V »). - (void)vm.call(*setter, receiver, value); - if (vm.exception()) - return {}; + (void)TRY(vm.call(*setter, receiver, value)); // 8. Return true. return true; diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 54ae685f45..1e96267579 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -104,7 +104,7 @@ public: virtual ThrowCompletionOr internal_delete(PropertyName const&); virtual ThrowCompletionOr internal_own_property_keys() const; - bool ordinary_set_with_own_descriptor(PropertyName const&, Value, Value, Optional); + ThrowCompletionOr ordinary_set_with_own_descriptor(PropertyName const&, Value, Value, Optional); // 10.4.7 Immutable Prototype Exotic Objects, https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects