diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-06 02:32:14 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-06 01:34:22 +0100 |
commit | bbf75d0beab57498d5a757126972791244932a91 (patch) | |
tree | db0058ed32addea4d85a563861bbfcb50ccdbdfe | |
parent | bda32e9440d50630112f45506da8c0fa5e7d5dfb (diff) | |
download | serenity-bbf75d0beab57498d5a757126972791244932a91.zip |
LibJS: Trim initial whitespace in parseFloat
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 0032bce697..855bbdac40 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -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; } |