Chromium Code Reviews| 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 // 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 + FLOOR((year-1601)/400); | 74 + FLOOR((year-1601)/400); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 function TimeFromYear(year) { | 78 function TimeFromYear(year) { |
| 79 return msPerDay * DayFromYear(year); | 79 return msPerDay * DayFromYear(year); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 function InLeapYear(time) { | 83 function InLeapYear(time) { |
| 84 return DaysInYear(YEAR_FROM_TIME(time)) == 366 ? 1 : 0; | 84 return DaysInYear(YearFromTime(time)) == 366 ? 1 : 0; |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 function DayWithinYear(time) { | 88 function DayWithinYear(time) { |
| 89 return DAY(time) - DayFromYear(YEAR_FROM_TIME(time)); | 89 return DAY(time) - DayFromYear(YearFromTime(time)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 // ECMA 262 - 15.9.1.9 | 93 // ECMA 262 - 15.9.1.9 |
| 94 function EquivalentYear(year) { | 94 function EquivalentYear(year) { |
| 95 // Returns an equivalent year in the range [2008-2035] matching | 95 // Returns an equivalent year in the range [2008-2035] matching |
| 96 // - leap year. | 96 // - leap year. |
| 97 // - week day of first day. | 97 // - week day of first day. |
| 98 var time = TimeFromYear(year); | 98 var time = TimeFromYear(year); |
| 99 var recent_year = (InLeapYear(time) == 0 ? 1967 : 1956) + | 99 var recent_year = (InLeapYear(time) == 0 ? 1967 : 1956) + |
| 100 (WeekDay(time) * 12) % 28; | 100 (WeekDay(time) * 12) % 28; |
| 101 // Find the year in the range 2008..2037 that is equivalent mod 28. | 101 // Find the year in the range 2008..2037 that is equivalent mod 28. |
| 102 // Add 3*28 to give a positive argument to the modulus operator. | 102 // Add 3*28 to give a positive argument to the modulus operator. |
| 103 return 2008 + (recent_year + 3*28 - 2008) % 28; | 103 return 2008 + (recent_year + 3*28 - 2008) % 28; |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 function EquivalentTime(t) { | 107 function EquivalentTime(t) { |
| 108 // The issue here is that some library calls don't work right for dates | 108 // The issue here is that some library calls don't work right for dates |
| 109 // that cannot be represented using a non-negative signed 32 bit integer | 109 // that cannot be represented using a non-negative signed 32 bit integer |
| 110 // (measured in whole seconds based on the 1970 epoch). | 110 // (measured in whole seconds based on the 1970 epoch). |
| 111 // We solve this by mapping the time to a year with same leap-year-ness | 111 // We solve this by mapping the time to a year with same leap-year-ness |
| 112 // and same starting day for the year. The ECMAscript specification says | 112 // and same starting day for the year. The ECMAscript specification says |
| 113 // we must do this, but for compatibility with other browsers, we use | 113 // we must do this, but for compatibility with other browsers, we use |
| 114 // the actual year if it is in the range 1970..2037 | 114 // the actual year if it is in the range 1970..2037 |
| 115 if (t >= 0 && t <= 2.1e12) return t; | 115 if (t >= 0 && t <= 2.1e12) return t; |
| 116 | 116 |
| 117 var day = MakeDay(EquivalentYear(YEAR_FROM_TIME(t)), | 117 var day = MakeDay(EquivalentYear(YearFromTime(t)), |
| 118 MONTH_FROM_TIME(t), | 118 MonthFromTime(t), |
| 119 DATE_FROM_TIME(t)); | 119 DateFromTime(t)); |
| 120 return MakeDate(day, TimeWithinDay(t)); | 120 return MakeDate(day, TimeWithinDay(t)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 | 123 |
| 124 // local_time_offset is initialized when the DST_offset_cache is missed. | 124 // local_time_offset is initialized when the DST_offset_cache is missed. |
| 125 // It must not be used until after a call to DaylightSavingsOffset(). | 125 // It must not be used until after a call to DaylightSavingsOffset(). |
| 126 // In this way, only one check, for a DST cache miss, is needed. | 126 // In this way, only one check, for a DST cache miss, is needed. |
| 127 var local_time_offset; | 127 var local_time_offset; |
| 128 | 128 |
| 129 | 129 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 246 |
| 247 | 247 |
| 248 var ltcache = { | 248 var ltcache = { |
| 249 key: null, | 249 key: null, |
| 250 val: null | 250 val: null |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 function LocalTimeNoCheck(time) { | 253 function LocalTimeNoCheck(time) { |
| 254 var ltc = ltcache; | 254 var ltc = ltcache; |
| 255 if (%_ObjectEquals(time, ltc.key)) return ltc.val; | 255 if (%_ObjectEquals(time, ltc.key)) return ltc.val; |
| 256 if (time < -MAX_TIME_MS || time > MAX_TIME_MS) { | |
| 257 return $NaN; | |
| 258 } | |
| 259 | 256 |
| 260 // Inline the DST offset cache checks for speed. | 257 // Inline the DST offset cache checks for speed. |
| 261 // The cache is hit, or DaylightSavingsOffset is called, | 258 // The cache is hit, or DaylightSavingsOffset is called, |
| 262 // before local_time_offset is used. | 259 // before local_time_offset is used. |
| 263 var cache = DST_offset_cache; | 260 var cache = DST_offset_cache; |
| 264 if (cache.start <= time && time <= cache.end) { | 261 if (cache.start <= time && time <= cache.end) { |
| 265 var dst_offset = cache.offset; | 262 var dst_offset = cache.offset; |
| 266 } else { | 263 } else { |
| 267 var dst_offset = DaylightSavingsOffset(time); | 264 var dst_offset = DaylightSavingsOffset(time); |
| 268 } | 265 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 return $NaN; | 361 return $NaN; |
| 365 } | 362 } |
| 366 | 363 |
| 367 // Now we rely on year, month and date being SMIs. | 364 // Now we rely on year, month and date being SMIs. |
| 368 return %DateMakeDay(year, month, date); | 365 return %DateMakeDay(year, month, date); |
| 369 } | 366 } |
| 370 | 367 |
| 371 | 368 |
| 372 // ECMA 262 - 15.9.1.13 | 369 // ECMA 262 - 15.9.1.13 |
| 373 function MakeDate(day, time) { | 370 function MakeDate(day, time) { |
| 374 if (!$isFinite(day)) return $NaN; | 371 var time = day * msPerDay + time; |
|
Søren Thygesen Gjesse
2010/12/16 11:38:30
As you mentioned offline please add tests where da
| |
| 375 if (!$isFinite(time)) return $NaN; | 372 // Some of our runtime funtions for computing UTC(time) rely on |
| 376 return day * msPerDay + time; | 373 // times not being significantly larger than MAX_TIME_MS. If there |
| 374 // is no way that the time can be within range even after UTC | |
| 375 // conversion we return NaN immediately instead of relying on | |
| 376 // TimeClip to do it. | |
| 377 if ($abs(time) > MAX_TIME_BEFORE_UTC) return $NaN; | |
| 378 return time; | |
| 377 } | 379 } |
| 378 | 380 |
| 379 | 381 |
| 380 // ECMA 262 - 15.9.1.14 | 382 // ECMA 262 - 15.9.1.14 |
| 381 function TimeClip(time) { | 383 function TimeClip(time) { |
| 382 if (!$isFinite(time)) return $NaN; | 384 if (!$isFinite(time)) return $NaN; |
| 383 if ($abs(time) > 8.64E15) return $NaN; | 385 if ($abs(time) > MAX_TIME_MS) return $NaN; |
| 384 return TO_INTEGER(time); | 386 return TO_INTEGER(time); |
| 385 } | 387 } |
| 386 | 388 |
| 387 | 389 |
| 388 // The Date cache is used to limit the cost of parsing the same Date | 390 // The Date cache is used to limit the cost of parsing the same Date |
| 389 // strings over and over again. | 391 // strings over and over again. |
| 390 var Date_cache = { | 392 var Date_cache = { |
| 391 // Cached time value. | 393 // Cached time value. |
| 392 time: $NaN, | 394 time: $NaN, |
| 393 // Cached year when interpreting the time as a local time. Only | 395 // Cached year when interpreting the time as a local time. Only |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 417 } else if (IS_STRING(year)) { | 419 } else if (IS_STRING(year)) { |
| 418 // Probe the Date cache. If we already have a time value for the | 420 // Probe the Date cache. If we already have a time value for the |
| 419 // given time, we re-use that instead of parsing the string again. | 421 // given time, we re-use that instead of parsing the string again. |
| 420 var cache = Date_cache; | 422 var cache = Date_cache; |
| 421 if (cache.string === year) { | 423 if (cache.string === year) { |
| 422 value = cache.time; | 424 value = cache.time; |
| 423 } else { | 425 } else { |
| 424 value = DateParse(year); | 426 value = DateParse(year); |
| 425 if (!NUMBER_IS_NAN(value)) { | 427 if (!NUMBER_IS_NAN(value)) { |
| 426 cache.time = value; | 428 cache.time = value; |
| 427 cache.year = YEAR_FROM_TIME(LocalTimeNoCheck(value)); | 429 cache.year = YearFromTime(LocalTimeNoCheck(value)); |
| 428 cache.string = year; | 430 cache.string = year; |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 | 433 |
| 432 } else { | 434 } else { |
| 433 // According to ECMA 262, no hint should be given for this | 435 // According to ECMA 262, no hint should be given for this |
| 434 // conversion. However, ToPrimitive defaults to STRING_HINT for | 436 // conversion. However, ToPrimitive defaults to STRING_HINT for |
| 435 // Date objects which will lose precision when the Date | 437 // Date objects which will lose precision when the Date |
| 436 // constructor is called with another Date object as its | 438 // constructor is called with another Date object as its |
| 437 // argument. We therefore use NUMBER_HINT for the conversion, | 439 // argument. We therefore use NUMBER_HINT for the conversion, |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 return DATE_VALUE(this); | 637 return DATE_VALUE(this); |
| 636 } | 638 } |
| 637 | 639 |
| 638 | 640 |
| 639 // ECMA 262 - 15.9.5.10 | 641 // ECMA 262 - 15.9.5.10 |
| 640 function DateGetFullYear() { | 642 function DateGetFullYear() { |
| 641 var t = DATE_VALUE(this); | 643 var t = DATE_VALUE(this); |
| 642 if (NUMBER_IS_NAN(t)) return t; | 644 if (NUMBER_IS_NAN(t)) return t; |
| 643 var cache = Date_cache; | 645 var cache = Date_cache; |
| 644 if (cache.time === t) return cache.year; | 646 if (cache.time === t) return cache.year; |
| 645 return YEAR_FROM_TIME(LocalTimeNoCheck(t)); | 647 return YearFromTime(LocalTimeNoCheck(t)); |
| 646 } | 648 } |
| 647 | 649 |
| 648 | 650 |
| 649 // ECMA 262 - 15.9.5.11 | 651 // ECMA 262 - 15.9.5.11 |
| 650 function DateGetUTCFullYear() { | 652 function DateGetUTCFullYear() { |
| 651 var t = DATE_VALUE(this); | 653 var t = DATE_VALUE(this); |
| 652 if (NUMBER_IS_NAN(t)) return t; | 654 if (NUMBER_IS_NAN(t)) return t; |
| 653 return YEAR_FROM_TIME(t); | 655 return YearFromTime(t); |
| 654 } | 656 } |
| 655 | 657 |
| 656 | 658 |
| 657 // ECMA 262 - 15.9.5.12 | 659 // ECMA 262 - 15.9.5.12 |
| 658 function DateGetMonth() { | 660 function DateGetMonth() { |
| 659 var t = DATE_VALUE(this); | 661 var t = DATE_VALUE(this); |
| 660 if (NUMBER_IS_NAN(t)) return t; | 662 if (NUMBER_IS_NAN(t)) return t; |
| 661 return MONTH_FROM_TIME(LocalTimeNoCheck(t)); | 663 return MonthFromTime(LocalTimeNoCheck(t)); |
| 662 } | 664 } |
| 663 | 665 |
| 664 | 666 |
| 665 // ECMA 262 - 15.9.5.13 | 667 // ECMA 262 - 15.9.5.13 |
| 666 function DateGetUTCMonth() { | 668 function DateGetUTCMonth() { |
| 667 var t = DATE_VALUE(this); | 669 var t = DATE_VALUE(this); |
| 668 if (NUMBER_IS_NAN(t)) return t; | 670 if (NUMBER_IS_NAN(t)) return t; |
| 669 return MONTH_FROM_TIME(t); | 671 return MonthFromTime(t); |
| 670 } | 672 } |
| 671 | 673 |
| 672 | 674 |
| 673 // ECMA 262 - 15.9.5.14 | 675 // ECMA 262 - 15.9.5.14 |
| 674 function DateGetDate() { | 676 function DateGetDate() { |
| 675 var t = DATE_VALUE(this); | 677 var t = DATE_VALUE(this); |
| 676 if (NUMBER_IS_NAN(t)) return t; | 678 if (NUMBER_IS_NAN(t)) return t; |
| 677 return DATE_FROM_TIME(LocalTimeNoCheck(t)); | 679 return DateFromTime(LocalTimeNoCheck(t)); |
| 678 } | 680 } |
| 679 | 681 |
| 680 | 682 |
| 681 // ECMA 262 - 15.9.5.15 | 683 // ECMA 262 - 15.9.5.15 |
| 682 function DateGetUTCDate() { | 684 function DateGetUTCDate() { |
| 683 var t = DATE_VALUE(this); | 685 var t = DATE_VALUE(this); |
| 684 return NAN_OR_DATE_FROM_TIME(t); | 686 return NAN_OR_DATE_FROM_TIME(t); |
| 685 } | 687 } |
| 686 | 688 |
| 687 | 689 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 ms = argc < 4 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); | 864 ms = argc < 4 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
| 863 var time = MakeTime(hour, min, sec, ms); | 865 var time = MakeTime(hour, min, sec, ms); |
| 864 return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); | 866 return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); |
| 865 } | 867 } |
| 866 | 868 |
| 867 | 869 |
| 868 // ECMA 262 - 15.9.5.36 | 870 // ECMA 262 - 15.9.5.36 |
| 869 function DateSetDate(date) { | 871 function DateSetDate(date) { |
| 870 var t = LocalTime(DATE_VALUE(this)); | 872 var t = LocalTime(DATE_VALUE(this)); |
| 871 date = ToNumber(date); | 873 date = ToNumber(date); |
| 872 var day = MakeDay(YEAR_FROM_TIME(t), MONTH_FROM_TIME(t), date); | 874 var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); |
| 873 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); | 875 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
| 874 } | 876 } |
| 875 | 877 |
| 876 | 878 |
| 877 // ECMA 262 - 15.9.5.37 | 879 // ECMA 262 - 15.9.5.37 |
| 878 function DateSetUTCDate(date) { | 880 function DateSetUTCDate(date) { |
| 879 var t = DATE_VALUE(this); | 881 var t = DATE_VALUE(this); |
| 880 date = ToNumber(date); | 882 date = ToNumber(date); |
| 881 var day = MakeDay(YEAR_FROM_TIME(t), MONTH_FROM_TIME(t), date); | 883 var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); |
| 882 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); | 884 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
| 883 } | 885 } |
| 884 | 886 |
| 885 | 887 |
| 886 // ECMA 262 - 15.9.5.38 | 888 // ECMA 262 - 15.9.5.38 |
| 887 function DateSetMonth(month, date) { | 889 function DateSetMonth(month, date) { |
| 888 var t = LocalTime(DATE_VALUE(this)); | 890 var t = LocalTime(DATE_VALUE(this)); |
| 889 month = ToNumber(month); | 891 month = ToNumber(month); |
| 890 date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date); | 892 date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date); |
| 891 var day = MakeDay(YEAR_FROM_TIME(t), month, date); | 893 var day = MakeDay(YearFromTime(t), month, date); |
| 892 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); | 894 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
| 893 } | 895 } |
| 894 | 896 |
| 895 | 897 |
| 896 // ECMA 262 - 15.9.5.39 | 898 // ECMA 262 - 15.9.5.39 |
| 897 function DateSetUTCMonth(month, date) { | 899 function DateSetUTCMonth(month, date) { |
| 898 var t = DATE_VALUE(this); | 900 var t = DATE_VALUE(this); |
| 899 month = ToNumber(month); | 901 month = ToNumber(month); |
| 900 date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date); | 902 date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date); |
| 901 var day = MakeDay(YEAR_FROM_TIME(t), month, date); | 903 var day = MakeDay(YearFromTime(t), month, date); |
| 902 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); | 904 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
| 903 } | 905 } |
| 904 | 906 |
| 905 | 907 |
| 906 // ECMA 262 - 15.9.5.40 | 908 // ECMA 262 - 15.9.5.40 |
| 907 function DateSetFullYear(year, month, date) { | 909 function DateSetFullYear(year, month, date) { |
| 908 var t = DATE_VALUE(this); | 910 var t = DATE_VALUE(this); |
| 909 t = NUMBER_IS_NAN(t) ? 0 : LocalTimeNoCheck(t); | 911 t = NUMBER_IS_NAN(t) ? 0 : LocalTimeNoCheck(t); |
| 910 year = ToNumber(year); | 912 year = ToNumber(year); |
| 911 var argc = %_ArgumentsLength(); | 913 var argc = %_ArgumentsLength(); |
| 912 month = argc < 2 ? MONTH_FROM_TIME(t) : ToNumber(month); | 914 month = argc < 2 ? MonthFromTime(t) : ToNumber(month); |
| 913 date = argc < 3 ? DATE_FROM_TIME(t) : ToNumber(date); | 915 date = argc < 3 ? DateFromTime(t) : ToNumber(date); |
| 914 var day = MakeDay(year, month, date); | 916 var day = MakeDay(year, month, date); |
| 915 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); | 917 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
| 916 } | 918 } |
| 917 | 919 |
| 918 | 920 |
| 919 // ECMA 262 - 15.9.5.41 | 921 // ECMA 262 - 15.9.5.41 |
| 920 function DateSetUTCFullYear(year, month, date) { | 922 function DateSetUTCFullYear(year, month, date) { |
| 921 var t = DATE_VALUE(this); | 923 var t = DATE_VALUE(this); |
| 922 if (NUMBER_IS_NAN(t)) t = 0; | 924 if (NUMBER_IS_NAN(t)) t = 0; |
| 923 var argc = %_ArgumentsLength(); | 925 var argc = %_ArgumentsLength(); |
| 924 year = ToNumber(year); | 926 year = ToNumber(year); |
| 925 month = argc < 2 ? MONTH_FROM_TIME(t) : ToNumber(month); | 927 month = argc < 2 ? MonthFromTime(t) : ToNumber(month); |
| 926 date = argc < 3 ? DATE_FROM_TIME(t) : ToNumber(date); | 928 date = argc < 3 ? DateFromTime(t) : ToNumber(date); |
| 927 var day = MakeDay(year, month, date); | 929 var day = MakeDay(year, month, date); |
| 928 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); | 930 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
| 929 } | 931 } |
| 930 | 932 |
| 931 | 933 |
| 932 // ECMA 262 - 15.9.5.42 | 934 // ECMA 262 - 15.9.5.42 |
| 933 function DateToUTCString() { | 935 function DateToUTCString() { |
| 934 var t = DATE_VALUE(this); | 936 var t = DATE_VALUE(this); |
| 935 if (NUMBER_IS_NAN(t)) return kInvalidDate; | 937 if (NUMBER_IS_NAN(t)) return kInvalidDate; |
| 936 // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT | 938 // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT |
| 937 return WeekDays[WeekDay(t)] + ', ' | 939 return WeekDays[WeekDay(t)] + ', ' |
| 938 + TwoDigitString(DATE_FROM_TIME(t)) + ' ' | 940 + TwoDigitString(DateFromTime(t)) + ' ' |
| 939 + Months[MONTH_FROM_TIME(t)] + ' ' | 941 + Months[MonthFromTime(t)] + ' ' |
| 940 + YEAR_FROM_TIME(t) + ' ' | 942 + YearFromTime(t) + ' ' |
| 941 + TimeString(t) + ' GMT'; | 943 + TimeString(t) + ' GMT'; |
| 942 } | 944 } |
| 943 | 945 |
| 944 | 946 |
| 945 // ECMA 262 - B.2.4 | 947 // ECMA 262 - B.2.4 |
| 946 function DateGetYear() { | 948 function DateGetYear() { |
| 947 var t = DATE_VALUE(this); | 949 var t = DATE_VALUE(this); |
| 948 if (NUMBER_IS_NAN(t)) return $NaN; | 950 if (NUMBER_IS_NAN(t)) return $NaN; |
| 949 return YEAR_FROM_TIME(LocalTimeNoCheck(t)) - 1900; | 951 return YearFromTime(LocalTimeNoCheck(t)) - 1900; |
| 950 } | 952 } |
| 951 | 953 |
| 952 | 954 |
| 953 // ECMA 262 - B.2.5 | 955 // ECMA 262 - B.2.5 |
| 954 function DateSetYear(year) { | 956 function DateSetYear(year) { |
| 955 var t = LocalTime(DATE_VALUE(this)); | 957 var t = LocalTime(DATE_VALUE(this)); |
| 956 if (NUMBER_IS_NAN(t)) t = 0; | 958 if (NUMBER_IS_NAN(t)) t = 0; |
| 957 year = ToNumber(year); | 959 year = ToNumber(year); |
| 958 if (NUMBER_IS_NAN(year)) return %_SetValueOf(this, $NaN); | 960 if (NUMBER_IS_NAN(year)) return %_SetValueOf(this, $NaN); |
| 959 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) | 961 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
| 960 ? 1900 + TO_INTEGER(year) : year; | 962 ? 1900 + TO_INTEGER(year) : year; |
| 961 var day = MakeDay(year, MONTH_FROM_TIME(t), DATE_FROM_TIME(t)); | 963 var day = MakeDay(year, MonthFromTime(t), DateFromTime(t)); |
| 962 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); | 964 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
| 963 } | 965 } |
| 964 | 966 |
| 965 | 967 |
| 966 // ECMA 262 - B.2.6 | 968 // ECMA 262 - B.2.6 |
| 967 // | 969 // |
| 968 // Notice that this does not follow ECMA 262 completely. ECMA 262 | 970 // Notice that this does not follow ECMA 262 completely. ECMA 262 |
| 969 // says that toGMTString should be the same Function object as | 971 // says that toGMTString should be the same Function object as |
| 970 // toUTCString. JSC does not do this, so for compatibility we do not | 972 // toUTCString. JSC does not do this, so for compatibility we do not |
| 971 // do that either. Instead, we create a new function whose name | 973 // do that either. Instead, we create a new function whose name |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 "toGMTString", DateToGMTString, | 1066 "toGMTString", DateToGMTString, |
| 1065 "toUTCString", DateToUTCString, | 1067 "toUTCString", DateToUTCString, |
| 1066 "getYear", DateGetYear, | 1068 "getYear", DateGetYear, |
| 1067 "setYear", DateSetYear, | 1069 "setYear", DateSetYear, |
| 1068 "toISOString", DateToISOString, | 1070 "toISOString", DateToISOString, |
| 1069 "toJSON", DateToJSON | 1071 "toJSON", DateToJSON |
| 1070 )); | 1072 )); |
| 1071 } | 1073 } |
| 1072 | 1074 |
| 1073 SetupDate(); | 1075 SetupDate(); |
| OLD | NEW |