From 0881f8160fd81d8e25b7cc2eff2d64f2aed7ed53 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 20 Oct 2021 19:17:45 +0100 Subject: [PATCH] LibJS: Use implicit ThrowCompletionOr constructor where possible Luckily this is not very widespread yet as most of it would happen in the various JS functions instead of AOs. --- Userland/Libraries/LibJS/Runtime/Array.cpp | 2 +- .../Libraries/LibJS/Runtime/FunctionEnvironment.cpp | 2 +- Userland/Libraries/LibJS/Runtime/FunctionObject.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp | 2 +- .../LibJS/Runtime/Intl/AbstractOperations.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp | 8 ++++---- Userland/Libraries/LibJS/Runtime/Object.cpp | 2 +- Userland/Libraries/LibJS/Runtime/ProxyObject.cpp | 2 +- Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp | 2 +- .../LibJS/Runtime/Temporal/AbstractOperations.cpp | 10 +++++----- Userland/Libraries/LibJS/Runtime/TypedArray.h | 4 ++-- Userland/Libraries/LibJS/Runtime/Value.cpp | 10 +++++----- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index f609274aa7a..f293d239870 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -159,7 +159,7 @@ ThrowCompletionOr> Array::internal_get_own_property { auto& vm = this->vm(); if (property_name.is_string() && property_name.as_string() == vm.names.length.as_string()) - return { PropertyDescriptor { .value = Value(indexed_properties().array_like_size()), .writable = m_length_writable, .enumerable = false, .configurable = false } }; + return PropertyDescriptor { .value = Value(indexed_properties().array_like_size()), .writable = m_length_writable, .enumerable = false, .configurable = false }; return Object::internal_get_own_property(property_name); } diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp index 7ae94ae4f26..198189515c6 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp @@ -43,7 +43,7 @@ ThrowCompletionOr FunctionEnvironment::get_super_base() const // 3. Assert: Type(home) is Object. // 4. Return ? home.[[GetPrototypeOf]](). - return { TRY(home_object->internal_get_prototype_of()) }; + return TRY(home_object->internal_get_prototype_of()); } // 9.1.1.3.2 HasThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp index a9d3c26b83e..ff6e3925330 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp @@ -33,9 +33,9 @@ BoundFunction* FunctionObject::bind(Value bound_this_value, Vector argume case Value::Type::Null: if (vm.in_strict_mode()) return bound_this_value; - return { &global_object() }; + return &global_object(); default: - return { TRY(bound_this_value.to_object(global_object())) }; + return TRY(bound_this_value.to_object(global_object())); } }; auto bound_this_object = TRY_OR_DISCARD(get_bound_this_object()); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp index 94d2133f570..ef42b5ea23a 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp @@ -35,7 +35,7 @@ void GlobalEnvironment::visit_edges(Cell::Visitor& visitor) ThrowCompletionOr GlobalEnvironment::get_this_binding(GlobalObject&) const { // 1. Return envRec.[[GlobalThisValue]]. - return { m_global_this_value }; + return m_global_this_value; } // 9.1.1.4.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-hasbinding-n diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index 69eec049818..b1eb98f0821 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -657,7 +657,7 @@ ThrowCompletionOr> default_number_option(GlobalObject& global_obje return vm.throw_completion(global_object, ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum); // 4. Return floor(value). - return { floor(value.as_double()) }; + return floor(value.as_double()); } // 9.2.15 GetNumberOption ( options, property, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-getnumberoption diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp index c720533c020..05af7040e96 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp @@ -117,7 +117,7 @@ ThrowCompletionOr canonical_code_for_display_names(GlobalObject& global_o // c. Set code to CanonicalizeUnicodeLocaleId(code). // d. Return code. auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id); - return { js_string(vm, move(canonicalized_tag)) }; + return js_string(vm, move(canonicalized_tag)); } // 2. If type is "region", then @@ -128,7 +128,7 @@ ThrowCompletionOr canonical_code_for_display_names(GlobalObject& global_o // b. Let code be the result of mapping code to upper case as described in 6.1. // c. Return code. - return { js_string(vm, code.to_uppercase_string()) }; + return js_string(vm, code.to_uppercase_string()); } // 3. If type is "script", then @@ -139,7 +139,7 @@ ThrowCompletionOr canonical_code_for_display_names(GlobalObject& global_o // b. Let code be the result of mapping the first character in code to upper case, and mapping the second, third, and fourth character in code to lower case, as described in 6.1. // c. Return code. - return { js_string(vm, code.to_titlecase_string()) }; + return js_string(vm, code.to_titlecase_string()); } // 4. Assert: type is "currency". @@ -151,7 +151,7 @@ ThrowCompletionOr canonical_code_for_display_names(GlobalObject& global_o // 6. Let code be the result of mapping code to upper case as described in 6.1. // 7. Return code. - return { js_string(vm, code.to_uppercase_string()) }; + return js_string(vm, code.to_uppercase_string()); } } diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 8b11d694553..600dfb53654 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -676,7 +676,7 @@ ThrowCompletionOr> Object::internal_get_own_propert descriptor.configurable = attributes.is_configurable(); // 9. Return D. - return { descriptor }; + return descriptor; } // 10.1.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp index 1390ebb6c9b..9d7b0c208df 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -312,7 +312,7 @@ ThrowCompletionOr> ProxyObject::internal_get_own_pr } // 18. Return resultDesc. - return { result_desc }; + return result_desc; } // 10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index cdc584605bc..becc7af91f1 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -272,7 +272,7 @@ ThrowCompletionOr get_wrapped_value(GlobalObject& global_object, Realm& c return vm.throw_completion(global_object, ErrorType::ShadowRealmWrappedValueNonFunctionObject, value); // b. Return ! WrappedFunctionCreate(callerRealm, value). - return { WrappedFunction::create(global_object, caller_realm, value.as_function()) }; + return WrappedFunction::create(global_object, caller_realm, value.as_function()); } // 3. Return value. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index f2a3c302ece..ab8b08e67a7 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -174,7 +174,7 @@ ThrowCompletionOr> get_string_or_number_option(Globa return vm.template throw_completion(global_object, ErrorType::OptionIsNotValidValue, value.as_double(), property.as_string()); // b. Return floor(ℝ(value)). - return { static_cast(floor(value.as_double())) }; + return static_cast(floor(value.as_double())); } // 4. Assert: Type(value) is String. @@ -185,7 +185,7 @@ ThrowCompletionOr> get_string_or_number_option(Globa return vm.template throw_completion(global_object, ErrorType::OptionIsNotValidValue, value.as_string().string(), property.as_string()); // 6. Return value. - return { value.as_string().string() }; + return value.as_string().string(); } // 13.6 ToTemporalOverflow ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloverflow @@ -430,7 +430,7 @@ ThrowCompletionOr> to_smallest_temporal_unit(GlobalObject& glob } // 5. Return smallestUnit. - return { smallest_unit }; + return smallest_unit; } // 13.22 ValidateTemporalUnitRange ( largestUnit, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-validatetemporalunitrange @@ -871,7 +871,7 @@ ThrowCompletionOr parse_temporal_calendar_string(GlobalObject& global_ob // 4. If id is undefined, then if (!id_part.has_value()) { // a. Return "iso8601". - return { "iso8601"sv }; + return "iso8601"sv; } // 5. If ! IsBuiltinCalendar(id) is false, then @@ -881,7 +881,7 @@ ThrowCompletionOr parse_temporal_calendar_string(GlobalObject& global_ob } // 6. Return id. - return { id_part.value() }; + return id_part.value(); } // 13.38 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index cf947015f00..d77e6abfc2a 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -216,12 +216,12 @@ public: return Optional {}; // iii. Return the PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }. - return { PropertyDescriptor { + return PropertyDescriptor { .value = value, .writable = true, .enumerable = true, .configurable = true, - } }; + }; } } diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 38f9ecf55f2..0c843433d03 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -337,11 +337,11 @@ ThrowCompletionOr Value::to_string(GlobalObject& global_object) const auto& vm = global_object.vm(); switch (m_type) { case Type::Undefined: - return { "undefined"sv }; + return "undefined"sv; case Type::Null: - return { "null"sv }; + return "null"sv; case Type::Boolean: - return { m_value.as_bool ? "true"sv : "false"sv }; + return m_value.as_bool ? "true"sv : "false"sv; case Type::Int32: return String::number(m_value.as_i32); case Type::Double: @@ -563,8 +563,8 @@ ThrowCompletionOr Value::to_property_key(GlobalObject& global_ob { auto key = TRY(to_primitive(global_object, PreferredType::String)); if (key.is_symbol()) - return StringOrSymbol { &key.as_symbol() }; - return StringOrSymbol { TRY(key.to_string(global_object)) }; + return &key.as_symbol(); + return TRY(key.to_string(global_object)); } ThrowCompletionOr Value::to_i32_slow_case(GlobalObject& global_object) const