mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-14 23:22:52 +00:00
LibJS: Fix parseFloat(-0) returning -0 instead of +0
The optimization that skips the string conversion for number values was causing -0 to be returned as-is. This patch adds a check for this case.
This commit is contained in:
parent
61744322ad
commit
53cdb04ee8
Notes:
github-actions[bot]
2025-03-02 16:31:28 +00:00
Author: https://github.com/aplefull
Commit: 53cdb04ee8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3765
Reviewed-by: https://github.com/tcl3
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 27 additions and 2 deletions
|
@ -247,8 +247,13 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
|
|||
auto string = vm.argument(0);
|
||||
|
||||
// OPTIMIZATION: We can skip the number-to-string-to-number round trip when the value is already a number.
|
||||
if (string.is_number())
|
||||
if (string.is_number()) {
|
||||
// Special case for negative zero - it should become positive zero
|
||||
if (string.is_negative_zero())
|
||||
return Value(0);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
// 1. Let inputString be ? ToString(string).
|
||||
auto input_string = TRY(string.to_string(vm));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue