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 4139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4150 | 4150 |
4151 static Object* Runtime_NumberToInteger(Arguments args) { | 4151 static Object* Runtime_NumberToInteger(Arguments args) { |
4152 NoHandleAllocation ha; | 4152 NoHandleAllocation ha; |
4153 ASSERT(args.length() == 1); | 4153 ASSERT(args.length() == 1); |
4154 | 4154 |
4155 CONVERT_DOUBLE_CHECKED(number, args[0]); | 4155 CONVERT_DOUBLE_CHECKED(number, args[0]); |
4156 | 4156 |
4157 // We do not include 0 so that we don't have to treat +0 / -0 cases. | 4157 // We do not include 0 so that we don't have to treat +0 / -0 cases. |
4158 if (number > 0 && number <= Smi::kMaxValue) { | 4158 if (number > 0 && number <= Smi::kMaxValue) { |
4159 return Smi::FromInt(static_cast<int>(number)); | 4159 return Smi::FromInt(static_cast<int>(number)); |
4160 } else { | |
4161 return Heap::NumberFromDouble(DoubleToInteger(number)); | |
4162 } | 4160 } |
| 4161 return Heap::NumberFromDouble(DoubleToInteger(number)); |
4163 } | 4162 } |
4164 | 4163 |
4165 | 4164 |
4166 static Object* Runtime_NumberToJSUint32(Arguments args) { | 4165 static Object* Runtime_NumberToJSUint32(Arguments args) { |
4167 NoHandleAllocation ha; | 4166 NoHandleAllocation ha; |
4168 ASSERT(args.length() == 1); | 4167 ASSERT(args.length() == 1); |
4169 | 4168 |
4170 CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, args[0]); | 4169 CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, args[0]); |
4171 return Heap::NumberFromUint32(number); | 4170 return Heap::NumberFromUint32(number); |
4172 } | 4171 } |
4173 | 4172 |
4174 | 4173 |
4175 static Object* Runtime_NumberToJSInt32(Arguments args) { | 4174 static Object* Runtime_NumberToJSInt32(Arguments args) { |
4176 NoHandleAllocation ha; | 4175 NoHandleAllocation ha; |
4177 ASSERT(args.length() == 1); | 4176 ASSERT(args.length() == 1); |
4178 | 4177 |
4179 CONVERT_DOUBLE_CHECKED(number, args[0]); | 4178 CONVERT_DOUBLE_CHECKED(number, args[0]); |
4180 | 4179 |
4181 // We do not include 0 so that we don't have to treat +0 / -0 cases. | 4180 // We do not include 0 so that we don't have to treat +0 / -0 cases. |
4182 if (number > 0 && number <= Smi::kMaxValue) { | 4181 if (number > 0 && number <= Smi::kMaxValue) { |
4183 return Smi::FromInt(static_cast<int>(number)); | 4182 return Smi::FromInt(static_cast<int>(number)); |
4184 } else { | 4183 } |
4185 return Heap::NumberFromInt32(DoubleToInt32(number)); | 4184 return Heap::NumberFromInt32(DoubleToInt32(number)); |
4186 } | |
4187 } | 4185 } |
4188 | 4186 |
4189 | 4187 |
4190 // Converts a Number to a Smi, if possible. Returns NaN if the number is not | 4188 // Converts a Number to a Smi, if possible. Returns NaN if the number is not |
4191 // a small integer. | 4189 // a small integer. |
4192 static Object* Runtime_NumberToSmi(Arguments args) { | 4190 static Object* Runtime_NumberToSmi(Arguments args) { |
4193 NoHandleAllocation ha; | 4191 NoHandleAllocation ha; |
4194 ASSERT(args.length() == 1); | 4192 ASSERT(args.length() == 1); |
4195 | 4193 |
4196 Object* obj = args[0]; | 4194 Object* obj = args[0]; |
(...skipping 4136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8333 } else { | 8331 } else { |
8334 // Handle last resort GC and make sure to allow future allocations | 8332 // Handle last resort GC and make sure to allow future allocations |
8335 // to grow the heap without causing GCs (if possible). | 8333 // to grow the heap without causing GCs (if possible). |
8336 Counters::gc_last_resort_from_js.Increment(); | 8334 Counters::gc_last_resort_from_js.Increment(); |
8337 Heap::CollectAllGarbage(false); | 8335 Heap::CollectAllGarbage(false); |
8338 } | 8336 } |
8339 } | 8337 } |
8340 | 8338 |
8341 | 8339 |
8342 } } // namespace v8::internal | 8340 } } // namespace v8::internal |
OLD | NEW |