mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 22:30:31 +00:00
LibJS: Do not generate a format string in Number.prototype.toFixed
We can use the placeholder syntax to specify the precision dynamically. Note that `fraction_digits` is a double, which we do not support as a precision argument. It's safe to cast to an integer here because we guaranteed above that the value is in the range [0, 100], and is not fractional.
This commit is contained in:
parent
64d290447c
commit
d5222e9bba
Notes:
github-actions[bot]
2025-04-09 00:01:25 +00:00
Author: https://github.com/trflynn89
Commit: d5222e9bba
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4286
1 changed files with 1 additions and 2 deletions
|
@ -256,8 +256,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
|
||||||
// `number` double. Instead of generating a huge, unwieldy `n`, we format
|
// `number` double. Instead of generating a huge, unwieldy `n`, we format
|
||||||
// the double using our existing formatting code.
|
// the double using our existing formatting code.
|
||||||
|
|
||||||
auto number_format_string = ByteString::formatted("{{}}{{:.{}f}}", fraction_digits);
|
return PrimitiveString::create(vm, MUST(String::formatted("{}{:.{}f}", s, number, static_cast<u32>(fraction_digits))));
|
||||||
return PrimitiveString::create(vm, ByteString::formatted(number_format_string, s, number));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 20.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
|
// 20.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue