From 887852f36db075eb7855de18e53ec8269ba0d35c Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 6 Jun 2021 07:03:12 +0100 Subject: [PATCH] LibJS: Make Number.prototype.toString() radix coercion spec compliant This should use the ToIntegerOrInfinity() abstract operation. --- Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index eda66d8609..568275dee4 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -61,13 +61,14 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) if (vm.exception()) return {}; - int radix; + double radix_argument = 10; auto argument = vm.argument(0); - if (argument.is_undefined()) { - radix = 10; - } else { - radix = argument.to_i32(global_object); + if (!vm.argument(0).is_undefined()) { + radix_argument = argument.to_integer_or_infinity(global_object); + if (vm.exception()) + return {}; } + int radix = (int)radix_argument; if (vm.exception() || radix < 2 || radix > 36) { vm.throw_exception(global_object, ErrorType::InvalidRadix);