Chromium Code Reviews| 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 4134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4145 RUNTIME_ASSERT(number->IsNumber()); | 4145 RUNTIME_ASSERT(number->IsNumber()); |
| 4146 | 4146 |
| 4147 return Heap::NumberToString(number); | 4147 return Heap::NumberToString(number); |
| 4148 } | 4148 } |
| 4149 | 4149 |
| 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 Object* obj = args[0]; | 4155 CONVERT_DOUBLE_CHECKED(number, args[0]); |
| 4156 if (obj->IsSmi()) return obj; | 4156 |
| 4157 CONVERT_DOUBLE_CHECKED(number, obj); | 4157 // We do not include 0 so that we didn't have to treat +0 / -0 cases. |
|
Mads Ager (chromium)
2010/02/25 15:11:03
didn't -> don't
Oleg Eterevsky
2010/02/25 15:30:43
Done.
| |
| 4158 return Heap::NumberFromDouble(DoubleToInteger(number)); | 4158 if (number > 0 && number <= Smi::kMaxValue) |
|
Mads Ager (chromium)
2010/02/25 15:11:03
Please use braces around both the if and the else
Oleg Eterevsky
2010/02/25 15:30:43
Done.
| |
| 4159 return Smi::FromInt(static_cast<int>(number)); | |
| 4160 else | |
| 4161 return Heap::NumberFromDouble(DoubleToInteger(number)); | |
| 4159 } | 4162 } |
| 4160 | 4163 |
| 4161 | 4164 |
| 4162 static Object* Runtime_NumberToJSUint32(Arguments args) { | 4165 static Object* Runtime_NumberToJSUint32(Arguments args) { |
| 4163 NoHandleAllocation ha; | 4166 NoHandleAllocation ha; |
| 4164 ASSERT(args.length() == 1); | 4167 ASSERT(args.length() == 1); |
| 4165 | 4168 |
| 4166 Object* obj = args[0]; | 4169 Object* obj = args[0]; |
|
Mads Ager (chromium)
2010/02/25 15:11:03
Just use args[0] in the CONVERT_NUMBER_CHECKED bel
Oleg Eterevsky
2010/02/25 15:30:43
Done.
| |
| 4167 if (obj->IsSmi() && Smi::cast(obj)->value() >= 0) return obj; | |
| 4168 CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, obj); | 4170 CONVERT_NUMBER_CHECKED(int32_t, number, Uint32, obj); |
| 4169 return Heap::NumberFromUint32(number); | 4171 return Heap::NumberFromUint32(number); |
| 4170 } | 4172 } |
| 4171 | 4173 |
| 4172 | 4174 |
| 4173 static Object* Runtime_NumberToJSInt32(Arguments args) { | 4175 static Object* Runtime_NumberToJSInt32(Arguments args) { |
| 4174 NoHandleAllocation ha; | 4176 NoHandleAllocation ha; |
| 4175 ASSERT(args.length() == 1); | 4177 ASSERT(args.length() == 1); |
| 4176 | 4178 |
| 4177 Object* obj = args[0]; | 4179 CONVERT_DOUBLE_CHECKED(number, args[0]); |
| 4178 if (obj->IsSmi()) return obj; | 4180 if (number > 0 && number <= Smi::kMaxValue) |
|
Mads Ager (chromium)
2010/02/25 15:11:03
Please use braces here as well. Repeat the commen
Oleg Eterevsky
2010/02/25 15:30:43
Done.
| |
| 4179 CONVERT_DOUBLE_CHECKED(number, obj); | 4181 return Smi::FromInt(static_cast<int>(number)); |
| 4180 return Heap::NumberFromInt32(DoubleToInt32(number)); | 4182 else |
| 4183 return Heap::NumberFromInt32(DoubleToInt32(number)); | |
| 4181 } | 4184 } |
| 4182 | 4185 |
| 4183 | 4186 |
| 4184 // Converts a Number to a Smi, if possible. Returns NaN if the number is not | 4187 // Converts a Number to a Smi, if possible. Returns NaN if the number is not |
| 4185 // a small integer. | 4188 // a small integer. |
| 4186 static Object* Runtime_NumberToSmi(Arguments args) { | 4189 static Object* Runtime_NumberToSmi(Arguments args) { |
| 4187 NoHandleAllocation ha; | 4190 NoHandleAllocation ha; |
| 4188 ASSERT(args.length() == 1); | 4191 ASSERT(args.length() == 1); |
| 4189 | 4192 |
| 4190 Object* obj = args[0]; | 4193 Object* obj = args[0]; |
| (...skipping 4088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8279 } else { | 8282 } else { |
| 8280 // Handle last resort GC and make sure to allow future allocations | 8283 // Handle last resort GC and make sure to allow future allocations |
| 8281 // to grow the heap without causing GCs (if possible). | 8284 // to grow the heap without causing GCs (if possible). |
| 8282 Counters::gc_last_resort_from_js.Increment(); | 8285 Counters::gc_last_resort_from_js.Increment(); |
| 8283 Heap::CollectAllGarbage(false); | 8286 Heap::CollectAllGarbage(false); |
| 8284 } | 8287 } |
| 8285 } | 8288 } |
| 8286 | 8289 |
| 8287 | 8290 |
| 8288 } } // namespace v8::internal | 8291 } } // namespace v8::internal |
| OLD | NEW |