mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:37:34 +00:00
LibJS: Convert to_integer_or_infinity() to ThrowCompletionOr
This commit is contained in:
parent
ffee3890a7
commit
be28a6142b
16 changed files with 100 additions and 237 deletions
|
@ -751,7 +751,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
|
|||
normalized_year = year_part.value_or("");
|
||||
|
||||
// 5. Set year to ! ToIntegerOrInfinity(year).
|
||||
i32 year = Value(js_string(vm, normalized_year)).to_integer_or_infinity(global_object);
|
||||
i32 year = MUST(Value(js_string(vm, normalized_year)).to_integer_or_infinity(global_object));
|
||||
|
||||
u8 month;
|
||||
// 6. If month is undefined, then
|
||||
|
@ -984,7 +984,7 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
|
|||
VERIFY(sign_part.has_value());
|
||||
|
||||
// b. Set hours to ! ToIntegerOrInfinity(hours).
|
||||
u8 hours = Value(js_string(vm, *hours_part)).to_integer_or_infinity(global_object);
|
||||
u8 hours = MUST(Value(js_string(vm, *hours_part)).to_integer_or_infinity(global_object));
|
||||
|
||||
u8 sign;
|
||||
// c. If sign is the code unit 0x002D (HYPHEN-MINUS) or the code unit 0x2212 (MINUS SIGN), then
|
||||
|
@ -999,10 +999,10 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
|
|||
}
|
||||
|
||||
// e. Set minutes to ! ToIntegerOrInfinity(minutes).
|
||||
u8 minutes = Value(js_string(vm, minutes_part.value_or(""sv))).to_integer_or_infinity(global_object);
|
||||
u8 minutes = MUST(Value(js_string(vm, minutes_part.value_or(""sv))).to_integer_or_infinity(global_object));
|
||||
|
||||
// f. Set seconds to ! ToIntegerOrInfinity(seconds).
|
||||
u8 seconds = Value(js_string(vm, seconds_part.value_or(""sv))).to_integer_or_infinity(global_object);
|
||||
u8 seconds = MUST(Value(js_string(vm, seconds_part.value_or(""sv))).to_integer_or_infinity(global_object));
|
||||
|
||||
i32 nanoseconds;
|
||||
// g. If fraction is not undefined, then
|
||||
|
@ -1011,7 +1011,7 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
|
|||
auto fraction = String::formatted("{}000000000", *fraction_part);
|
||||
// ii. Let nanoseconds be the String value equal to the substring of fraction from 0 to 9.
|
||||
// iii. Set nanoseconds to ! ToIntegerOrInfinity(nanoseconds).
|
||||
nanoseconds = Value(js_string(vm, fraction.substring(0, 9))).to_integer_or_infinity(global_object);
|
||||
nanoseconds = MUST(Value(js_string(vm, fraction.substring(0, 9))).to_integer_or_infinity(global_object));
|
||||
}
|
||||
// h. Else,
|
||||
else {
|
||||
|
|
|
@ -123,9 +123,7 @@ ThrowCompletionOr<double> to_integer_throw_on_infinity(GlobalObject& global_obje
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let integer be ? ToIntegerOrInfinity(argument).
|
||||
auto integer = argument.to_integer_or_infinity(global_object);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto integer = TRY(argument.to_integer_or_infinity(global_object));
|
||||
|
||||
// 2. If integer is −∞ or +∞ , then
|
||||
if (Value(integer).is_infinity()) {
|
||||
|
|
|
@ -711,7 +711,7 @@ ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object
|
|||
auto number_part = month_code_string.substring(1);
|
||||
|
||||
// 8. Set numberPart to ! ToIntegerOrInfinity(numberPart).
|
||||
auto number_part_integer = Value(js_string(vm, move(number_part))).to_integer_or_infinity(global_object);
|
||||
auto number_part_integer = MUST(Value(js_string(vm, move(number_part))).to_integer_or_infinity(global_object));
|
||||
|
||||
// 9. If numberPart < 1 or numberPart > 12, throw a RangeError exception.
|
||||
if (number_part_integer < 1 || number_part_integer > 12)
|
||||
|
|
|
@ -237,11 +237,11 @@ ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject& global_obj
|
|||
}
|
||||
|
||||
// 7. Set hours to ! ToIntegerOrInfinity(hours).
|
||||
auto hours = Value(js_string(vm, hours_part)).to_integer_or_infinity(global_object);
|
||||
auto hours = MUST(Value(js_string(vm, hours_part)).to_integer_or_infinity(global_object));
|
||||
// 8. Set minutes to ! ToIntegerOrInfinity(minutes).
|
||||
auto minutes = Value(js_string(vm, minutes_part.value_or(""sv))).to_integer_or_infinity(global_object);
|
||||
auto minutes = MUST(Value(js_string(vm, minutes_part.value_or(""sv))).to_integer_or_infinity(global_object));
|
||||
// 9. Set seconds to ! ToIntegerOrInfinity(seconds).
|
||||
auto seconds = Value(js_string(vm, seconds_part.value_or(""sv))).to_integer_or_infinity(global_object);
|
||||
auto seconds = MUST(Value(js_string(vm, seconds_part.value_or(""sv))).to_integer_or_infinity(global_object));
|
||||
|
||||
double nanoseconds;
|
||||
// 10. If fraction is not undefined, then
|
||||
|
@ -250,7 +250,7 @@ ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject& global_obj
|
|||
auto fraction = String::formatted("{}000000000", *fraction_part);
|
||||
// b. Let nanoseconds be the String value equal to the substring of fraction consisting of the code units with indices 0 (inclusive) through 9 (exclusive).
|
||||
// c. Set nanoseconds to ! ToIntegerOrInfinity(nanoseconds).
|
||||
nanoseconds = Value(js_string(vm, fraction_part->substring_view(0, 9))).to_integer_or_infinity(global_object);
|
||||
nanoseconds = MUST(Value(js_string(vm, fraction_part->substring_view(0, 9))).to_integer_or_infinity(global_object));
|
||||
}
|
||||
// 11. Else,
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue