diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-03 19:54:37 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-04 09:52:15 +0100 |
commit | 3b59a4577dec1cc749cc9209bf396c38e4b568e8 (patch) | |
tree | f4098c1dc1e3da9387ad35b05e96123e895758c6 /Userland/Libraries/LibJS | |
parent | 0a49a2db60212df1a92ad96170ef9497632ab6da (diff) | |
download | serenity-3b59a4577dec1cc749cc9209bf396c38e4b568e8.zip |
LibJS: Convert define_properties() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Object.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Object.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp | 4 |
3 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 4e93771321..c58db078bf 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1038,7 +1038,7 @@ void Object::define_native_function(PropertyName const& property_name, Function< } // 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties -Object* Object::define_properties(Value properties) +ThrowCompletionOr<Object*> Object::define_properties(Value properties) { auto& vm = this->vm(); auto& global_object = this->global_object(); @@ -1047,11 +1047,11 @@ Object* Object::define_properties(Value properties) // 2. Let props be ? ToObject(Properties). auto* props = properties.to_object(global_object); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // 3. Let keys be ? props.[[OwnPropertyKeys]](). - auto keys = TRY_OR_DISCARD(props->internal_own_property_keys()); + auto keys = TRY(props->internal_own_property_keys()); struct NameAndDescriptor { PropertyName name; @@ -1066,17 +1066,17 @@ Object* Object::define_properties(Value properties) auto property_name = PropertyName::from_value(global_object, next_key); // a. Let propDesc be ? props.[[GetOwnProperty]](nextKey). - auto property_descriptor = TRY_OR_DISCARD(props->internal_get_own_property(property_name)); + auto property_descriptor = TRY(props->internal_get_own_property(property_name)); // 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_OR_DISCARD(props->get(property_name)); + auto descriptor_object = TRY(props->get(property_name)); // ii. Let desc be ? ToPropertyDescriptor(descObj). auto descriptor = to_property_descriptor(global_object, descriptor_object); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors. descriptors.append({ property_name, descriptor }); @@ -1089,7 +1089,7 @@ Object* Object::define_properties(Value properties) // b. Let desc be the second element of pair. // c. Perform ? DefinePropertyOrThrow(O, P, desc). - TRY_OR_DISCARD(define_property_or_throw(name, descriptor)); + TRY(define_property_or_throw(name, descriptor)); } // 7. Return O. diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 1fb370c8ae..54ae685f45 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -112,7 +112,7 @@ public: // 20.1 Object Objects, https://tc39.es/ecma262/#sec-object-objects - Object* define_properties(Value properties); + ThrowCompletionOr<Object*> define_properties(Value properties); // Implementation-specific storage abstractions diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 6be1d4b862..7598aba558 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -354,7 +354,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_properties) } // 2. Return ? ObjectDefineProperties(O, Properties). - return object.as_object().define_properties(properties); + return TRY_OR_DISCARD(object.as_object().define_properties(properties)); } // 20.1.2.13 Object.is ( value1, value2 ), https://tc39.es/ecma262/#sec-object.is @@ -411,7 +411,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create) // 3. If Properties is not undefined, then if (!properties.is_undefined()) { // a. Return ? ObjectDefineProperties(obj, Properties). - return object->define_properties(properties); + return TRY_OR_DISCARD(object->define_properties(properties)); } // 4. Return obj. |