Ver código fonte

LibJS: Use implicit ThrowCompletionOr<T> constructor where possible

Luckily this is not very widespread yet as most of it would happen in
the various JS functions instead of AOs.
Linus Groh 3 anos atrás
pai
commit
0881f8160f

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Array.cpp

@@ -159,7 +159,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Array::internal_get_own_property
 {
 {
     auto& vm = this->vm();
     auto& vm = this->vm();
     if (property_name.is_string() && property_name.as_string() == vm.names.length.as_string())
     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);
     return Object::internal_get_own_property(property_name);
 }
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp

@@ -43,7 +43,7 @@ ThrowCompletionOr<Value> FunctionEnvironment::get_super_base() const
     // 3. Assert: Type(home) is Object.
     // 3. Assert: Type(home) is Object.
 
 
     // 4. Return ? home.[[GetPrototypeOf]]().
     // 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
 // 9.1.1.3.2 HasThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FunctionObject.cpp

@@ -33,9 +33,9 @@ BoundFunction* FunctionObject::bind(Value bound_this_value, Vector<Value> argume
         case Value::Type::Null:
         case Value::Type::Null:
             if (vm.in_strict_mode())
             if (vm.in_strict_mode())
                 return bound_this_value;
                 return bound_this_value;
-            return { &global_object() };
+            return &global_object();
         default:
         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());
     auto bound_this_object = TRY_OR_DISCARD(get_bound_this_object());

+ 1 - 1
Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp

@@ -35,7 +35,7 @@ void GlobalEnvironment::visit_edges(Cell::Visitor& visitor)
 ThrowCompletionOr<Value> GlobalEnvironment::get_this_binding(GlobalObject&) const
 ThrowCompletionOr<Value> GlobalEnvironment::get_this_binding(GlobalObject&) const
 {
 {
     // 1. Return envRec.[[GlobalThisValue]].
     // 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
 // 9.1.1.4.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-hasbinding-n

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp

@@ -657,7 +657,7 @@ ThrowCompletionOr<Optional<int>> default_number_option(GlobalObject& global_obje
         return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum);
         return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum);
 
 
     // 4. Return floor(value).
     // 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
 // 9.2.15 GetNumberOption ( options, property, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-getnumberoption

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp

@@ -117,7 +117,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
         // c. Set code to CanonicalizeUnicodeLocaleId(code).
         // c. Set code to CanonicalizeUnicodeLocaleId(code).
         // d. Return code.
         // d. Return code.
         auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
         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
     // 2. If type is "region", then
@@ -128,7 +128,7 @@ ThrowCompletionOr<Value> 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.
         // b. Let code be the result of mapping code to upper case as described in 6.1.
         // c. Return code.
         // 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
     // 3. If type is "script", then
@@ -139,7 +139,7 @@ ThrowCompletionOr<Value> 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.
         // 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.
         // c. Return code.
-        return { js_string(vm, code.to_titlecase_string()) };
+        return js_string(vm, code.to_titlecase_string());
     }
     }
 
 
     // 4. Assert: type is "currency".
     // 4. Assert: type is "currency".
@@ -151,7 +151,7 @@ ThrowCompletionOr<Value> 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.
     // 6. Let code be the result of mapping code to upper case as described in 6.1.
     // 7. Return code.
     // 7. Return code.
-    return { js_string(vm, code.to_uppercase_string()) };
+    return js_string(vm, code.to_uppercase_string());
 }
 }
 
 
 }
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Object.cpp

@@ -676,7 +676,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> Object::internal_get_own_propert
     descriptor.configurable = attributes.is_configurable();
     descriptor.configurable = attributes.is_configurable();
 
 
     // 9. Return D.
     // 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
 // 10.1.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ProxyObject.cpp

@@ -312,7 +312,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr
     }
     }
 
 
     // 18. Return resultDesc.
     // 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
 // 10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp

@@ -272,7 +272,7 @@ ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& c
             return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmWrappedValueNonFunctionObject, value);
             return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmWrappedValueNonFunctionObject, value);
 
 
         // b. Return ! WrappedFunctionCreate(callerRealm, 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.
     // 3. Return value.

+ 5 - 5
Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp

