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

LibJS: Make string_to_number() return double instead of Optional<Value>

This would never return an empty optional or non-numeric value, and in
fact every caller as_double()'d the value right away.
Let's make the type match reality instead :^)
This commit is contained in:
Linus Groh 2023-03-01 14:48:12 +00:00
parent 9fb7f7fceb
commit e77503e49b
3 changed files with 14 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -570,7 +570,7 @@ double parse_time_zone_offset_string(StringView offset_string)
auto parsed_hours = *parse_result->time_zone_utc_offset_hour;
// 10. Let hours be (StringToNumber(CodePointsToString(parsedHours))).
auto hours = string_to_number(parsed_hours)->as_double();
auto hours = string_to_number(parsed_hours);
double minutes { 0 };
double seconds { 0 };
@ -587,7 +587,7 @@ double parse_time_zone_offset_string(StringView offset_string)
auto parsed_minutes = *parse_result->time_zone_utc_offset_minute;
// b. Let minutes be (StringToNumber(CodePointsToString(parsedMinutes))).
minutes = string_to_number(parsed_minutes)->as_double();
minutes = string_to_number(parsed_minutes);
}
// 13. If parseResult does not contain two MinuteSecond Parse Nodes, then
@ -601,7 +601,7 @@ double parse_time_zone_offset_string(StringView offset_string)
auto parsed_seconds = *parse_result->time_zone_utc_offset_second;
// b. Let seconds be (StringToNumber(CodePointsToString(parsedSeconds))).
seconds = string_to_number(parsed_seconds)->as_double();
seconds = string_to_number(parsed_seconds);
}
// 15. If parseResult does not contain a TemporalDecimalFraction Parse Node, then
@ -621,7 +621,7 @@ double parse_time_zone_offset_string(StringView offset_string)
auto nanoseconds_string = fraction.substring_view(1, 9);
// d. Let nanoseconds be (StringToNumber(nanosecondsString)).
nanoseconds = string_to_number(nanoseconds_string)->as_double();
nanoseconds = string_to_number(nanoseconds_string);
}
// 17. Return sign × (((hours × 60 + minutes) × 60 + seconds) × 10^9 + nanoseconds).