1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

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.
This commit is contained in:
Linus Groh 2021-10-20 19:17:45 +01:00
parent 894834b5d5
commit 0881f8160f
12 changed files with 25 additions and 25 deletions

View file

@ -159,7 +159,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> 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);
}

View file

@ -43,7 +43,7 @@ ThrowCompletionOr<Value> 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

View file

@ -33,9 +33,9 @@ BoundFunction* FunctionObject::bind(Value bound_this_value, Vector<Value> 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());

View file

@ -35,7 +35,7 @@ void GlobalEnvironment::visit_edges(Cell::Visitor& visitor)
ThrowCompletionOr<Value> 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

View file

@ -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);
// 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

View file

@ -117,7 +117,7 @@ ThrowCompletionOr<Value> 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<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.
// 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<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.
// 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<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.
// 7. Return code.
return { js_string(vm, code.to_uppercase_string()) };
return js_string(vm, code.to_uppercase_string());
}
}

View file

@ -676,7 +676,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> 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

View file

@ -312,7 +312,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> 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

View file

@ -272,7 +272,7 @@ ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& c
return vm.throw_completion<TypeError>(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.

View file

@ -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());
// 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.
@ -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());
// 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<Optional<String>> 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<String> 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<String> 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

View file

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

View file

@ -337,11 +337,11 @@ ThrowCompletionOr<String> 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<StringOrSymbol> 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<i32> Value::to_i32_slow_case(GlobalObject& global_object) const