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 |
11 "use strict"; | 11 "use strict"; |
12 | 12 |
13 %CheckIsBootstrapping(); | 13 %CheckIsBootstrapping(); |
14 | 14 |
15 // ------------------------------------------------------------------- | 15 // ------------------------------------------------------------------- |
16 // Imports | 16 // Imports |
17 | 17 |
18 var GlobalDate = global.Date; | 18 var GlobalDate = global.Date; |
19 var GlobalObject = global.Object; | 19 var GlobalObject = global.Object; |
20 var InternalArray = utils.InternalArray; | 20 var InternalArray = utils.InternalArray; |
21 var IsFinite; | 21 var IsFinite; |
22 var MathAbs; | 22 var MathAbs; |
23 var MathFloor; | 23 var MathFloor; |
24 var ToNumber; | 24 var ToNumber; |
25 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); | |
26 var ToString; | 25 var ToString; |
27 | 26 |
28 utils.Import(function(from) { | 27 utils.Import(function(from) { |
29 IsFinite = from.IsFinite; | 28 IsFinite = from.IsFinite; |
30 MathAbs = from.MathAbs; | 29 MathAbs = from.MathAbs; |
31 MathFloor = from.MathFloor; | 30 MathFloor = from.MathFloor; |
32 ToNumber = from.ToNumber; | 31 ToNumber = from.ToNumber; |
33 ToString = from.ToString; | 32 ToString = from.ToString; |
34 }); | 33 }); |
35 | 34 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 142 |
144 // ECMA 262 - 15.9.3 | 143 // ECMA 262 - 15.9.3 |
145 var argc = %_ArgumentsLength(); | 144 var argc = %_ArgumentsLength(); |
146 var value; | 145 var value; |
147 if (argc == 0) { | 146 if (argc == 0) { |
148 value = %DateCurrentTime(); | 147 value = %DateCurrentTime(); |
149 SET_UTC_DATE_VALUE(this, value); | 148 SET_UTC_DATE_VALUE(this, value); |
150 } else if (argc == 1) { | 149 } else if (argc == 1) { |
151 if (IS_NUMBER(year)) { | 150 if (IS_NUMBER(year)) { |
152 value = year; | 151 value = year; |
| 152 |
153 } else if (IS_STRING(year)) { | 153 } else if (IS_STRING(year)) { |
154 // Probe the Date cache. If we already have a time value for the | 154 // Probe the Date cache. If we already have a time value for the |
155 // given time, we re-use that instead of parsing the string again. | 155 // given time, we re-use that instead of parsing the string again. |
156 CheckDateCacheCurrent(); | 156 CheckDateCacheCurrent(); |
157 var cache = Date_cache; | 157 var cache = Date_cache; |
158 if (cache.string === year) { | 158 if (cache.string === year) { |
159 value = cache.time; | 159 value = cache.time; |
160 } else { | 160 } else { |
161 value = DateParse(year); | 161 value = DateParse(year); |
162 if (!NUMBER_IS_NAN(value)) { | 162 if (!NUMBER_IS_NAN(value)) { |
163 cache.time = value; | 163 cache.time = value; |
164 cache.string = year; | 164 cache.string = year; |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
| 168 } else if (IS_DATE(year)) { |
| 169 value = UTC_DATE_VALUE(year); |
| 170 |
168 } else { | 171 } else { |
169 // According to ECMA 262, no hint should be given for this | 172 var time = TO_PRIMITIVE(year); |
170 // conversion. However, ToPrimitive defaults to STRING_HINT for | |
171 // Date objects which will lose precision when the Date | |
172 // constructor is called with another Date object as its | |
173 // argument. We therefore use NUMBER_HINT for the conversion, | |
174 // which is the default for everything else than Date objects. | |
175 // This makes us behave like KJS and SpiderMonkey. | |
176 var time = $toPrimitive(year, NUMBER_HINT); | |
177 value = IS_STRING(time) ? DateParse(time) : ToNumber(time); | 173 value = IS_STRING(time) ? DateParse(time) : ToNumber(time); |
178 } | 174 } |
179 SET_UTC_DATE_VALUE(this, value); | 175 SET_UTC_DATE_VALUE(this, value); |
180 } else { | 176 } else { |
181 year = ToNumber(year); | 177 year = ToNumber(year); |
182 month = ToNumber(month); | 178 month = ToNumber(month); |
183 date = argc > 2 ? ToNumber(date) : 1; | 179 date = argc > 2 ? ToNumber(date) : 1; |
184 hours = argc > 3 ? ToNumber(hours) : 0; | 180 hours = argc > 3 ? ToNumber(hours) : 0; |
185 minutes = argc > 4 ? ToNumber(minutes) : 0; | 181 minutes = argc > 4 ? ToNumber(minutes) : 0; |
186 seconds = argc > 5 ? ToNumber(seconds) : 0; | 182 seconds = argc > 5 ? ToNumber(seconds) : 0; |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 "toUTCString", DateToUTCString, | 878 "toUTCString", DateToUTCString, |
883 "getYear", DateGetYear, | 879 "getYear", DateGetYear, |
884 "setYear", DateSetYear, | 880 "setYear", DateSetYear, |
885 "toISOString", DateToISOString, | 881 "toISOString", DateToISOString, |
886 "toJSON", DateToJSON | 882 "toJSON", DateToJSON |
887 ]); | 883 ]); |
888 | 884 |
889 %InstallToContext(["create_date_fun", CreateDate]); | 885 %InstallToContext(["create_date_fun", CreateDate]); |
890 | 886 |
891 }) | 887 }) |
OLD | NEW |