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