| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var $createDate; | 5 var $createDate; |
| 6 | 6 |
| 7 // ------------------------------------------------------------------- | 7 // ------------------------------------------------------------------- |
| 8 | 8 |
| 9 (function(global, utils) { | 9 (function(global, utils) { |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // TimeClip to do it. | 109 // TimeClip to do it. |
| 110 if (MathAbs(time) > MAX_TIME_BEFORE_UTC) return NAN; | 110 if (MathAbs(time) > MAX_TIME_BEFORE_UTC) return NAN; |
| 111 return time; | 111 return time; |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 // ECMA 262 - 15.9.1.14 | 115 // ECMA 262 - 15.9.1.14 |
| 116 function TimeClip(time) { | 116 function TimeClip(time) { |
| 117 if (!IsFinite(time)) return NAN; | 117 if (!IsFinite(time)) return NAN; |
| 118 if (MathAbs(time) > MAX_TIME_MS) return NAN; | 118 if (MathAbs(time) > MAX_TIME_MS) return NAN; |
| 119 return TO_INTEGER(time); | 119 return TO_INTEGER(time) + 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 // The Date cache is used to limit the cost of parsing the same Date | 123 // The Date cache is used to limit the cost of parsing the same Date |
| 124 // strings over and over again. | 124 // strings over and over again. |
| 125 var Date_cache = { | 125 var Date_cache = { |
| 126 // Cached time value. | 126 // Cached time value. |
| 127 time: 0, | 127 time: 0, |
| 128 // String input for which the cached time is valid. | 128 // String input for which the cached time is valid. |
| 129 string: null | 129 string: null |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 | 132 |
| 133 function DateConstructor(year, month, date, hours, minutes, seconds, ms) { | 133 function DateConstructor(year, month, date, hours, minutes, seconds, ms) { |
| 134 if (!%_IsConstructCall()) { | 134 if (!%_IsConstructCall()) { |
| 135 // ECMA 262 - 15.9.2 | 135 // ECMA 262 - 15.9.2 |
| 136 return %_CallFunction(new GlobalDate(), DateToString); | 136 return %_CallFunction(new GlobalDate(), DateToString); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // ECMA 262 - 15.9.3 | 139 // ECMA 262 - 15.9.3 |
| 140 var argc = %_ArgumentsLength(); | 140 var argc = %_ArgumentsLength(); |
| 141 var value; | 141 var value; |
| 142 if (argc == 0) { | 142 if (argc == 0) { |
| 143 value = %DateCurrentTime(); | 143 value = %DateCurrentTime(); |
| 144 SET_UTC_DATE_VALUE(this, value); | 144 SET_UTC_DATE_VALUE(this, value); |
| 145 } else if (argc == 1) { | 145 } else if (argc == 1) { |
| 146 if (IS_NUMBER(year)) { | 146 if (IS_NUMBER(year)) { |
| 147 value = year; | 147 value = TimeClip(year); |
| 148 | 148 |
| 149 } else if (IS_STRING(year)) { | 149 } else if (IS_STRING(year)) { |
| 150 // Probe the Date cache. If we already have a time value for the | 150 // Probe the Date cache. If we already have a time value for the |
| 151 // given time, we re-use that instead of parsing the string again. | 151 // given time, we re-use that instead of parsing the string again. |
| 152 CheckDateCacheCurrent(); | 152 CheckDateCacheCurrent(); |
| 153 var cache = Date_cache; | 153 var cache = Date_cache; |
| 154 if (cache.string === year) { | 154 if (cache.string === year) { |
| 155 value = cache.time; | 155 value = cache.time; |
| 156 } else { | 156 } else { |
| 157 value = DateParse(year); | 157 value = DateParse(year); |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 "toUTCString", DateToUTCString, | 874 "toUTCString", DateToUTCString, |
| 875 "getYear", DateGetYear, | 875 "getYear", DateGetYear, |
| 876 "setYear", DateSetYear, | 876 "setYear", DateSetYear, |
| 877 "toISOString", DateToISOString, | 877 "toISOString", DateToISOString, |
| 878 "toJSON", DateToJSON | 878 "toJSON", DateToJSON |
| 879 ]); | 879 ]); |
| 880 | 880 |
| 881 %InstallToContext(["create_date_fun", CreateDate]); | 881 %InstallToContext(["create_date_fun", CreateDate]); |
| 882 | 882 |
| 883 }) | 883 }) |
| OLD | NEW |