mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Trim initial whitespace in parseFloat
This commit is contained in:
parent
bda32e9440
commit
bbf75d0bea
Notes:
sideshowbarker
2024-07-18 14:29:45 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/bbf75d0beab Pull-request: https://github.com/SerenityOS/serenity/pull/7830 Reviewed-by: https://github.com/linusg ✅
1 changed files with 4 additions and 3 deletions
|
@ -202,12 +202,13 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
|
|||
{
|
||||
if (vm.argument(0).is_number())
|
||||
return vm.argument(0);
|
||||
auto string = vm.argument(0).to_string(global_object);
|
||||
auto input_string = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
for (size_t length = string.length(); length > 0; --length) {
|
||||
auto trimmed_string = input_string.trim_whitespace(TrimMode::Left);
|
||||
for (size_t length = trimmed_string.length(); length > 0; --length) {
|
||||
// This can't throw, so no exception check is fine.
|
||||
auto number = Value(js_string(vm, string.substring(0, length))).to_number(global_object);
|
||||
auto number = Value(js_string(vm, trimmed_string.substring(0, length))).to_number(global_object);
|
||||
if (!number.is_nan())
|
||||
return number;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue