mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibJS: Trim initial whitespace in parseFloat
This commit is contained in:
parent
bda32e9440
commit
bbf75d0bea
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())
|
if (vm.argument(0).is_number())
|
||||||
return vm.argument(0);
|
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())
|
if (vm.exception())
|
||||||
return {};
|
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.
|
// 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())
|
if (!number.is_nan())
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue