Index: src/heap.cc |
diff --git a/src/heap.cc b/src/heap.cc |
index cf7a0463f411ff393ab595e5a457b30bbb5692aa..d1f8e9f7224c494690fa917c7546b17408c8debc 100644 |
--- a/src/heap.cc |
+++ b/src/heap.cc |
@@ -1582,6 +1582,31 @@ Object* Heap::SmiOrNumberFromDouble(double value, |
} |
+Object* Heap::NumberToString(Object* number) { |
+ Object* cached = GetNumberStringCache(number); |
+ if (cached != undefined_value()) { |
+ return cached; |
+ } |
+ |
+ char arr[100]; |
+ Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
+ const char* str; |
+ if (number->IsSmi()) { |
+ int num = Smi::cast(number)->value(); |
+ str = IntToCString(num, buffer); |
+ } else { |
+ double num = HeapNumber::cast(number)->value(); |
+ str = DoubleToCString(num, buffer); |
+ } |
+ Object* result = AllocateStringFromAscii(CStrVector(str)); |
+ |
+ if (!result->IsFailure()) { |
+ SetNumberStringCache(number, String::cast(result)); |
+ } |
+ return result; |
+} |
+ |
+ |
Object* Heap::NewNumberFromDouble(double value, PretenureFlag pretenure) { |
return SmiOrNumberFromDouble(value, |
true /* number object must be new */, |