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

Side by Side Diff: src/runtime.cc

Issue 2577001: Fix double to integer conversions in runtime string indexing. (Closed)
Patch Set: Created 10 years, 6 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 | « no previous file | test/mjsunit/string-charat.js » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 RUNTIME_ASSERT(index->IsNumber()); 1658 RUNTIME_ASSERT(index->IsNumber());
1659 1659
1660 uint32_t i = 0; 1660 uint32_t i = 0;
1661 if (index->IsSmi()) { 1661 if (index->IsSmi()) {
1662 int value = Smi::cast(index)->value(); 1662 int value = Smi::cast(index)->value();
1663 if (value < 0) return Heap::nan_value(); 1663 if (value < 0) return Heap::nan_value();
1664 i = value; 1664 i = value;
1665 } else { 1665 } else {
1666 ASSERT(index->IsHeapNumber()); 1666 ASSERT(index->IsHeapNumber());
1667 double value = HeapNumber::cast(index)->value(); 1667 double value = HeapNumber::cast(index)->value();
1668 i = static_cast<uint32_t>(value); 1668 i = static_cast<uint32_t>(DoubleToInteger(value));
1669 } 1669 }
1670 1670
1671 // Flatten the string. If someone wants to get a char at an index 1671 // Flatten the string. If someone wants to get a char at an index
1672 // in a cons string, it is likely that more indices will be 1672 // in a cons string, it is likely that more indices will be
1673 // accessed. 1673 // accessed.
1674 Object* flat = subject->TryFlatten(); 1674 Object* flat = subject->TryFlatten();
1675 if (flat->IsFailure()) return flat; 1675 if (flat->IsFailure()) return flat;
1676 subject = String::cast(flat); 1676 subject = String::cast(flat);
1677 1677
1678 if (i >= static_cast<uint32_t>(subject->length())) { 1678 if (i >= static_cast<uint32_t>(subject->length())) {
(...skipping 8625 matching lines...) Expand 10 before | Expand all | Expand 10 after
10304 } else { 10304 } else {
10305 // Handle last resort GC and make sure to allow future allocations 10305 // Handle last resort GC and make sure to allow future allocations
10306 // to grow the heap without causing GCs (if possible). 10306 // to grow the heap without causing GCs (if possible).
10307 Counters::gc_last_resort_from_js.Increment(); 10307 Counters::gc_last_resort_from_js.Increment();
10308 Heap::CollectAllGarbage(false); 10308 Heap::CollectAllGarbage(false);
10309 } 10309 }
10310 } 10310 }
10311 10311
10312 10312
10313 } } // namespace v8::internal 10313 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/string-charat.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698