| OLD | NEW |
| 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 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 // It's okay to skip the write barrier here because the literals | 1631 // It's okay to skip the write barrier here because the literals |
| 1632 // are guaranteed to be in old space. | 1632 // are guaranteed to be in old space. |
| 1633 target->set_literals(*literals, SKIP_WRITE_BARRIER); | 1633 target->set_literals(*literals, SKIP_WRITE_BARRIER); |
| 1634 } | 1634 } |
| 1635 | 1635 |
| 1636 target->set_context(*context); | 1636 target->set_context(*context); |
| 1637 return *target; | 1637 return *target; |
| 1638 } | 1638 } |
| 1639 | 1639 |
| 1640 | 1640 |
| 1641 static Object* CharCodeAt(String* subject, Object* index) { | |
| 1642 uint32_t i = 0; | |
| 1643 if (!index->ToArrayIndex(&i)) return Heap::nan_value(); | |
| 1644 // Flatten the string. If someone wants to get a char at an index | |
| 1645 // in a cons string, it is likely that more indices will be | |
| 1646 // accessed. | |
| 1647 Object* flat = subject->TryFlatten(); | |
| 1648 if (flat->IsFailure()) return flat; | |
| 1649 subject = String::cast(flat); | |
| 1650 if (i >= static_cast<uint32_t>(subject->length())) { | |
| 1651 return Heap::nan_value(); | |
| 1652 } | |
| 1653 return Smi::FromInt(subject->Get(i)); | |
| 1654 } | |
| 1655 | |
| 1656 | |
| 1657 static Object* CharFromCode(Object* char_code) { | 1641 static Object* CharFromCode(Object* char_code) { |
| 1658 uint32_t code; | 1642 uint32_t code; |
| 1659 if (char_code->ToArrayIndex(&code)) { | 1643 if (char_code->ToArrayIndex(&code)) { |
| 1660 if (code <= 0xffff) { | 1644 if (code <= 0xffff) { |
| 1661 return Heap::LookupSingleCharacterStringFromCode(code); | 1645 return Heap::LookupSingleCharacterStringFromCode(code); |
| 1662 } | 1646 } |
| 1663 } | 1647 } |
| 1664 return Heap::empty_string(); | 1648 return Heap::empty_string(); |
| 1665 } | 1649 } |
| 1666 | 1650 |
| 1667 | 1651 |
| 1668 static Object* Runtime_StringCharCodeAt(Arguments args) { | 1652 static Object* Runtime_StringCharCodeAt(Arguments args) { |
| 1669 NoHandleAllocation ha; | 1653 NoHandleAllocation ha; |
| 1670 ASSERT(args.length() == 2); | 1654 ASSERT(args.length() == 2); |
| 1671 | 1655 |
| 1672 CONVERT_CHECKED(String, subject, args[0]); | 1656 CONVERT_CHECKED(String, subject, args[0]); |
| 1673 Object* index = args[1]; | 1657 Object* index = args[1]; |
| 1674 return CharCodeAt(subject, index); | 1658 RUNTIME_ASSERT(index->IsNumber()); |
| 1659 |
| 1660 uint32_t i = 0; |
| 1661 if (index->IsSmi()) { |
| 1662 int value = Smi::cast(index)->value(); |
| 1663 if (value < 0) return Heap::nan_value(); |
| 1664 i = value; |
| 1665 } else { |
| 1666 ASSERT(index->IsHeapNumber()); |
| 1667 double value = HeapNumber::cast(index)->value(); |
| 1668 i = static_cast<uint32_t>(value); |
| 1669 } |
| 1670 |
| 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 |
| 1673 // accessed. |
| 1674 Object* flat = subject->TryFlatten(); |
| 1675 if (flat->IsFailure()) return flat; |
| 1676 subject = String::cast(flat); |
| 1677 |
| 1678 if (i >= static_cast<uint32_t>(subject->length())) { |
| 1679 return Heap::nan_value(); |
| 1680 } |
| 1681 |
| 1682 return Smi::FromInt(subject->Get(i)); |
| 1675 } | 1683 } |
| 1676 | 1684 |
| 1677 | 1685 |
| 1678 static Object* Runtime_StringCharAt(Arguments args) { | |
| 1679 NoHandleAllocation ha; | |
| 1680 ASSERT(args.length() == 2); | |
| 1681 | |
| 1682 CONVERT_CHECKED(String, subject, args[0]); | |
| 1683 Object* index = args[1]; | |
| 1684 Object* code = CharCodeAt(subject, index); | |
| 1685 if (code == Heap::nan_value()) { | |
| 1686 return Heap::undefined_value(); | |
| 1687 } | |
| 1688 return CharFromCode(code); | |
| 1689 } | |
| 1690 | |
| 1691 | |
| 1692 static Object* Runtime_CharFromCode(Arguments args) { | 1686 static Object* Runtime_CharFromCode(Arguments args) { |
| 1693 NoHandleAllocation ha; | 1687 NoHandleAllocation ha; |
| 1694 ASSERT(args.length() == 1); | 1688 ASSERT(args.length() == 1); |
| 1695 return CharFromCode(args[0]); | 1689 return CharFromCode(args[0]); |
| 1696 } | 1690 } |
| 1697 | 1691 |
| 1698 | 1692 |
| 1699 class FixedArrayBuilder { | 1693 class FixedArrayBuilder { |
| 1700 public: | 1694 public: |
| 1701 explicit FixedArrayBuilder(int initial_capacity) | 1695 explicit FixedArrayBuilder(int initial_capacity) |
| (...skipping 3635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5337 CONVERT_DOUBLE_CHECKED(number, args[0]); | 5331 CONVERT_DOUBLE_CHECKED(number, args[0]); |
| 5338 | 5332 |
| 5339 // We do not include 0 so that we don't have to treat +0 / -0 cases. | 5333 // We do not include 0 so that we don't have to treat +0 / -0 cases. |
| 5340 if (number > 0 && number <= Smi::kMaxValue) { | 5334 if (number > 0 && number <= Smi::kMaxValue) { |
| 5341 return Smi::FromInt(static_cast<int>(number)); | 5335 return Smi::FromInt(static_cast<int>(number)); |
| 5342 } | 5336 } |
| 5343 return Heap::NumberFromDouble(DoubleToInteger(number)); | 5337 return Heap::NumberFromDouble(DoubleToInteger(number)); |
| 5344 } | 5338 } |
| 5345 | 5339 |
| 5346 | 5340 |
| 5341 |
| 5342 |
| 5343 |
| 5347 static Object* Runtime_NumberToIntegerMapMinusZero(Arguments args) { | 5344 static Object* Runtime_NumberToIntegerMapMinusZero(Arguments args) { |
| 5348 NoHandleAllocation ha; | 5345 NoHandleAllocation ha; |
| 5349 ASSERT(args.length() == 1); | 5346 ASSERT(args.length() == 1); |
| 5350 | 5347 |
| 5351 CONVERT_DOUBLE_CHECKED(number, args[0]); | 5348 CONVERT_DOUBLE_CHECKED(number, args[0]); |
| 5352 | 5349 |
| 5353 // We do not include 0 so that we don't have to treat +0 / -0 cases. | 5350 // We do not include 0 so that we don't have to treat +0 / -0 cases. |
| 5354 if (number > 0 && number <= Smi::kMaxValue) { | 5351 if (number > 0 && number <= Smi::kMaxValue) { |
| 5355 return Smi::FromInt(static_cast<int>(number)); | 5352 return Smi::FromInt(static_cast<int>(number)); |
| 5356 } | 5353 } |
| (...skipping 4950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10307 } else { | 10304 } else { |
| 10308 // Handle last resort GC and make sure to allow future allocations | 10305 // Handle last resort GC and make sure to allow future allocations |
| 10309 // to grow the heap without causing GCs (if possible). | 10306 // to grow the heap without causing GCs (if possible). |
| 10310 Counters::gc_last_resort_from_js.Increment(); | 10307 Counters::gc_last_resort_from_js.Increment(); |
| 10311 Heap::CollectAllGarbage(false); | 10308 Heap::CollectAllGarbage(false); |
| 10312 } | 10309 } |
| 10313 } | 10310 } |
| 10314 | 10311 |
| 10315 | 10312 |
| 10316 } } // namespace v8::internal | 10313 } } // namespace v8::internal |
| OLD | NEW |