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 4721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4732 | 4732 |
4733 | 4733 |
4734 static Object* Runtime_StringParseInt(Arguments args) { | 4734 static Object* Runtime_StringParseInt(Arguments args) { |
4735 NoHandleAllocation ha; | 4735 NoHandleAllocation ha; |
4736 | 4736 |
4737 CONVERT_CHECKED(String, s, args[0]); | 4737 CONVERT_CHECKED(String, s, args[0]); |
4738 CONVERT_SMI_CHECKED(radix, args[1]); | 4738 CONVERT_SMI_CHECKED(radix, args[1]); |
4739 | 4739 |
4740 s->TryFlatten(); | 4740 s->TryFlatten(); |
4741 | 4741 |
4742 int len = s->length(); | 4742 RUNTIME_ASSERT(radix == 0 || (2 <= radix && radix <= 36)); |
4743 int i; | 4743 double value = StringToInt(s, radix); |
4744 | 4744 return Heap::NumberFromDouble(value); |
4745 // Skip leading white space. | |
4746 for (i = 0; i < len && Scanner::kIsWhiteSpace.get(s->Get(i)); i++) ; | |
4747 if (i == len) return Heap::nan_value(); | |
4748 | |
4749 // Compute the sign (default to +). | |
4750 int sign = 1; | |
4751 if (s->Get(i) == '-') { | |
4752 sign = -1; | |
4753 i++; | |
4754 } else if (s->Get(i) == '+') { | |
4755 i++; | |
4756 } | |
4757 | |
4758 // Compute the radix if 0. | |
4759 if (radix == 0) { | |
4760 radix = 10; | |
4761 if (i < len && s->Get(i) == '0') { | |
4762 radix = 8; | |
4763 if (i + 1 < len) { | |
4764 int c = s->Get(i + 1); | |
4765 if (c == 'x' || c == 'X') { | |
4766 radix = 16; | |
4767 i += 2; | |
4768 } | |
4769 } | |
4770 } | |
4771 } else if (radix == 16) { | |
4772 // Allow 0x or 0X prefix if radix is 16. | |
4773 if (i + 1 < len && s->Get(i) == '0') { | |
4774 int c = s->Get(i + 1); | |
4775 if (c == 'x' || c == 'X') i += 2; | |
4776 } | |
4777 } | |
4778 | |
4779 RUNTIME_ASSERT(2 <= radix && radix <= 36); | |
4780 double value; | |
4781 int end_index = StringToInt(s, i, radix, &value); | |
4782 if (end_index != i) { | |
4783 return Heap::NumberFromDouble(sign * value); | |
4784 } | |
4785 return Heap::nan_value(); | 4745 return Heap::nan_value(); |
4786 } | 4746 } |
4787 | 4747 |
4788 | 4748 |
4789 static Object* Runtime_StringParseFloat(Arguments args) { | 4749 static Object* Runtime_StringParseFloat(Arguments args) { |
4790 NoHandleAllocation ha; | 4750 NoHandleAllocation ha; |
4791 CONVERT_CHECKED(String, str, args[0]); | 4751 CONVERT_CHECKED(String, str, args[0]); |
4792 | 4752 |
4793 // ECMA-262 section 15.1.2.3, empty string is NaN | 4753 // ECMA-262 section 15.1.2.3, empty string is NaN |
4794 double value = StringToDouble(str, ALLOW_TRAILING_JUNK, OS::nan_value()); | 4754 double value = StringToDouble(str, ALLOW_TRAILING_JUNK, OS::nan_value()); |
(...skipping 5297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10092 } else { | 10052 } else { |
10093 // Handle last resort GC and make sure to allow future allocations | 10053 // Handle last resort GC and make sure to allow future allocations |
10094 // to grow the heap without causing GCs (if possible). | 10054 // to grow the heap without causing GCs (if possible). |
10095 Counters::gc_last_resort_from_js.Increment(); | 10055 Counters::gc_last_resort_from_js.Increment(); |
10096 Heap::CollectAllGarbage(false); | 10056 Heap::CollectAllGarbage(false); |
10097 } | 10057 } |
10098 } | 10058 } |
10099 | 10059 |
10100 | 10060 |
10101 } } // namespace v8::internal | 10061 } } // namespace v8::internal |
OLD | NEW |