Index: src/runtime/runtime-numbers.cc |
diff --git a/src/runtime/runtime-numbers.cc b/src/runtime/runtime-numbers.cc |
index 9f43c0acfceeeff5bfec4d3fca72ebbf41830f2d..edd83bc5e80adb19b31ec41ff1dbe1a738658e54 100644 |
--- a/src/runtime/runtime-numbers.cc |
+++ b/src/runtime/runtime-numbers.cc |
@@ -12,6 +12,90 @@ |
namespace v8 { |
namespace internal { |
+ |
+RUNTIME_FUNCTION(Runtime_NumberToRadixString) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ CONVERT_SMI_ARG_CHECKED(radix, 1); |
+ CHECK(2 <= radix && radix <= 36); |
+ |
+ // Fast case where the result is a one character string. |
+ if (args[0]->IsSmi()) { |
+ int value = args.smi_at(0); |
+ if (value >= 0 && value < radix) { |
+ // Character array used for conversion. |
+ static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
+ return *isolate->factory()->LookupSingleCharacterStringFromCode( |
+ kCharTable[value]); |
+ } |
+ } |
+ |
+ // Slow case. |
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
+ if (std::isnan(value)) { |
+ return isolate->heap()->nan_string(); |
+ } |
+ if (std::isinf(value)) { |
+ if (value < 0) { |
+ return isolate->heap()->minus_infinity_string(); |
+ } |
+ return isolate->heap()->infinity_string(); |
+ } |
+ char* str = DoubleToRadixCString(value, radix); |
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
+ DeleteArray(str); |
+ return *result; |
+} |
+ |
+ |
+RUNTIME_FUNCTION(Runtime_NumberToFixed) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ |
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
+ CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); |
+ int f = FastD2IChecked(f_number); |
+ // See DoubleToFixedCString for these constants: |
+ CHECK(f >= 0 && f <= 20); |
+ CHECK(!Double(value).IsSpecial()); |
+ char* str = DoubleToFixedCString(value, f); |
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
+ DeleteArray(str); |
+ return *result; |
+} |
+ |
+ |
+RUNTIME_FUNCTION(Runtime_NumberToExponential) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ |
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
+ CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); |
+ int f = FastD2IChecked(f_number); |
+ CHECK(f >= -1 && f <= 20); |
+ CHECK(!Double(value).IsSpecial()); |
+ char* str = DoubleToExponentialCString(value, f); |
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
+ DeleteArray(str); |
+ return *result; |
+} |
+ |
+ |
+RUNTIME_FUNCTION(Runtime_NumberToPrecision) { |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ |
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
+ CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); |
+ int f = FastD2IChecked(f_number); |
+ CHECK(f >= 1 && f <= 21); |
+ CHECK(!Double(value).IsSpecial()); |
+ char* str = DoubleToPrecisionCString(value, f); |
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
+ DeleteArray(str); |
+ return *result; |
+} |
+ |
RUNTIME_FUNCTION(Runtime_IsValidSmi) { |
SealHandleScope shs(isolate); |