Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: src/date-delay.js

Issue 150021: Replaced DateFromTime and isNaN with macro calls in date code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/macros.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 28
29 // This file relies on the fact that the following declarations have been made 29 // This file relies on the fact that the following declarations have been made
30 // in v8natives.js: 30 // in v8natives.js:
31 // const $isNaN = GlobalIsNaN;
32 // const $isFinite = GlobalIsFinite; 31 // const $isFinite = GlobalIsFinite;
33 32
34 // ------------------------------------------------------------------- 33 // -------------------------------------------------------------------
35 34
36 // This file contains date support implemented in JavaScript. 35 // This file contains date support implemented in JavaScript.
37 36
38 37
39 // Keep reference to original values of some global properties. This 38 // Keep reference to original values of some global properties. This
40 // has the added benefit that the code in this file is isolated from 39 // has the added benefit that the code in this file is isolated from
41 // changes to these properties. 40 // changes to these properties.
42 const $Date = global.Date; 41 const $Date = global.Date;
43 42
43 // Helper function to throw error.
44 function ThrowTypeError() {
Kasper Lund 2009/06/29 12:03:07 How about calling this something with Date in the
45 throw new $TypeError('this is not a Date object.');
46 }
47
44 // ECMA 262 - 15.9.1.2 48 // ECMA 262 - 15.9.1.2
45 function Day(time) { 49 function Day(time) {
46 return FLOOR(time/msPerDay); 50 return FLOOR(time/msPerDay);
47 } 51 }
48 52
49 53
50 // ECMA 262 - 5.2 54 // ECMA 262 - 5.2
51 function Modulo(value, remainder) { 55 function Modulo(value, remainder) {
52 var mod = value % remainder; 56 var mod = value % remainder;
53 // Guard against returning -0. 57 // Guard against returning -0.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 229 }
226 230
227 231
228 function WeekDay(time) { 232 function WeekDay(time) {
229 return Modulo(Day(time) + 4, 7); 233 return Modulo(Day(time) + 4, 7);
230 } 234 }
231 235
232 var local_time_offset = %DateLocalTimeOffset(); 236 var local_time_offset = %DateLocalTimeOffset();
233 237
234 function LocalTime(time) { 238 function LocalTime(time) {
235 if ($isNaN(time)) return time; 239 if (NUMBER_IS_NAN(time)) return time;
236 return time + local_time_offset + DaylightSavingsOffset(time); 240 return time + local_time_offset + DaylightSavingsOffset(time);
237 } 241 }
238 242
239 function LocalTimeNoCheck(time) { 243 function LocalTimeNoCheck(time) {
240 return time + local_time_offset + DaylightSavingsOffset(time); 244 return time + local_time_offset + DaylightSavingsOffset(time);
241 } 245 }
242 246
243 247
244 function UTC(time) { 248 function UTC(time) {
245 if ($isNaN(time)) return time; 249 if (NUMBER_IS_NAN(time)) return time;
246 var tmp = time - local_time_offset; 250 var tmp = time - local_time_offset;
247 return tmp - DaylightSavingsOffset(tmp); 251 return tmp - DaylightSavingsOffset(tmp);
248 } 252 }
249 253
250 254
251 // ECMA 262 - 15.9.1.10 255 // ECMA 262 - 15.9.1.10
252 function HourFromTime(time) { 256 function HourFromTime(time) {
253 return Modulo(FLOOR(time / msPerHour), HoursPerDay); 257 return Modulo(FLOOR(time / msPerHour), HoursPerDay);
254 } 258 }
255 259
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 451 }
448 return; 452 return;
449 } 453 }
450 year = ToNumber(year); 454 year = ToNumber(year);
451 month = ToNumber(month); 455 month = ToNumber(month);
452 date = argc > 2 ? ToNumber(date) : 1; 456 date = argc > 2 ? ToNumber(date) : 1;
453 hours = argc > 3 ? ToNumber(hours) : 0; 457 hours = argc > 3 ? ToNumber(hours) : 0;
454 minutes = argc > 4 ? ToNumber(minutes) : 0; 458 minutes = argc > 4 ? ToNumber(minutes) : 0;
455 seconds = argc > 5 ? ToNumber(seconds) : 0; 459 seconds = argc > 5 ? ToNumber(seconds) : 0;
456 ms = argc > 6 ? ToNumber(ms) : 0; 460 ms = argc > 6 ? ToNumber(ms) : 0;
457 year = (!$isNaN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) 461 year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
458 ? 1900 + TO_INTEGER(year) : year; 462 ? 1900 + TO_INTEGER(year) : year;
459 var day = MakeDay(year, month, date); 463 var day = MakeDay(year, month, date);
460 var time = MakeTime(hours, minutes, seconds, ms); 464 var time = MakeTime(hours, minutes, seconds, ms);
461 %_SetValueOf(this, TimeClip(UTC(MakeDate(day, time)))); 465 %_SetValueOf(this, TimeClip(UTC(MakeDate(day, time))));
462 } else { 466 } else {
463 // ECMA 262 - 15.9.2 467 // ECMA 262 - 15.9.2
464 return (new $Date()).toString(); 468 return (new $Date()).toString();
465 } 469 }
466 }); 470 });
467 471
468 472
469 // Helper functions. 473 // Helper functions.
470 function GetTimeFrom(aDate) { 474 function GetTimeFrom(aDate) {
471 if (IS_DATE(aDate)) return %_ValueOf(aDate); 475 return DATE_VALUE(aDate);
472 throw new $TypeError('this is not a Date object.');
473 } 476 }
474 477
475 478
476 function GetMillisecondsFrom(aDate) { 479 function GetMillisecondsFrom(aDate) {
477 var t = GetTimeFrom(aDate); 480 var t = DATE_VALUE(aDate);
478 if ($isNaN(t)) return t; 481 if (NUMBER_IS_NAN(t)) return t;
479 return msFromTime(LocalTimeNoCheck(t)); 482 return msFromTime(LocalTimeNoCheck(t));
480 } 483 }
481 484
482 485
483 function GetUTCMillisecondsFrom(aDate) { 486 function GetUTCMillisecondsFrom(aDate) {
484 var t = GetTimeFrom(aDate); 487 var t = DATE_VALUE(aDate);
485 if ($isNaN(t)) return t; 488 if (NUMBER_IS_NAN(t)) return t;
486 return msFromTime(t); 489 return msFromTime(t);
487 } 490 }
488 491
489 492
490 function GetSecondsFrom(aDate) { 493 function GetSecondsFrom(aDate) {
491 var t = GetTimeFrom(aDate); 494 var t = DATE_VALUE(aDate);
492 if ($isNaN(t)) return t; 495 if (NUMBER_IS_NAN(t)) return t;
493 return SecFromTime(LocalTimeNoCheck(t)); 496 return SecFromTime(LocalTimeNoCheck(t));
494 } 497 }
495 498
496 499
497 function GetUTCSecondsFrom(aDate) { 500 function GetUTCSecondsFrom(aDate) {
498 var t = GetTimeFrom(aDate); 501 var t = DATE_VALUE(aDate);
499 if ($isNaN(t)) return t; 502 if (NUMBER_IS_NAN(t)) return t;
500 return SecFromTime(t); 503 return SecFromTime(t);
501 } 504 }
502 505
503 506
504 function GetMinutesFrom(aDate) { 507 function GetMinutesFrom(aDate) {
505 var t = GetTimeFrom(aDate); 508 var t = DATE_VALUE(aDate);
506 if ($isNaN(t)) return t; 509 if (NUMBER_IS_NAN(t)) return t;
507 return MinFromTime(LocalTimeNoCheck(t)); 510 return MinFromTime(LocalTimeNoCheck(t));
508 } 511 }
509 512
510 513
511 function GetUTCMinutesFrom(aDate) { 514 function GetUTCMinutesFrom(aDate) {
512 var t = GetTimeFrom(aDate); 515 var t = DATE_VALUE(aDate);
513 if ($isNaN(t)) return t; 516 if (NUMBER_IS_NAN(t)) return t;
514 return MinFromTime(t); 517 return MinFromTime(t);
515 } 518 }
516 519
517 520
518 function GetHoursFrom(aDate) { 521 function GetHoursFrom(aDate) {
519 var t = GetTimeFrom(aDate); 522 var t = DATE_VALUE(aDate);
520 if ($isNaN(t)) return t; 523 if (NUMBER_IS_NAN(t)) return t;
521 return HourFromTime(LocalTimeNoCheck(t)); 524 return HourFromTime(LocalTimeNoCheck(t));
522 } 525 }
523 526
524 527
525 function GetUTCHoursFrom(aDate) { 528 function GetUTCHoursFrom(aDate) {
526 var t = GetTimeFrom(aDate); 529 var t = DATE_VALUE(aDate);
527 if ($isNaN(t)) return t; 530 if (NUMBER_IS_NAN(t)) return t;
528 return HourFromTime(t); 531 return HourFromTime(t);
529 } 532 }
530 533
531 534
532 function GetFullYearFrom(aDate) { 535 function GetFullYearFrom(aDate) {
533 var t = GetTimeFrom(aDate); 536 var t = DATE_VALUE(aDate);
534 if ($isNaN(t)) return t; 537 if (NUMBER_IS_NAN(t)) return t;
535 // Ignore the DST offset for year computations. 538 // Ignore the DST offset for year computations.
536 return YearFromTime(t + local_time_offset); 539 return YearFromTime(t + local_time_offset);
537 } 540 }
538 541
539 542
540 function GetUTCFullYearFrom(aDate) { 543 function GetUTCFullYearFrom(aDate) {
541 var t = GetTimeFrom(aDate); 544 var t = DATE_VALUE(aDate);
542 if ($isNaN(t)) return t; 545 if (NUMBER_IS_NAN(t)) return t;
543 return YearFromTime(t); 546 return YearFromTime(t);
544 } 547 }
545 548
546 549
547 function GetMonthFrom(aDate) { 550 function GetMonthFrom(aDate) {
548 var t = GetTimeFrom(aDate); 551 var t = DATE_VALUE(aDate);
549 if ($isNaN(t)) return t; 552 if (NUMBER_IS_NAN(t)) return t;
550 return MonthFromTime(LocalTimeNoCheck(t)); 553 return MonthFromTime(LocalTimeNoCheck(t));
551 } 554 }
552 555
553 556
554 function GetUTCMonthFrom(aDate) { 557 function GetUTCMonthFrom(aDate) {
555 var t = GetTimeFrom(aDate); 558 var t = DATE_VALUE(aDate);
556 if ($isNaN(t)) return t; 559 if (NUMBER_IS_NAN(t)) return t;
557 return MonthFromTime(t); 560 return MonthFromTime(t);
558 } 561 }
559 562
560 563
561 function GetDateFrom(aDate) { 564 function GetDateFrom(aDate) {
562 var t = GetTimeFrom(aDate); 565 var t = DATE_VALUE(aDate);
563 if ($isNaN(t)) return t; 566 if (NUMBER_IS_NAN(t)) return t;
564 return DateFromTime(LocalTimeNoCheck(t)); 567 return DateFromTime(LocalTimeNoCheck(t));
565 } 568 }
566 569
567 570
568 function GetUTCDateFrom(aDate) { 571 function GetUTCDateFrom(aDate) {
569 var t = GetTimeFrom(aDate); 572 var t = DATE_VALUE(aDate);
570 if ($isNaN(t)) return t; 573 if (NUMBER_IS_NAN(t)) return t;
571 return DateFromTime(t); 574 return DateFromTime(t);
572 } 575 }
573 576
574 577
575 %FunctionSetPrototype($Date, new $Date($NaN)); 578 %FunctionSetPrototype($Date, new $Date($NaN));
576 579
577 580
578 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 581 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
579 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc t', 'Nov', 'Dec']; 582 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc t', 'Nov', 'Dec'];
580 583
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 // ECMA 262 - 15.9.4.3 655 // ECMA 262 - 15.9.4.3
653 function DateUTC(year, month, date, hours, minutes, seconds, ms) { 656 function DateUTC(year, month, date, hours, minutes, seconds, ms) {
654 year = ToNumber(year); 657 year = ToNumber(year);
655 month = ToNumber(month); 658 month = ToNumber(month);
656 var argc = %_ArgumentsLength(); 659 var argc = %_ArgumentsLength();
657 date = argc > 2 ? ToNumber(date) : 1; 660 date = argc > 2 ? ToNumber(date) : 1;
658 hours = argc > 3 ? ToNumber(hours) : 0; 661 hours = argc > 3 ? ToNumber(hours) : 0;
659 minutes = argc > 4 ? ToNumber(minutes) : 0; 662 minutes = argc > 4 ? ToNumber(minutes) : 0;
660 seconds = argc > 5 ? ToNumber(seconds) : 0; 663 seconds = argc > 5 ? ToNumber(seconds) : 0;
661 ms = argc > 6 ? ToNumber(ms) : 0; 664 ms = argc > 6 ? ToNumber(ms) : 0;
662 year = (!$isNaN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) 665 year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 9 9)
663 ? 1900 + TO_INTEGER(year) : year; 666 ? 1900 + TO_INTEGER(year) : year;
664 var day = MakeDay(year, month, date); 667 var day = MakeDay(year, month, date);
665 var time = MakeTime(hours, minutes, seconds, ms); 668 var time = MakeTime(hours, minutes, seconds, ms);
666 return %_SetValueOf(this, TimeClip(MakeDate(day, time))); 669 return %_SetValueOf(this, TimeClip(MakeDate(day, time)));
667 } 670 }
668 671
669 672
670 // Mozilla-specific extension. Returns the number of milliseconds 673 // Mozilla-specific extension. Returns the number of milliseconds
671 // elapsed since 1 January 1970 00:00:00 UTC. 674 // elapsed since 1 January 1970 00:00:00 UTC.
672 function DateNow() { 675 function DateNow() {
673 return %DateCurrentTime(); 676 return %DateCurrentTime();
674 } 677 }
675 678
676 679
677 // ECMA 262 - 15.9.5.2 680 // ECMA 262 - 15.9.5.2
678 function DateToString() { 681 function DateToString() {
679 var t = GetTimeFrom(this); 682 var t = DATE_VALUE(this);
680 if ($isNaN(t)) return kInvalidDate; 683 if (NUMBER_IS_NAN(t)) return kInvalidDate;
681 return DatePrintString(LocalTimeNoCheck(t)) + LocalTimezoneString(t); 684 return DatePrintString(LocalTimeNoCheck(t)) + LocalTimezoneString(t);
682 } 685 }
683 686
684 687
685 // ECMA 262 - 15.9.5.3 688 // ECMA 262 - 15.9.5.3
686 function DateToDateString() { 689 function DateToDateString() {
687 var t = GetTimeFrom(this); 690 var t = DATE_VALUE(this);
688 if ($isNaN(t)) return kInvalidDate; 691 if (NUMBER_IS_NAN(t)) return kInvalidDate;
689 return DateString(LocalTimeNoCheck(t)); 692 return DateString(LocalTimeNoCheck(t));
690 } 693 }
691 694
692 695
693 // ECMA 262 - 15.9.5.4 696 // ECMA 262 - 15.9.5.4
694 function DateToTimeString() { 697 function DateToTimeString() {
695 var t = GetTimeFrom(this); 698 var t = DATE_VALUE(this);
696 if ($isNaN(t)) return kInvalidDate; 699 if (NUMBER_IS_NAN(t)) return kInvalidDate;
697 var lt = LocalTimeNoCheck(t); 700 var lt = LocalTimeNoCheck(t);
698 return TimeString(lt) + LocalTimezoneString(lt); 701 return TimeString(lt) + LocalTimezoneString(lt);
699 } 702 }
700 703
701 704
702 // ECMA 262 - 15.9.5.5 705 // ECMA 262 - 15.9.5.5
703 function DateToLocaleString() { 706 function DateToLocaleString() {
704 return DateToString.call(this); 707 return DateToString.call(this);
705 } 708 }
706 709
707 710
708 // ECMA 262 - 15.9.5.6 711 // ECMA 262 - 15.9.5.6
709 function DateToLocaleDateString() { 712 function DateToLocaleDateString() {
710 var t = GetTimeFrom(this); 713 var t = DATE_VALUE(this);
711 if ($isNaN(t)) return kInvalidDate; 714 if (NUMBER_IS_NAN(t)) return kInvalidDate;
712 return LongDateString(LocalTimeNoCheck(t)); 715 return LongDateString(LocalTimeNoCheck(t));
713 } 716 }
714 717
715 718
716 // ECMA 262 - 15.9.5.7 719 // ECMA 262 - 15.9.5.7
717 function DateToLocaleTimeString() { 720 function DateToLocaleTimeString() {
718 var t = GetTimeFrom(this); 721 var t = DATE_VALUE(this);
719 if ($isNaN(t)) return kInvalidDate; 722 if (NUMBER_IS_NAN(t)) return kInvalidDate;
720 var lt = LocalTimeNoCheck(t); 723 var lt = LocalTimeNoCheck(t);
721 return TimeString(lt); 724 return TimeString(lt);
722 } 725 }
723 726
724 727
725 // ECMA 262 - 15.9.5.8 728 // ECMA 262 - 15.9.5.8
726 function DateValueOf() { 729 function DateValueOf() {
727 return GetTimeFrom(this); 730 return DATE_VALUE(this);
728 } 731 }
729 732
730 733
731 // ECMA 262 - 15.9.5.9 734 // ECMA 262 - 15.9.5.9
732 function DateGetTime() { 735 function DateGetTime() {
733 return GetTimeFrom(this); 736 return DATE_VALUE(this);
734 } 737 }
735 738
736 739
737 // ECMA 262 - 15.9.5.10 740 // ECMA 262 - 15.9.5.10
738 function DateGetFullYear() { 741 function DateGetFullYear() {
739 return GetFullYearFrom(this) 742 return GetFullYearFrom(this)
740 } 743 }
741 744
742 745
743 // ECMA 262 - 15.9.5.11 746 // ECMA 262 - 15.9.5.11
(...skipping 21 matching lines...) Expand all
765 768
766 769
767 // ECMA 262 - 15.9.5.15 770 // ECMA 262 - 15.9.5.15
768 function DateGetUTCDate() { 771 function DateGetUTCDate() {
769 return GetUTCDateFrom(this); 772 return GetUTCDateFrom(this);
770 } 773 }
771 774
772 775
773 // ECMA 262 - 15.9.5.16 776 // ECMA 262 - 15.9.5.16
774 function DateGetDay() { 777 function DateGetDay() {
775 var t = GetTimeFrom(this); 778 var t = %_ValueOf(this);
776 if ($isNaN(t)) return t; 779 if (NUMBER_IS_NAN(t)) return t;
777 return WeekDay(LocalTimeNoCheck(t)); 780 return WeekDay(LocalTimeNoCheck(t));
778 } 781 }
779 782
780 783
781 // ECMA 262 - 15.9.5.17 784 // ECMA 262 - 15.9.5.17
782 function DateGetUTCDay() { 785 function DateGetUTCDay() {
783 var t = GetTimeFrom(this); 786 var t = %_ValueOf(this);
784 if ($isNaN(t)) return t; 787 if (NUMBER_IS_NAN(t)) return t;
785 return WeekDay(t); 788 return WeekDay(t);
786 } 789 }
787 790
788 791
789 // ECMA 262 - 15.9.5.18 792 // ECMA 262 - 15.9.5.18
790 function DateGetHours() { 793 function DateGetHours() {
791 return GetHoursFrom(this); 794 return GetHoursFrom(this);
792 } 795 }
793 796
794 797
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 832
830 833
831 // ECMA 262 - 15.9.5.25 834 // ECMA 262 - 15.9.5.25
832 function DateGetUTCMilliseconds() { 835 function DateGetUTCMilliseconds() {
833 return GetUTCMillisecondsFrom(this); 836 return GetUTCMillisecondsFrom(this);
834 } 837 }
835 838
836 839
837 // ECMA 262 - 15.9.5.26 840 // ECMA 262 - 15.9.5.26
838 function DateGetTimezoneOffset() { 841 function DateGetTimezoneOffset() {
839 var t = GetTimeFrom(this); 842 var t = DATE_VALUE(this);
840 if ($isNaN(t)) return t; 843 if (NUMBER_IS_NAN(t)) return t;
841 return (t - LocalTimeNoCheck(t)) / msPerMinute; 844 return (t - LocalTimeNoCheck(t)) / msPerMinute;
842 } 845 }
843 846
844 847
845 // ECMA 262 - 15.9.5.27 848 // ECMA 262 - 15.9.5.27
846 function DateSetTime(ms) { 849 function DateSetTime(ms) {
847 if (!IS_DATE(this)) throw new $TypeError('this is not a Date object.'); 850 if (!IS_DATE(this)) ThrowTypeError();
848 return %_SetValueOf(this, TimeClip(ToNumber(ms))); 851 return %_SetValueOf(this, TimeClip(ToNumber(ms)));
849 } 852 }
850 853
851 854
852 // ECMA 262 - 15.9.5.28 855 // ECMA 262 - 15.9.5.28
853 function DateSetMilliseconds(ms) { 856 function DateSetMilliseconds(ms) {
854 var t = LocalTime(GetTimeFrom(this)); 857 var t = LocalTime(DATE_VALUE(this));
855 ms = ToNumber(ms); 858 ms = ToNumber(ms);
856 var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms); 859 var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms);
857 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); 860 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
858 } 861 }
859 862
860 863
861 // ECMA 262 - 15.9.5.29 864 // ECMA 262 - 15.9.5.29
862 function DateSetUTCMilliseconds(ms) { 865 function DateSetUTCMilliseconds(ms) {
863 var t = GetTimeFrom(this); 866 var t = DATE_VALUE(this);
864 ms = ToNumber(ms); 867 ms = ToNumber(ms);
865 var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms); 868 var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms);
866 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); 869 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
867 } 870 }
868 871
869 872
870 // ECMA 262 - 15.9.5.30 873 // ECMA 262 - 15.9.5.30
871 function DateSetSeconds(sec, ms) { 874 function DateSetSeconds(sec, ms) {
872 var t = LocalTime(GetTimeFrom(this)); 875 var t = LocalTime(DATE_VALUE(this));
873 sec = ToNumber(sec); 876 sec = ToNumber(sec);
874 ms = %_ArgumentsLength() < 2 ? GetMillisecondsFrom(this) : ToNumber(ms); 877 ms = %_ArgumentsLength() < 2 ? GetMillisecondsFrom(this) : ToNumber(ms);
875 var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms); 878 var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms);
876 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); 879 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
877 } 880 }
878 881
879 882
880 // ECMA 262 - 15.9.5.31 883 // ECMA 262 - 15.9.5.31
881 function DateSetUTCSeconds(sec, ms) { 884 function DateSetUTCSeconds(sec, ms) {
882 var t = GetTimeFrom(this); 885 var t = DATE_VALUE(this);
883 sec = ToNumber(sec); 886 sec = ToNumber(sec);
884 ms = %_ArgumentsLength() < 2 ? GetUTCMillisecondsFrom(this) : ToNumber(ms); 887 ms = %_ArgumentsLength() < 2 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
885 var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms); 888 var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms);
886 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); 889 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
887 } 890 }
888 891
889 892
890 // ECMA 262 - 15.9.5.33 893 // ECMA 262 - 15.9.5.33
891 function DateSetMinutes(min, sec, ms) { 894 function DateSetMinutes(min, sec, ms) {
892 var t = LocalTime(GetTimeFrom(this)); 895 var t = LocalTime(DATE_VALUE(this));
893 min = ToNumber(min); 896 min = ToNumber(min);
894 var argc = %_ArgumentsLength(); 897 var argc = %_ArgumentsLength();
895 sec = argc < 2 ? GetSecondsFrom(this) : ToNumber(sec); 898 sec = argc < 2 ? GetSecondsFrom(this) : ToNumber(sec);
896 ms = argc < 3 ? GetMillisecondsFrom(this) : ToNumber(ms); 899 ms = argc < 3 ? GetMillisecondsFrom(this) : ToNumber(ms);
897 var time = MakeTime(HourFromTime(t), min, sec, ms); 900 var time = MakeTime(HourFromTime(t), min, sec, ms);
898 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); 901 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
899 } 902 }
900 903
901 904
902 // ECMA 262 - 15.9.5.34 905 // ECMA 262 - 15.9.5.34
903 function DateSetUTCMinutes(min, sec, ms) { 906 function DateSetUTCMinutes(min, sec, ms) {
904 var t = GetTimeFrom(this); 907 var t = DATE_VALUE(this);
905 min = ToNumber(min); 908 min = ToNumber(min);
906 var argc = %_ArgumentsLength(); 909 var argc = %_ArgumentsLength();
907 sec = argc < 2 ? GetUTCSecondsFrom(this) : ToNumber(sec); 910 sec = argc < 2 ? GetUTCSecondsFrom(this) : ToNumber(sec);
908 ms = argc < 3 ? GetUTCMillisecondsFrom(this) : ToNumber(ms); 911 ms = argc < 3 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
909 var time = MakeTime(HourFromTime(t), min, sec, ms); 912 var time = MakeTime(HourFromTime(t), min, sec, ms);
910 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); 913 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
911 } 914 }
912 915
913 916
914 // ECMA 262 - 15.9.5.35 917 // ECMA 262 - 15.9.5.35
915 function DateSetHours(hour, min, sec, ms) { 918 function DateSetHours(hour, min, sec, ms) {
916 var t = LocalTime(GetTimeFrom(this)); 919 var t = LocalTime(DATE_VALUE(this));
917 hour = ToNumber(hour); 920 hour = ToNumber(hour);
918 var argc = %_ArgumentsLength(); 921 var argc = %_ArgumentsLength();
919 min = argc < 2 ? GetMinutesFrom(this) : ToNumber(min); 922 min = argc < 2 ? GetMinutesFrom(this) : ToNumber(min);
920 sec = argc < 3 ? GetSecondsFrom(this) : ToNumber(sec); 923 sec = argc < 3 ? GetSecondsFrom(this) : ToNumber(sec);
921 ms = argc < 4 ? GetMillisecondsFrom(this) : ToNumber(ms); 924 ms = argc < 4 ? GetMillisecondsFrom(this) : ToNumber(ms);
922 var time = MakeTime(hour, min, sec, ms); 925 var time = MakeTime(hour, min, sec, ms);
923 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time)))); 926 return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
924 } 927 }
925 928
926 929
927 // ECMA 262 - 15.9.5.34 930 // ECMA 262 - 15.9.5.34
928 function DateSetUTCHours(hour, min, sec, ms) { 931 function DateSetUTCHours(hour, min, sec, ms) {
929 var t = GetTimeFrom(this); 932 var t = DATE_VALUE(this);
930 hour = ToNumber(hour); 933 hour = ToNumber(hour);
931 var argc = %_ArgumentsLength(); 934 var argc = %_ArgumentsLength();
932 min = argc < 2 ? GetUTCMinutesFrom(this) : ToNumber(min); 935 min = argc < 2 ? GetUTCMinutesFrom(this) : ToNumber(min);
933 sec = argc < 3 ? GetUTCSecondsFrom(this) : ToNumber(sec); 936 sec = argc < 3 ? GetUTCSecondsFrom(this) : ToNumber(sec);
934 ms = argc < 4 ? GetUTCMillisecondsFrom(this) : ToNumber(ms); 937 ms = argc < 4 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
935 var time = MakeTime(hour, min, sec, ms); 938 var time = MakeTime(hour, min, sec, ms);
936 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time))); 939 return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
937 } 940 }
938 941
939 942
940 // ECMA 262 - 15.9.5.36 943 // ECMA 262 - 15.9.5.36
941 function DateSetDate(date) { 944 function DateSetDate(date) {
942 var t = LocalTime(GetTimeFrom(this)); 945 var t = LocalTime(DATE_VALUE(this));
943 date = ToNumber(date); 946 date = ToNumber(date);
944 var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); 947 var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
945 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); 948 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
946 } 949 }
947 950
948 951
949 // ECMA 262 - 15.9.5.37 952 // ECMA 262 - 15.9.5.37
950 function DateSetUTCDate(date) { 953 function DateSetUTCDate(date) {
951 var t = GetTimeFrom(this); 954 var t = DATE_VALUE(this);
952 date = ToNumber(date); 955 date = ToNumber(date);
953 var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); 956 var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
954 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); 957 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
955 } 958 }
956 959
957 960
958 // ECMA 262 - 15.9.5.38 961 // ECMA 262 - 15.9.5.38
959 function DateSetMonth(month, date) { 962 function DateSetMonth(month, date) {
960 var t = LocalTime(GetTimeFrom(this)); 963 var t = LocalTime(DATE_VALUE(this));
961 month = ToNumber(month); 964 month = ToNumber(month);
962 date = %_ArgumentsLength() < 2 ? GetDateFrom(this) : ToNumber(date); 965 date = %_ArgumentsLength() < 2 ? GetDateFrom(this) : ToNumber(date);
963 var day = MakeDay(YearFromTime(t), month, date); 966 var day = MakeDay(YearFromTime(t), month, date);
964 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); 967 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
965 } 968 }
966 969
967 970
968 // ECMA 262 - 15.9.5.39 971 // ECMA 262 - 15.9.5.39
969 function DateSetUTCMonth(month, date) { 972 function DateSetUTCMonth(month, date) {
970 var t = GetTimeFrom(this); 973 var t = DATE_VALUE(this);
971 month = ToNumber(month); 974 month = ToNumber(month);
972 date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date); 975 date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date);
973 var day = MakeDay(YearFromTime(t), month, date); 976 var day = MakeDay(YearFromTime(t), month, date);
974 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); 977 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
975 } 978 }
976 979
977 980
978 // ECMA 262 - 15.9.5.40 981 // ECMA 262 - 15.9.5.40
979 function DateSetFullYear(year, month, date) { 982 function DateSetFullYear(year, month, date) {
980 var t = GetTimeFrom(this); 983 var t = DATE_VALUE(this);
981 t = $isNaN(t) ? 0 : LocalTimeNoCheck(t); 984 t = NUMBER_IS_NAN(t) ? 0 : LocalTimeNoCheck(t);
982 year = ToNumber(year); 985 year = ToNumber(year);
983 var argc = %_ArgumentsLength(); 986 var argc = %_ArgumentsLength();
984 month = argc < 2 ? MonthFromTime(t) : ToNumber(month); 987 month = argc < 2 ? MonthFromTime(t) : ToNumber(month);
985 date = argc < 3 ? DateFromTime(t) : ToNumber(date); 988 date = argc < 3 ? DateFromTime(t) : ToNumber(date);
986 var day = MakeDay(year, month, date); 989 var day = MakeDay(year, month, date);
987 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); 990 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
988 } 991 }
989 992
990 993
991 // ECMA 262 - 15.9.5.41 994 // ECMA 262 - 15.9.5.41
992 function DateSetUTCFullYear(year, month, date) { 995 function DateSetUTCFullYear(year, month, date) {
993 var t = GetTimeFrom(this); 996 var t = DATE_VALUE(this);
994 if ($isNaN(t)) t = 0; 997 if (NUMBER_IS_NAN(t)) t = 0;
995 var argc = %_ArgumentsLength(); 998 var argc = %_ArgumentsLength();
996 year = ToNumber(year); 999 year = ToNumber(year);
997 month = argc < 2 ? MonthFromTime(t) : ToNumber(month); 1000 month = argc < 2 ? MonthFromTime(t) : ToNumber(month);
998 date = argc < 3 ? DateFromTime(t) : ToNumber(date); 1001 date = argc < 3 ? DateFromTime(t) : ToNumber(date);
999 var day = MakeDay(year, month, date); 1002 var day = MakeDay(year, month, date);
1000 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); 1003 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
1001 } 1004 }
1002 1005
1003 1006
1004 // ECMA 262 - 15.9.5.42 1007 // ECMA 262 - 15.9.5.42
1005 function DateToUTCString() { 1008 function DateToUTCString() {
1006 var t = GetTimeFrom(this); 1009 var t = DATE_VALUE(this);
1007 if ($isNaN(t)) return kInvalidDate; 1010 if (NUMBER_IS_NAN(t)) return kInvalidDate;
1008 // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT 1011 // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT
1009 return WeekDays[WeekDay(t)] + ', ' 1012 return WeekDays[WeekDay(t)] + ', '
1010 + TwoDigitString(DateFromTime(t)) + ' ' 1013 + TwoDigitString(DateFromTime(t)) + ' '
1011 + Months[MonthFromTime(t)] + ' ' 1014 + Months[MonthFromTime(t)] + ' '
1012 + YearFromTime(t) + ' ' 1015 + YearFromTime(t) + ' '
1013 + TimeString(t) + ' GMT'; 1016 + TimeString(t) + ' GMT';
1014 } 1017 }
1015 1018
1016 1019
1017 // ECMA 262 - B.2.4 1020 // ECMA 262 - B.2.4
1018 function DateGetYear() { 1021 function DateGetYear() {
1019 var t = GetTimeFrom(this); 1022 var t = DATE_VALUE(this);
1020 if ($isNaN(t)) return $NaN; 1023 if (NUMBER_IS_NAN(t)) return $NaN;
1021 return YearFromTime(LocalTimeNoCheck(t)) - 1900; 1024 return YearFromTime(LocalTimeNoCheck(t)) - 1900;
1022 } 1025 }
1023 1026
1024 1027
1025 // ECMA 262 - B.2.5 1028 // ECMA 262 - B.2.5
1026 function DateSetYear(year) { 1029 function DateSetYear(year) {
1027 var t = LocalTime(GetTimeFrom(this)); 1030 var t = LocalTime(DATE_VALUE(this));
1028 if ($isNaN(t)) t = 0; 1031 if (NUMBER_IS_NAN(t)) t = 0;
1029 year = ToNumber(year); 1032 year = ToNumber(year);
1030 if ($isNaN(year)) return %_SetValueOf(this, $NaN); 1033 if (NUMBER_IS_NAN(year)) return %_SetValueOf(this, $NaN);
1031 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) 1034 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
1032 ? 1900 + TO_INTEGER(year) : year; 1035 ? 1900 + TO_INTEGER(year) : year;
1033 var day = MakeDay(year, MonthFromTime(t), DateFromTime(t)); 1036 var day = MakeDay(year, MonthFromTime(t), DateFromTime(t));
1034 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); 1037 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
1035 } 1038 }
1036 1039
1037 1040
1038 // ECMA 262 - B.2.6 1041 // ECMA 262 - B.2.6
1039 // 1042 //
1040 // Notice that this does not follow ECMA 262 completely. ECMA 262 1043 // Notice that this does not follow ECMA 262 completely. ECMA 262
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 "toGMTString", DateToGMTString, 1128 "toGMTString", DateToGMTString,
1126 "toUTCString", DateToUTCString, 1129 "toUTCString", DateToUTCString,
1127 "getYear", DateGetYear, 1130 "getYear", DateGetYear,
1128 "setYear", DateSetYear, 1131 "setYear", DateSetYear,
1129 "toISOString", DateToISOString, 1132 "toISOString", DateToISOString,
1130 "toJSON", DateToJSON 1133 "toJSON", DateToJSON
1131 )); 1134 ));
1132 } 1135 }
1133 1136
1134 SetupDate(); 1137 SetupDate();
OLDNEW
« no previous file with comments | « no previous file | src/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698