summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-10-12 02:23:50 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-23 15:48:45 +0200
commit783b1a479dddb330cb4c32dda0ea5477474add42 (patch)
treebbd19fcd06203aa1da61061fa5df026e0c1f51c1 /Userland/Libraries/LibJS
parent6805ded21de966b5f3f9d752b2db3547cade1b2d (diff)
downloadserenity-783b1a479dddb330cb4c32dda0ea5477474add42.zip
LibJS: Make string_to_double use the new double parser
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 5ed60fefd9..9ea8b4f4aa 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -9,6 +9,7 @@
#include <AK/AllOf.h>
#include <AK/Assertions.h>
#include <AK/CharacterTypes.h>
+#include <AK/FloatingPointStringConversions.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Utf8View.h>
@@ -549,12 +550,11 @@ Optional<Value> string_to_number(StringView string)
return Value(bigint.to_double());
}
- char* endptr;
- auto parsed_double = strtod(text.characters(), &endptr);
- if (*endptr)
+ auto maybe_double = text.to_double(AK::TrimWhitespace::No);
+ if (!maybe_double.has_value())
return js_nan();
- return Value(parsed_double);
+ return Value(*maybe_double);
}
// 7.1.4 ToNumber ( argument ), https://tc39.es/ecma262/#sec-tonumber