diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 2c42a60fa41..cb0251ed98e 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, Linus Groh + * Copyright (c) 2020-2023, Linus Groh * Copyright (c) 2022, Tim Flynn * * 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). diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 0dd7bbc2d67..660fe78bb26 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -664,36 +664,36 @@ static Optional parse_number_text(StringView text) } // 7.1.4.1.1 StringToNumber ( str ), https://tc39.es/ecma262/#sec-stringtonumber -Optional string_to_number(StringView string) +double string_to_number(StringView string) { // 1. Let text be StringToCodePoints(str). DeprecatedString text = Utf8View(string).trim(whitespace_characters, AK::TrimMode::Both).as_string(); // 2. Let literal be ParseText(text, StringNumericLiteral). if (text.is_empty()) - return Value(0); + return 0; if (text == "Infinity" || text == "+Infinity") - return js_infinity(); + return INFINITY; if (text == "-Infinity") - return js_negative_infinity(); + return -INFINITY; auto result = parse_number_text(text); // 3. If literal is a List of errors, return NaN. if (!result.has_value()) - return js_nan(); + return NAN; // 4. Return StringNumericValue of literal. if (result->base != 10) { auto bigint = Crypto::UnsignedBigInteger::from_base(result->base, result->literal); - return Value(bigint.to_double()); + return bigint.to_double(); } auto maybe_double = text.to_double(AK::TrimWhitespace::No); if (!maybe_double.has_value()) - return js_nan(); + return NAN; - return Value(*maybe_double); + return *maybe_double; } // 7.1.4 ToNumber ( argument ), https://tc39.es/ecma262/#sec-tonumber diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 2f3cf2d11c9..81ac4c57ec5 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -563,7 +563,7 @@ enum class NumberToStringMode { }; ErrorOr number_to_string(double, NumberToStringMode = NumberToStringMode::WithExponent); DeprecatedString number_to_deprecated_string(double, NumberToStringMode = NumberToStringMode::WithExponent); -Optional string_to_number(StringView); +double string_to_number(StringView); inline bool Value::operator==(Value const& value) const { return same_value(*this, value); }