mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:37:34 +00:00
LibJS: Make Number.prototype.toString() radix coercion spec compliant
This should use the ToIntegerOrInfinity() abstract operation.
This commit is contained in:
parent
adc3de4480
commit
887852f36d
1 changed files with 6 additions and 5 deletions
|
@ -61,13 +61,14 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
int radix;
|
double radix_argument = 10;
|
||||||
auto argument = vm.argument(0);
|
auto argument = vm.argument(0);
|
||||||
if (argument.is_undefined()) {
|
if (!vm.argument(0).is_undefined()) {
|
||||||
radix = 10;
|
radix_argument = argument.to_integer_or_infinity(global_object);
|
||||||
} else {
|
if (vm.exception())
|
||||||
radix = argument.to_i32(global_object);
|
return {};
|
||||||
}
|
}
|
||||||
|
int radix = (int)radix_argument;
|
||||||
|
|
||||||
if (vm.exception() || radix < 2 || radix > 36) {
|
if (vm.exception() || radix < 2 || radix > 36) {
|
||||||
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidRadix);
|
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidRadix);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue