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 4951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4962 year += month / 12; | 4962 year += month / 12; |
4963 month %= 12; | 4963 month %= 12; |
4964 if (month < 0) { | 4964 if (month < 0) { |
4965 year--; | 4965 year--; |
4966 month += 12; | 4966 month += 12; |
4967 } | 4967 } |
4968 | 4968 |
4969 ASSERT(month >= 0); | 4969 ASSERT(month >= 0); |
4970 ASSERT(month < 12); | 4970 ASSERT(month < 12); |
4971 | 4971 |
4972 static const int base_day = 365*1969 + 1969/4 - 1969/100 + 1969/400; | 4972 // year_delta is an arbitrary number such that: |
4973 int year1 = year - 1; | 4973 // a) year_delta = -1 (mod 400) |
4974 int day_from_year = 365 * year1 + year1 / 4 - year1 / 100 + year1 / 400 - | 4974 // b) year + year_delta > 0 for years in the range defined by |
| 4975 // ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of |
| 4976 // Jan 1 1970. This is required so that we don't run into integer |
| 4977 // division of negative numbers. |
| 4978 // c) there shouldn't be overflow for 32-bit integers in the following |
| 4979 // operations. |
| 4980 static const int year_delta = 399999; |
| 4981 static const int base_day = 365 * (1970 + year_delta) + |
| 4982 (1970 + year_delta) / 4 - |
| 4983 (1970 + year_delta) / 100 + |
| 4984 (1970 + year_delta) / 400; |
| 4985 |
| 4986 int year1 = year + year_delta; |
| 4987 int day_from_year = 365 * year1 + |
| 4988 year1 / 4 - |
| 4989 year1 / 100 + |
| 4990 year1 / 400 - |
4975 base_day; | 4991 base_day; |
4976 | 4992 |
4977 if (year % 4 || (year % 100 == 0 && year % 400 != 0)) { | 4993 if (year % 4 || (year % 100 == 0 && year % 400 != 0)) { |
4978 return Smi::FromInt(day_from_year + day_from_month[month] + date - 1); | 4994 return Smi::FromInt(day_from_year + day_from_month[month] + date - 1); |
4979 } | 4995 } |
4980 | 4996 |
4981 return Smi::FromInt(day_from_year + day_from_month_leap[month] + date - 1); | 4997 return Smi::FromInt(day_from_year + day_from_month_leap[month] + date - 1); |
4982 } | 4998 } |
4983 | 4999 |
4984 | 5000 |
(...skipping 3414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8399 } else { | 8415 } else { |
8400 // Handle last resort GC and make sure to allow future allocations | 8416 // Handle last resort GC and make sure to allow future allocations |
8401 // to grow the heap without causing GCs (if possible). | 8417 // to grow the heap without causing GCs (if possible). |
8402 Counters::gc_last_resort_from_js.Increment(); | 8418 Counters::gc_last_resort_from_js.Increment(); |
8403 Heap::CollectAllGarbage(false); | 8419 Heap::CollectAllGarbage(false); |
8404 } | 8420 } |
8405 } | 8421 } |
8406 | 8422 |
8407 | 8423 |
8408 } } // namespace v8::internal | 8424 } } // namespace v8::internal |
OLD | NEW |