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 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 357 |
358 // ECMA 262 - 15.9.5.7 | 358 // ECMA 262 - 15.9.5.7 |
359 function DateToLocaleTimeString() { | 359 function DateToLocaleTimeString() { |
360 CHECK_DATE(this); | 360 CHECK_DATE(this); |
361 var t = UTC_DATE_VALUE(this); | 361 var t = UTC_DATE_VALUE(this); |
362 if (NUMBER_IS_NAN(t)) return kInvalidDate; | 362 if (NUMBER_IS_NAN(t)) return kInvalidDate; |
363 return TimeString(this); | 363 return TimeString(this); |
364 } | 364 } |
365 | 365 |
366 | 366 |
| 367 // 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) |
| 368 function DateToPrimitive(hint) { |
| 369 if (!IS_SPEC_OBJECT(this)) { |
| 370 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 371 "Date.prototype [ @@toPrimitive ]", this); |
| 372 } |
| 373 if (hint === "default") { |
| 374 hint = "string"; |
| 375 } else if (hint !== "number" && hint !== "string") { |
| 376 throw MakeTypeError(kInvalidHint, hint); |
| 377 } |
| 378 return %OrdinaryToPrimitive(this, hint); |
| 379 } |
| 380 |
| 381 |
367 // ECMA 262 - 15.9.5.8 | 382 // ECMA 262 - 15.9.5.8 |
368 function DateValueOf() { | 383 function DateValueOf() { |
369 CHECK_DATE(this); | 384 CHECK_DATE(this); |
370 return UTC_DATE_VALUE(this); | 385 return UTC_DATE_VALUE(this); |
371 } | 386 } |
372 | 387 |
373 | 388 |
374 // ECMA 262 - 15.9.5.9 | 389 // ECMA 262 - 15.9.5.9 |
375 function DateGetTime() { | 390 function DateGetTime() { |
376 CHECK_DATE(this); | 391 CHECK_DATE(this); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 '-' + PadInt(UTC_MONTH(this) + 1, 2) + | 785 '-' + PadInt(UTC_MONTH(this) + 1, 2) + |
771 '-' + PadInt(UTC_DAY(this), 2) + | 786 '-' + PadInt(UTC_DAY(this), 2) + |
772 'T' + PadInt(UTC_HOUR(this), 2) + | 787 'T' + PadInt(UTC_HOUR(this), 2) + |
773 ':' + PadInt(UTC_MIN(this), 2) + | 788 ':' + PadInt(UTC_MIN(this), 2) + |
774 ':' + PadInt(UTC_SEC(this), 2) + | 789 ':' + PadInt(UTC_SEC(this), 2) + |
775 '.' + PadInt(UTC_MS(this), 3) + | 790 '.' + PadInt(UTC_MS(this), 3) + |
776 'Z'; | 791 'Z'; |
777 } | 792 } |
778 | 793 |
779 | 794 |
| 795 // 20.3.4.37 Date.prototype.toJSON ( key ) |
780 function DateToJSON(key) { | 796 function DateToJSON(key) { |
781 var o = TO_OBJECT(this); | 797 var o = TO_OBJECT(this); |
782 var tv = $defaultNumber(o); | 798 var tv = TO_PRIMITIVE_NUMBER(o); |
783 if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { | 799 if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { |
784 return null; | 800 return null; |
785 } | 801 } |
786 return o.toISOString(); | 802 return o.toISOString(); |
787 } | 803 } |
788 | 804 |
789 | 805 |
790 var date_cache_version_holder; | 806 var date_cache_version_holder; |
791 var date_cache_version = NAN; | 807 var date_cache_version = NAN; |
792 | 808 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 840 |
825 // Set up non-enumerable properties of the Date object itself. | 841 // Set up non-enumerable properties of the Date object itself. |
826 utils.InstallFunctions(GlobalDate, DONT_ENUM, [ | 842 utils.InstallFunctions(GlobalDate, DONT_ENUM, [ |
827 "UTC", DateUTC, | 843 "UTC", DateUTC, |
828 "parse", DateParse, | 844 "parse", DateParse, |
829 "now", DateNow | 845 "now", DateNow |
830 ]); | 846 ]); |
831 | 847 |
832 // Set up non-enumerable constructor property of the Date prototype object. | 848 // Set up non-enumerable constructor property of the Date prototype object. |
833 %AddNamedProperty(GlobalDate.prototype, "constructor", GlobalDate, DONT_ENUM); | 849 %AddNamedProperty(GlobalDate.prototype, "constructor", GlobalDate, DONT_ENUM); |
| 850 utils.SetFunctionName(DateToPrimitive, symbolToPrimitive); |
| 851 %AddNamedProperty(GlobalDate.prototype, symbolToPrimitive, DateToPrimitive, |
| 852 DONT_ENUM | READ_ONLY); |
834 | 853 |
835 // Set up non-enumerable functions of the Date prototype object and | 854 // Set up non-enumerable functions of the Date prototype object and |
836 // set their names. | 855 // set their names. |
837 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ | 856 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ |
838 "toString", DateToString, | 857 "toString", DateToString, |
839 "toDateString", DateToDateString, | 858 "toDateString", DateToDateString, |
840 "toTimeString", DateToTimeString, | 859 "toTimeString", DateToTimeString, |
841 "toLocaleString", DateToLocaleString, | 860 "toLocaleString", DateToLocaleString, |
842 "toLocaleDateString", DateToLocaleDateString, | 861 "toLocaleDateString", DateToLocaleDateString, |
843 "toLocaleTimeString", DateToLocaleTimeString, | 862 "toLocaleTimeString", DateToLocaleTimeString, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 "toUTCString", DateToUTCString, | 898 "toUTCString", DateToUTCString, |
880 "getYear", DateGetYear, | 899 "getYear", DateGetYear, |
881 "setYear", DateSetYear, | 900 "setYear", DateSetYear, |
882 "toISOString", DateToISOString, | 901 "toISOString", DateToISOString, |
883 "toJSON", DateToJSON | 902 "toJSON", DateToJSON |
884 ]); | 903 ]); |
885 | 904 |
886 %InstallToContext(["create_date_fun", CreateDate]); | 905 %InstallToContext(["create_date_fun", CreateDate]); |
887 | 906 |
888 }) | 907 }) |
OLD | NEW |