Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // |reftest| random
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 /**
9 File Name: 15.9.5.34-1.js
10 ECMA Section: 15.9.5.34 Date.prototype.setMonth(mon [, date ] )
11 Description:
12 If date is not specified, this behaves as if date were specified with the
13 value getDate( ).
15 1. Let t be the result of LocalTime(this time value).
16 2. Call ToNumber(date).
17 3. If date is not specified, compute DateFromTime(t); otherwise, call ToNumber(date).
18 4. Compute MakeDay(YearFromTime(t), Result(2), Result(3)).
19 5. Compute UTC(MakeDate(Result(4), TimeWithinDay(t))).
20 6. Set the [[Value]] property of the this value to TimeClip(Result(5)).
21 7. Return the value of the [[Value]] property of the this value.
23 Author: christine@netscape.com
24 Date: 12 november 1997
25 */
26 var SECTION = "15.9.5.34-1";
27 var VERSION = "ECMA_1";
28 startTest();
30 writeHeaderToLog( SECTION + " Date.prototype.setMonth(mon [, date ] )");
32 getFunctionCases();
34 // regression test for http://scopus.mcom.com/bugsplat/show_bug.cgi?id=112404
35 d = new Date(0);
36 d.setMonth(1,1,1,1,1,1);
38 addNewTestCase(
39 "TDATE = new Date(0); TDATE.setMonth(1,1,1,1,1,1); TDATE",
40 UTCDateFromTime(SetMonth(0,1,1)),
41 LocalDateFromTime(SetMonth(0,1,1)) );
44 // whatever today is
46 addNewTestCase( "TDATE = new Date(TIME_NOW); (TDATE).setMonth(11,31); TDATE",
47 UTCDateFromTime(SetMonth(TIME_NOW,11,31)),
48 LocalDateFromTime(SetMonth(TIME_NOW,11,31)) );
50 // 1970
52 addNewTestCase( "TDATE = new Date(0);(TDATE).setMonth(0,1);TDATE",
53 UTCDateFromTime(SetMonth(0,0,1)),
54 LocalDateFromTime(SetMonth(0,0,1)) );
56 addNewTestCase( "TDATE = new Date("+TIME_1900+"); "+
57 "(TDATE).setMonth(11,31); TDATE",
58 UTCDateFromTime( SetMonth(TIME_1900,11,31) ),
59 LocalDateFromTime( SetMonth(TIME_1900,11,31) ) );
61 test();
63 function addNewTestCase( DateString, UTCDate, LocalDate) {
64 DateCase = eval( DateString );
66 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
67 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
69 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
70 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
71 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
72 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
73 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
74 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
75 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
76 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
78 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
79 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
80 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
81 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
82 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
83 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
84 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
85 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
87 DateCase.toString = Object.prototype.toString;
89 new TestCase( SECTION,
90 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
91 "[object Date]",
92 DateCase.toString() );
93 }
95 function getFunctionCases() {
96 // some tests for all functions
97 new TestCase(
98 SECTION,
99 "Date.prototype.setMonth.length",
100 2,
101 Date.prototype.setMonth.length );
103 new TestCase(
104 SECTION,
105 "typeof Date.prototype.setMonth",
106 "function",
107 typeof Date.prototype.setMonth );
109 }
111 function MyDate() {
112 this.year = 0;
113 this.month = 0;
114 this.date = 0;
115 this.hours = 0;
116 this.minutes = 0;
117 this.seconds = 0;
118 this.ms = 0;
119 }
120 function LocalDateFromTime(t) {
121 t = LocalTime(t);
122 return ( MyDateFromTime(t) );
123 }
124 function UTCDateFromTime(t) {
125 return ( MyDateFromTime(t) );
126 }
127 function MyDateFromTime( t ) {
128 var d = new MyDate();
129 d.year = YearFromTime(t);
130 d.month = MonthFromTime(t);
131 d.date = DateFromTime(t);
132 d.hours = HourFromTime(t);
133 d.minutes = MinFromTime(t);
134 d.seconds = SecFromTime(t);
135 d.ms = msFromTime(t);
137 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
138 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
139 d.day = WeekDay( d.value );
141 return (d);
142 }
143 function SetMonth( t, mon, date ) {
144 var TIME = LocalTime(t);
145 var MONTH = Number( mon );
146 var DATE = ( date == void 0 ) ? DateFromTime(TIME) : Number( date );
147 var DAY = MakeDay( YearFromTime(TIME), MONTH, DATE );
148 return ( TimeClip (UTC(MakeDate( DAY, TimeWithinDay(TIME) ))) );
149 }