| 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 "use strict"; | |
| 6 | |
| 7 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
| 8 // in v8natives.js: | 6 // in v8natives.js: |
| 9 // var $isFinite = GlobalIsFinite; | 7 // var $isFinite = GlobalIsFinite; |
| 10 | 8 |
| 11 var $Date = global.Date; | 9 var $createDate; |
| 12 | 10 |
| 13 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 14 | 12 |
| 13 (function() { |
| 14 |
| 15 "use strict"; |
| 16 |
| 17 %CheckIsBootstrapping(); |
| 18 |
| 19 var GlobalDate = global.Date; |
| 20 |
| 15 // This file contains date support implemented in JavaScript. | 21 // This file contains date support implemented in JavaScript. |
| 16 | 22 |
| 17 // Helper function to throw error. | 23 // Helper function to throw error. |
| 18 function ThrowDateTypeError() { | 24 function ThrowDateTypeError() { |
| 19 throw new $TypeError('this is not a Date object.'); | 25 throw new $TypeError('this is not a Date object.'); |
| 20 } | 26 } |
| 21 | 27 |
| 22 | |
| 23 var timezone_cache_time = NAN; | 28 var timezone_cache_time = NAN; |
| 24 var timezone_cache_timezone; | 29 var timezone_cache_timezone; |
| 25 | 30 |
| 26 function LocalTimezone(t) { | 31 function LocalTimezone(t) { |
| 27 if (NUMBER_IS_NAN(t)) return ""; | 32 if (NUMBER_IS_NAN(t)) return ""; |
| 28 CheckDateCacheCurrent(); | 33 CheckDateCacheCurrent(); |
| 29 if (t == timezone_cache_time) { | 34 if (t == timezone_cache_time) { |
| 30 return timezone_cache_timezone; | 35 return timezone_cache_timezone; |
| 31 } | 36 } |
| 32 var timezone = %DateLocalTimezone(t); | 37 var timezone = %DateLocalTimezone(t); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Cached time value. | 119 // Cached time value. |
| 115 time: 0, | 120 time: 0, |
| 116 // String input for which the cached time is valid. | 121 // String input for which the cached time is valid. |
| 117 string: null | 122 string: null |
| 118 }; | 123 }; |
| 119 | 124 |
| 120 | 125 |
| 121 function DateConstructor(year, month, date, hours, minutes, seconds, ms) { | 126 function DateConstructor(year, month, date, hours, minutes, seconds, ms) { |
| 122 if (!%_IsConstructCall()) { | 127 if (!%_IsConstructCall()) { |
| 123 // ECMA 262 - 15.9.2 | 128 // ECMA 262 - 15.9.2 |
| 124 return (new $Date()).toString(); | 129 return (new GlobalDate()).toString(); |
| 125 } | 130 } |
| 126 | 131 |
| 127 // ECMA 262 - 15.9.3 | 132 // ECMA 262 - 15.9.3 |
| 128 var argc = %_ArgumentsLength(); | 133 var argc = %_ArgumentsLength(); |
| 129 var value; | 134 var value; |
| 130 if (argc == 0) { | 135 if (argc == 0) { |
| 131 value = %DateCurrentTime(); | 136 value = %DateCurrentTime(); |
| 132 SET_UTC_DATE_VALUE(this, value); | 137 SET_UTC_DATE_VALUE(this, value); |
| 133 } else if (argc == 1) { | 138 } else if (argc == 1) { |
| 134 if (IS_NUMBER(year)) { | 139 if (IS_NUMBER(year)) { |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 timezone_cache_time = NAN; | 747 timezone_cache_time = NAN; |
| 743 timezone_cache_timezone = UNDEFINED; | 748 timezone_cache_timezone = UNDEFINED; |
| 744 | 749 |
| 745 // Reset the date cache: | 750 // Reset the date cache: |
| 746 Date_cache.time = NAN; | 751 Date_cache.time = NAN; |
| 747 Date_cache.string = null; | 752 Date_cache.string = null; |
| 748 } | 753 } |
| 749 | 754 |
| 750 | 755 |
| 751 function CreateDate(time) { | 756 function CreateDate(time) { |
| 752 var date = new $Date(); | 757 var date = new GlobalDate(); |
| 753 date.setTime(time); | 758 date.setTime(time); |
| 754 return date; | 759 return date; |
| 755 } | 760 } |
| 756 | 761 |
| 757 // ------------------------------------------------------------------- | 762 // ------------------------------------------------------------------- |
| 758 | 763 |
| 759 function SetUpDate() { | 764 %SetCode(GlobalDate, DateConstructor); |
| 760 %CheckIsBootstrapping(); | 765 %FunctionSetPrototype(GlobalDate, new GlobalDate(NAN)); |
| 761 | 766 |
| 762 %SetCode($Date, DateConstructor); | 767 // Set up non-enumerable properties of the Date object itself. |
| 763 %FunctionSetPrototype($Date, new $Date(NAN)); | 768 InstallFunctions(GlobalDate, DONT_ENUM, $Array( |
| 769 "UTC", DateUTC, |
| 770 "parse", DateParse, |
| 771 "now", DateNow |
| 772 )); |
| 764 | 773 |
| 765 // Set up non-enumerable properties of the Date object itself. | 774 // Set up non-enumerable constructor property of the Date prototype object. |
| 766 InstallFunctions($Date, DONT_ENUM, $Array( | 775 %AddNamedProperty(GlobalDate.prototype, "constructor", GlobalDate, DONT_ENUM); |
| 767 "UTC", DateUTC, | |
| 768 "parse", DateParse, | |
| 769 "now", DateNow | |
| 770 )); | |
| 771 | 776 |
| 772 // Set up non-enumerable constructor property of the Date prototype object. | 777 // Set up non-enumerable functions of the Date prototype object and |
| 773 %AddNamedProperty($Date.prototype, "constructor", $Date, DONT_ENUM); | 778 // set their names. |
| 779 InstallFunctions(GlobalDate.prototype, DONT_ENUM, $Array( |
| 780 "toString", DateToString, |
| 781 "toDateString", DateToDateString, |
| 782 "toTimeString", DateToTimeString, |
| 783 "toLocaleString", DateToLocaleString, |
| 784 "toLocaleDateString", DateToLocaleDateString, |
| 785 "toLocaleTimeString", DateToLocaleTimeString, |
| 786 "valueOf", DateValueOf, |
| 787 "getTime", DateGetTime, |
| 788 "getFullYear", DateGetFullYear, |
| 789 "getUTCFullYear", DateGetUTCFullYear, |
| 790 "getMonth", DateGetMonth, |
| 791 "getUTCMonth", DateGetUTCMonth, |
| 792 "getDate", DateGetDate, |
| 793 "getUTCDate", DateGetUTCDate, |
| 794 "getDay", DateGetDay, |
| 795 "getUTCDay", DateGetUTCDay, |
| 796 "getHours", DateGetHours, |
| 797 "getUTCHours", DateGetUTCHours, |
| 798 "getMinutes", DateGetMinutes, |
| 799 "getUTCMinutes", DateGetUTCMinutes, |
| 800 "getSeconds", DateGetSeconds, |
| 801 "getUTCSeconds", DateGetUTCSeconds, |
| 802 "getMilliseconds", DateGetMilliseconds, |
| 803 "getUTCMilliseconds", DateGetUTCMilliseconds, |
| 804 "getTimezoneOffset", DateGetTimezoneOffset, |
| 805 "setTime", DateSetTime, |
| 806 "setMilliseconds", DateSetMilliseconds, |
| 807 "setUTCMilliseconds", DateSetUTCMilliseconds, |
| 808 "setSeconds", DateSetSeconds, |
| 809 "setUTCSeconds", DateSetUTCSeconds, |
| 810 "setMinutes", DateSetMinutes, |
| 811 "setUTCMinutes", DateSetUTCMinutes, |
| 812 "setHours", DateSetHours, |
| 813 "setUTCHours", DateSetUTCHours, |
| 814 "setDate", DateSetDate, |
| 815 "setUTCDate", DateSetUTCDate, |
| 816 "setMonth", DateSetMonth, |
| 817 "setUTCMonth", DateSetUTCMonth, |
| 818 "setFullYear", DateSetFullYear, |
| 819 "setUTCFullYear", DateSetUTCFullYear, |
| 820 "toGMTString", DateToGMTString, |
| 821 "toUTCString", DateToUTCString, |
| 822 "getYear", DateGetYear, |
| 823 "setYear", DateSetYear, |
| 824 "toISOString", DateToISOString, |
| 825 "toJSON", DateToJSON |
| 826 )); |
| 774 | 827 |
| 775 // Set up non-enumerable functions of the Date prototype object and | 828 // Expose to the global scope. |
| 776 // set their names. | 829 $createDate = CreateDate; |
| 777 InstallFunctions($Date.prototype, DONT_ENUM, $Array( | |
| 778 "toString", DateToString, | |
| 779 "toDateString", DateToDateString, | |
| 780 "toTimeString", DateToTimeString, | |
| 781 "toLocaleString", DateToLocaleString, | |
| 782 "toLocaleDateString", DateToLocaleDateString, | |
| 783 "toLocaleTimeString", DateToLocaleTimeString, | |
| 784 "valueOf", DateValueOf, | |
| 785 "getTime", DateGetTime, | |
| 786 "getFullYear", DateGetFullYear, | |
| 787 "getUTCFullYear", DateGetUTCFullYear, | |
| 788 "getMonth", DateGetMonth, | |
| 789 "getUTCMonth", DateGetUTCMonth, | |
| 790 "getDate", DateGetDate, | |
| 791 "getUTCDate", DateGetUTCDate, | |
| 792 "getDay", DateGetDay, | |
| 793 "getUTCDay", DateGetUTCDay, | |
| 794 "getHours", DateGetHours, | |
| 795 "getUTCHours", DateGetUTCHours, | |
| 796 "getMinutes", DateGetMinutes, | |
| 797 "getUTCMinutes", DateGetUTCMinutes, | |
| 798 "getSeconds", DateGetSeconds, | |
| 799 "getUTCSeconds", DateGetUTCSeconds, | |
| 800 "getMilliseconds", DateGetMilliseconds, | |
| 801 "getUTCMilliseconds", DateGetUTCMilliseconds, | |
| 802 "getTimezoneOffset", DateGetTimezoneOffset, | |
| 803 "setTime", DateSetTime, | |
| 804 "setMilliseconds", DateSetMilliseconds, | |
| 805 "setUTCMilliseconds", DateSetUTCMilliseconds, | |
| 806 "setSeconds", DateSetSeconds, | |
| 807 "setUTCSeconds", DateSetUTCSeconds, | |
| 808 "setMinutes", DateSetMinutes, | |
| 809 "setUTCMinutes", DateSetUTCMinutes, | |
| 810 "setHours", DateSetHours, | |
| 811 "setUTCHours", DateSetUTCHours, | |
| 812 "setDate", DateSetDate, | |
| 813 "setUTCDate", DateSetUTCDate, | |
| 814 "setMonth", DateSetMonth, | |
| 815 "setUTCMonth", DateSetUTCMonth, | |
| 816 "setFullYear", DateSetFullYear, | |
| 817 "setUTCFullYear", DateSetUTCFullYear, | |
| 818 "toGMTString", DateToGMTString, | |
| 819 "toUTCString", DateToUTCString, | |
| 820 "getYear", DateGetYear, | |
| 821 "setYear", DateSetYear, | |
| 822 "toISOString", DateToISOString, | |
| 823 "toJSON", DateToJSON | |
| 824 )); | |
| 825 } | |
| 826 | 830 |
| 827 SetUpDate(); | 831 })(); |
| OLD | NEW |