Index: src/runtime/runtime-numbers.cc |
diff --git a/src/runtime/runtime-numbers.cc b/src/runtime/runtime-numbers.cc |
index 9f43c0acfceeeff5bfec4d3fca72ebbf41830f2d..1c8c91d126a6356f56335fd9b6301100b635ae09 100644 |
--- a/src/runtime/runtime-numbers.cc |
+++ b/src/runtime/runtime-numbers.cc |
@@ -74,10 +74,21 @@ RUNTIME_FUNCTION(Runtime_StringParseFloat) { |
RUNTIME_FUNCTION(Runtime_NumberToString) { |
HandleScope scope(isolate); |
- DCHECK(args.length() == 1); |
- CONVERT_NUMBER_ARG_HANDLE_CHECKED(number, 0); |
- |
- return *isolate->factory()->NumberToString(number); |
+ DCHECK_LE(1, args.length()); |
+ DCHECK_GE(2, args.length()); |
+ CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 0); |
+ if (args.length() == 1) return *isolate->factory()->NumberToString(value); |
+ double value_number = value->Number(); |
+ CONVERT_INT32_ARG_CHECKED(radix, 1); |
+ if (std::isnan(value_number)) return isolate->heap()->nan_string(); |
+ if (std::isinf(value_number)) { |
+ return (value_number < 0.0) ? isolate->heap()->minus_infinity_string() |
+ : isolate->heap()->infinity_string(); |
+ } |
+ char* const str = DoubleToRadixCString(value_number, radix); |
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
+ DeleteArray(str); |
+ return *result; |
} |