Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Side by Side Diff: src/heap.cc

Issue 246077: Changed Object.keys to return strings for element indices. (Closed)
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 int int_value = FastD2I(value); 1575 int int_value = FastD2I(value);
1576 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { 1576 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
1577 return Smi::FromInt(int_value); 1577 return Smi::FromInt(int_value);
1578 } 1578 }
1579 1579
1580 // Materialize the value in the heap. 1580 // Materialize the value in the heap.
1581 return AllocateHeapNumber(value, pretenure); 1581 return AllocateHeapNumber(value, pretenure);
1582 } 1582 }
1583 1583
1584 1584
1585 Object* Heap::NumberToString(Object* number) {
1586 Object* cached = GetNumberStringCache(number);
1587 if (cached != undefined_value()) {
1588 return cached;
1589 }
1590
1591 char arr[100];
1592 Vector<char> buffer(arr, ARRAY_SIZE(arr));
1593 const char* str;
1594 if (number->IsSmi()) {
1595 int num = Smi::cast(number)->value();
1596 str = IntToCString(num, buffer);
1597 } else {
1598 double num = HeapNumber::cast(number)->value();
1599 str = DoubleToCString(num, buffer);
1600 }
1601 Object* result = AllocateStringFromAscii(CStrVector(str));
1602
1603 if (!result->IsFailure()) {
1604 SetNumberStringCache(number, String::cast(result));
1605 }
1606 return result;
1607 }
1608
1609
1585 Object* Heap::NewNumberFromDouble(double value, PretenureFlag pretenure) { 1610 Object* Heap::NewNumberFromDouble(double value, PretenureFlag pretenure) {
1586 return SmiOrNumberFromDouble(value, 1611 return SmiOrNumberFromDouble(value,
1587 true /* number object must be new */, 1612 true /* number object must be new */,
1588 pretenure); 1613 pretenure);
1589 } 1614 }
1590 1615
1591 1616
1592 Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { 1617 Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) {
1593 return SmiOrNumberFromDouble(value, 1618 return SmiOrNumberFromDouble(value,
1594 false /* use preallocated NaN, -0.0 */, 1619 false /* use preallocated NaN, -0.0 */,
(...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after
3827 for (int i = 0; i < kNumberOfCaches; i++) { 3852 for (int i = 0; i < kNumberOfCaches; i++) {
3828 if (caches_[i] != NULL) { 3853 if (caches_[i] != NULL) {
3829 delete caches_[i]; 3854 delete caches_[i];
3830 caches_[i] = NULL; 3855 caches_[i] = NULL;
3831 } 3856 }
3832 } 3857 }
3833 } 3858 }
3834 3859
3835 3860
3836 } } // namespace v8::internal 3861 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698