@@ -174,7 +174,7 @@ ThrowCompletionOr<Variant<String, NumberType>> get_string_or_number_option(Globa
             return vm.template throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, value.as_double(), property.as_string());
             return vm.template throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, value.as_double(), property.as_string());
 
 
         // b. Return floor(ℝ(value)).
         // b. Return floor(ℝ(value)).
-        return { static_cast<NumberType>(floor(value.as_double())) };
+        return static_cast<NumberType>(floor(value.as_double()));
     }
     }
 
 
     // 4. Assert: Type(value) is String.
     // 4. Assert: Type(value) is String.
@@ -185,7 +185,7 @@ ThrowCompletionOr<Variant<String, NumberType>> get_string_or_number_option(Globa
         return vm.template throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, value.as_string().string(), property.as_string());
         return vm.template throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, value.as_string().string(), property.as_string());
 
 
     // 6. Return value.
     // 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
 // 13.6 ToTemporalOverflow ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloverflow
@@ -430,7 +430,7 @@ ThrowCompletionOr<Optional<String>> to_smallest_temporal_unit(GlobalObject& glob
     }
     }
 
 
     // 5. Return smallestUnit.
     // 5. Return smallestUnit.
-    return { smallest_unit };
+    return smallest_unit;
 }
 }
 
 
 // 13.22 ValidateTemporalUnitRange ( largestUnit, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-validatetemporalunitrange
 // 13.22 ValidateTemporalUnitRange ( largestUnit, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-validatetemporalunitrange
@@ -871,7 +871,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject& global_ob
     // 4. If id is undefined, then
     // 4. If id is undefined, then
     if (!id_part.has_value()) {
     if (!id_part.has_value()) {
         // a. Return "iso8601".
         // a. Return "iso8601".
-        return { "iso8601"sv };
+        return "iso8601"sv;
     }
     }
 
 
     // 5. If ! IsBuiltinCalendar(id) is false, then
     // 5. If ! IsBuiltinCalendar(id) is false, then
@@ -881,7 +881,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject& global_ob
     }
     }
 
 
     // 6. Return id.
     // 6. Return id.
-    return { id_part.value() };
+    return id_part.value();
 }
 }
 
 
 // 13.38 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring
 // 13.38 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring

+ 2 - 2
Userland/Libraries/LibJS/Runtime/TypedArray.h

@@ -216,12 +216,12 @@ public:
                     return Optional<PropertyDescriptor> {};
                     return Optional<PropertyDescriptor> {};
 
 
                 // iii. Return the PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
                 // iii. Return the PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
-                return { PropertyDescriptor {
+                return PropertyDescriptor {
                     .value = value,
                     .value = value,
                     .writable = true,
                     .writable = true,
                     .enumerable = true,
                     .enumerable = true,
                     .configurable = true,
                     .configurable = true,
-                } };
+                };
             }
             }
         }
         }
 
 

+ 5 - 5
Userland/Libraries/LibJS/Runtime/Value.cpp

@@ -337,11 +337,11 @@ ThrowCompletionOr<String> Value::to_string(GlobalObject& global_object) const
     auto& vm = global_object.vm();
     auto& vm = global_object.vm();
     switch (m_type) {
     switch (m_type) {
     case Type::Undefined:
     case Type::Undefined:
-        return { "undefined"sv };
+        return "undefined"sv;
     case Type::Null:
     case Type::Null:
-        return { "null"sv };
+        return "null"sv;
     case Type::Boolean:
     case Type::Boolean:
-        return { m_value.as_bool ? "true"sv : "false"sv };
+        return m_value.as_bool ? "true"sv : "false"sv;
     case Type::Int32:
     case Type::Int32:
         return String::number(m_value.as_i32);
         return String::number(m_value.as_i32);
     case Type::Double:
     case Type::Double:
@@ -563,8 +563,8 @@ ThrowCompletionOr<StringOrSymbol> Value::to_property_key(GlobalObject& global_ob
 {
 {
     auto key = TRY(to_primitive(global_object, PreferredType::String));
     auto key = TRY(to_primitive(global_object, PreferredType::String));
     if (key.is_symbol())
     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<i32> Value::to_i32_slow_case(GlobalObject& global_object) const
 ThrowCompletionOr<i32> Value::to_i32_slow_case(GlobalObject& global_object) const