mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-08 10:36:02 +00:00
LibJS: Make string_to_double use the new double parser
This commit is contained in:
parent
6805ded21d
commit
783b1a479d
Notes:
sideshowbarker
2024-07-17 05:11:36 +09:00
Author: https://github.com/davidot
Commit: 783b1a479d
Pull-request: https://github.com/SerenityOS/serenity/pull/15377
Issue: https://github.com/SerenityOS/serenity/issues/14691
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/linusg
1 changed files with 4 additions and 4 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue