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

LibJS: Make string_to_double use the new double parser

This commit is contained in:
davidot 2022-10-12 02:23:50 +02:00 committed by Linus Groh
parent 6805ded21d
commit 783b1a479d

View file

@ -9,6 +9,7 @@
#include <AK/AllOf.h> #include <AK/AllOf.h>
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/CharacterTypes.h> #include <AK/CharacterTypes.h>
#include <AK/FloatingPointStringConversions.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
@ -549,12 +550,11 @@ Optional<Value> string_to_number(StringView string)
return Value(bigint.to_double()); return Value(bigint.to_double());
} }
char* endptr; auto maybe_double = text.to_double(AK::TrimWhitespace::No);
auto parsed_double = strtod(text.characters(), &endptr); if (!maybe_double.has_value())
if (*endptr)
return js_nan(); return js_nan();
return Value(parsed_double); return Value(*maybe_double);
} }
// 7.1.4 ToNumber ( argument ), https://tc39.es/ecma262/#sec-tonumber // 7.1.4 ToNumber ( argument ), https://tc39.es/ecma262/#sec-tonumber