| 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 // This file relies on the fact that the following declarations have been made | |
| 6 // in v8natives.js: | |
| 7 // var $isFinite = GlobalIsFinite; | |
| 8 | |
| 9 var $createDate; | 5 var $createDate; |
| 10 | 6 |
| 11 // ------------------------------------------------------------------- | 7 // ------------------------------------------------------------------- |
| 12 | 8 |
| 13 (function(global, utils) { | 9 (function(global, utils) { |
| 14 | 10 |
| 15 "use strict"; | 11 "use strict"; |
| 16 | 12 |
| 17 %CheckIsBootstrapping(); | 13 %CheckIsBootstrapping(); |
| 18 | 14 |
| 19 // ------------------------------------------------------------------- | 15 // ------------------------------------------------------------------- |
| 20 // Imports | 16 // Imports |
| 21 | 17 |
| 22 var GlobalDate = global.Date; | 18 var GlobalDate = global.Date; |
| 23 var InternalArray = utils.InternalArray; | 19 var InternalArray = utils.InternalArray; |
| 24 | 20 |
| 21 var IsFinite; |
| 25 var MathAbs; | 22 var MathAbs; |
| 26 var MathFloor; | 23 var MathFloor; |
| 27 | 24 |
| 28 utils.Import(function(from) { | 25 utils.Import(function(from) { |
| 26 IsFinite = from.IsFinite; |
| 29 MathAbs = from.MathAbs; | 27 MathAbs = from.MathAbs; |
| 30 MathFloor = from.MathFloor; | 28 MathFloor = from.MathFloor; |
| 31 }); | 29 }); |
| 32 | 30 |
| 33 // ------------------------------------------------------------------- | 31 // ------------------------------------------------------------------- |
| 34 | 32 |
| 35 // This file contains date support implemented in JavaScript. | 33 // This file contains date support implemented in JavaScript. |
| 36 | 34 |
| 37 var timezone_cache_time = NAN; | 35 var timezone_cache_time = NAN; |
| 38 var timezone_cache_timezone; | 36 var timezone_cache_timezone; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 function UTC(time) { | 51 function UTC(time) { |
| 54 if (NUMBER_IS_NAN(time)) return time; | 52 if (NUMBER_IS_NAN(time)) return time; |
| 55 // local_time_offset is needed before the call to DaylightSavingsOffset, | 53 // local_time_offset is needed before the call to DaylightSavingsOffset, |
| 56 // so it may be uninitialized. | 54 // so it may be uninitialized. |
| 57 return %DateToUTC(time); | 55 return %DateToUTC(time); |
| 58 } | 56 } |
| 59 | 57 |
| 60 | 58 |
| 61 // ECMA 262 - 15.9.1.11 | 59 // ECMA 262 - 15.9.1.11 |
| 62 function MakeTime(hour, min, sec, ms) { | 60 function MakeTime(hour, min, sec, ms) { |
| 63 if (!$isFinite(hour)) return NAN; | 61 if (!IsFinite(hour)) return NAN; |
| 64 if (!$isFinite(min)) return NAN; | 62 if (!IsFinite(min)) return NAN; |
| 65 if (!$isFinite(sec)) return NAN; | 63 if (!IsFinite(sec)) return NAN; |
| 66 if (!$isFinite(ms)) return NAN; | 64 if (!IsFinite(ms)) return NAN; |
| 67 return TO_INTEGER(hour) * msPerHour | 65 return TO_INTEGER(hour) * msPerHour |
| 68 + TO_INTEGER(min) * msPerMinute | 66 + TO_INTEGER(min) * msPerMinute |
| 69 + TO_INTEGER(sec) * msPerSecond | 67 + TO_INTEGER(sec) * msPerSecond |
| 70 + TO_INTEGER(ms); | 68 + TO_INTEGER(ms); |
| 71 } | 69 } |
| 72 | 70 |
| 73 | 71 |
| 74 // ECMA 262 - 15.9.1.12 | 72 // ECMA 262 - 15.9.1.12 |
| 75 function TimeInYear(year) { | 73 function TimeInYear(year) { |
| 76 return DaysInYear(year) * msPerDay; | 74 return DaysInYear(year) * msPerDay; |
| 77 } | 75 } |
| 78 | 76 |
| 79 | 77 |
| 80 // Compute number of days given a year, month, date. | 78 // Compute number of days given a year, month, date. |
| 81 // Note that month and date can lie outside the normal range. | 79 // Note that month and date can lie outside the normal range. |
| 82 // For example: | 80 // For example: |
| 83 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) | 81 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) |
| 84 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) | 82 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) |
| 85 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) | 83 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) |
| 86 function MakeDay(year, month, date) { | 84 function MakeDay(year, month, date) { |
| 87 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return NAN; | 85 if (!IsFinite(year) || !IsFinite(month) || !IsFinite(date)) return NAN; |
| 88 | 86 |
| 89 // Convert to integer and map -0 to 0. | 87 // Convert to integer and map -0 to 0. |
| 90 year = TO_INTEGER_MAP_MINUS_ZERO(year); | 88 year = TO_INTEGER_MAP_MINUS_ZERO(year); |
| 91 month = TO_INTEGER_MAP_MINUS_ZERO(month); | 89 month = TO_INTEGER_MAP_MINUS_ZERO(month); |
| 92 date = TO_INTEGER_MAP_MINUS_ZERO(date); | 90 date = TO_INTEGER_MAP_MINUS_ZERO(date); |
| 93 | 91 |
| 94 if (year < kMinYear || year > kMaxYear || | 92 if (year < kMinYear || year > kMaxYear || |
| 95 month < kMinMonth || month > kMaxMonth) { | 93 month < kMinMonth || month > kMaxMonth) { |
| 96 return NAN; | 94 return NAN; |
| 97 } | 95 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 109 // is no way that the time can be within range even after UTC | 107 // is no way that the time can be within range even after UTC |
| 110 // conversion we return NaN immediately instead of relying on | 108 // conversion we return NaN immediately instead of relying on |
| 111 // TimeClip to do it. | 109 // TimeClip to do it. |
| 112 if (MathAbs(time) > MAX_TIME_BEFORE_UTC) return NAN; | 110 if (MathAbs(time) > MAX_TIME_BEFORE_UTC) return NAN; |
| 113 return time; | 111 return time; |
| 114 } | 112 } |
| 115 | 113 |
| 116 | 114 |
| 117 // ECMA 262 - 15.9.1.14 | 115 // ECMA 262 - 15.9.1.14 |
| 118 function TimeClip(time) { | 116 function TimeClip(time) { |
| 119 if (!$isFinite(time)) return NAN; | 117 if (!IsFinite(time)) return NAN; |
| 120 if (MathAbs(time) > MAX_TIME_MS) return NAN; | 118 if (MathAbs(time) > MAX_TIME_MS) return NAN; |
| 121 return TO_INTEGER(time); | 119 return TO_INTEGER(time); |
| 122 } | 120 } |
| 123 | 121 |
| 124 | 122 |
| 125 // 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 |
| 126 // strings over and over again. | 124 // strings over and over again. |
| 127 var Date_cache = { | 125 var Date_cache = { |
| 128 // Cached time value. | 126 // Cached time value. |
| 129 time: 0, | 127 time: 0, |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 date.setTime(time); | 765 date.setTime(time); |
| 768 return date; | 766 return date; |
| 769 } | 767 } |
| 770 | 768 |
| 771 // ------------------------------------------------------------------- | 769 // ------------------------------------------------------------------- |
| 772 | 770 |
| 773 %SetCode(GlobalDate, DateConstructor); | 771 %SetCode(GlobalDate, DateConstructor); |
| 774 %FunctionSetPrototype(GlobalDate, new GlobalDate(NAN)); | 772 %FunctionSetPrototype(GlobalDate, new GlobalDate(NAN)); |
| 775 | 773 |
| 776 // Set up non-enumerable properties of the Date object itself. | 774 // Set up non-enumerable properties of the Date object itself. |
| 777 $installFunctions(GlobalDate, DONT_ENUM, [ | 775 utils.InstallFunctions(GlobalDate, DONT_ENUM, [ |
| 778 "UTC", DateUTC, | 776 "UTC", DateUTC, |
| 779 "parse", DateParse, | 777 "parse", DateParse, |
| 780 "now", DateNow | 778 "now", DateNow |
| 781 ]); | 779 ]); |
| 782 | 780 |
| 783 // Set up non-enumerable constructor property of the Date prototype object. | 781 // Set up non-enumerable constructor property of the Date prototype object. |
| 784 %AddNamedProperty(GlobalDate.prototype, "constructor", GlobalDate, DONT_ENUM); | 782 %AddNamedProperty(GlobalDate.prototype, "constructor", GlobalDate, DONT_ENUM); |
| 785 | 783 |
| 786 // Set up non-enumerable functions of the Date prototype object and | 784 // Set up non-enumerable functions of the Date prototype object and |
| 787 // set their names. | 785 // set their names. |
| 788 $installFunctions(GlobalDate.prototype, DONT_ENUM, [ | 786 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ |
| 789 "toString", DateToString, | 787 "toString", DateToString, |
| 790 "toDateString", DateToDateString, | 788 "toDateString", DateToDateString, |
| 791 "toTimeString", DateToTimeString, | 789 "toTimeString", DateToTimeString, |
| 792 "toLocaleString", DateToLocaleString, | 790 "toLocaleString", DateToLocaleString, |
| 793 "toLocaleDateString", DateToLocaleDateString, | 791 "toLocaleDateString", DateToLocaleDateString, |
| 794 "toLocaleTimeString", DateToLocaleTimeString, | 792 "toLocaleTimeString", DateToLocaleTimeString, |
| 795 "valueOf", DateValueOf, | 793 "valueOf", DateValueOf, |
| 796 "getTime", DateGetTime, | 794 "getTime", DateGetTime, |
| 797 "getFullYear", DateGetFullYear, | 795 "getFullYear", DateGetFullYear, |
| 798 "getUTCFullYear", DateGetUTCFullYear, | 796 "getUTCFullYear", DateGetUTCFullYear, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 "getYear", DateGetYear, | 829 "getYear", DateGetYear, |
| 832 "setYear", DateSetYear, | 830 "setYear", DateSetYear, |
| 833 "toISOString", DateToISOString, | 831 "toISOString", DateToISOString, |
| 834 "toJSON", DateToJSON | 832 "toJSON", DateToJSON |
| 835 ]); | 833 ]); |
| 836 | 834 |
| 837 // Expose to the global scope. | 835 // Expose to the global scope. |
| 838 $createDate = CreateDate; | 836 $createDate = CreateDate; |
| 839 | 837 |
| 840 }) | 838 }) |
| OLD | NEW |