|
1 // Any copyright is dedicated to the Public Domain. |
|
2 // http://creativecommons.org/licenses/publicdomain/ |
|
3 |
|
4 //----------------------------------------------------------------------------- |
|
5 print("Test for correct short-circuiting implementation of Date.set methods"); |
|
6 |
|
7 /************** |
|
8 * BEGIN TEST * |
|
9 **************/ |
|
10 var global = 0; |
|
11 var date; |
|
12 |
|
13 /* Test that methods don't short circuit argument evaluation. */ |
|
14 date = new Date(0).setSeconds(NaN, {valueOf:function(){global = 3}}); |
|
15 assertEq(global, 3); |
|
16 |
|
17 date = new Date(0).setUTCSeconds(NaN, {valueOf:function(){global = 4}}); |
|
18 assertEq(global, 4); |
|
19 |
|
20 date = new Date(0).setMinutes(NaN, {valueOf:function(){global = 5}}); |
|
21 assertEq(global, 5); |
|
22 |
|
23 date = new Date(0).setUTCMinutes(NaN, {valueOf:function(){global = 6}}); |
|
24 assertEq(global, 6); |
|
25 |
|
26 date = new Date(0).setHours(NaN, {valueOf:function(){global = 7}}); |
|
27 assertEq(global, 7); |
|
28 |
|
29 date = new Date(0).setUTCHours(NaN, {valueOf:function(){global = 8}}); |
|
30 assertEq(global, 8); |
|
31 |
|
32 date = new Date(0).setMonth(NaN, {valueOf:function(){global = 11}}); |
|
33 assertEq(global, 11); |
|
34 |
|
35 date = new Date(0).setUTCMonth(NaN, {valueOf:function(){global = 12}}); |
|
36 assertEq(global, 12); |
|
37 |
|
38 date = new Date(0).setFullYear(NaN, {valueOf:function(){global = 13}}); |
|
39 assertEq(global, 13); |
|
40 |
|
41 date = new Date(0).setUTCFullYear(NaN, {valueOf:function(){global = 14}}); |
|
42 assertEq(global, 14); |
|
43 |
|
44 |
|
45 |
|
46 /* Test that argument evaluation is not short circuited if Date == NaN */ |
|
47 date = new Date(NaN).setMilliseconds({valueOf:function(){global = 15}}); |
|
48 assertEq(global, 15); |
|
49 |
|
50 date = new Date(NaN).setUTCMilliseconds({valueOf:function(){global = 16}}); |
|
51 assertEq(global, 16); |
|
52 |
|
53 date = new Date(NaN).setSeconds({valueOf:function(){global = 17}}); |
|
54 assertEq(global, 17); |
|
55 |
|
56 date = new Date(NaN).setUTCSeconds({valueOf:function(){global = 18}}); |
|
57 assertEq(global, 18); |
|
58 |
|
59 date = new Date(NaN).setMinutes({valueOf:function(){global = 19}}); |
|
60 assertEq(global, 19); |
|
61 |
|
62 date = new Date(NaN).setUTCMinutes({valueOf:function(){global = 20}}); |
|
63 assertEq(global, 20); |
|
64 |
|
65 date = new Date(NaN).setHours({valueOf:function(){global = 21}}); |
|
66 assertEq(global, 21); |
|
67 |
|
68 date = new Date(NaN).setUTCHours({valueOf:function(){global = 22}}); |
|
69 assertEq(global, 22); |
|
70 |
|
71 date = new Date(NaN).setDate({valueOf:function(){global = 23}}); |
|
72 assertEq(global, 23); |
|
73 |
|
74 date = new Date(NaN).setUTCDate({valueOf:function(){global = 24}}); |
|
75 assertEq(global, 24); |
|
76 |
|
77 date = new Date(NaN).setMonth({valueOf:function(){global = 25}}); |
|
78 assertEq(global, 25); |
|
79 |
|
80 date = new Date(NaN).setUTCMonth({valueOf:function(){global = 26}}); |
|
81 assertEq(global, 26); |
|
82 |
|
83 date = new Date(NaN).setFullYear({valueOf:function(){global = 27}}); |
|
84 assertEq(global, 27); |
|
85 |
|
86 date = new Date(NaN).setUTCFullYear({valueOf:function(){global = 28}}); |
|
87 assertEq(global, 28); |
|
88 |
|
89 |
|
90 /* Test the combination of the above two. */ |
|
91 date = new Date(NaN).setSeconds(NaN, {valueOf:function(){global = 31}}); |
|
92 assertEq(global, 31); |
|
93 |
|
94 date = new Date(NaN).setUTCSeconds(NaN, {valueOf:function(){global = 32}}); |
|
95 assertEq(global, 32); |
|
96 |
|
97 date = new Date(NaN).setMinutes(NaN, {valueOf:function(){global = 33}}); |
|
98 assertEq(global, 33); |
|
99 |
|
100 date = new Date(NaN).setUTCMinutes(NaN, {valueOf:function(){global = 34}}); |
|
101 assertEq(global, 34); |
|
102 |
|
103 date = new Date(NaN).setHours(NaN, {valueOf:function(){global = 35}}); |
|
104 assertEq(global, 35); |
|
105 |
|
106 date = new Date(NaN).setUTCHours(NaN, {valueOf:function(){global = 36}}); |
|
107 assertEq(global, 36); |
|
108 |
|
109 date = new Date(NaN).setMonth(NaN, {valueOf:function(){global = 39}}); |
|
110 assertEq(global, 39); |
|
111 |
|
112 date = new Date(NaN).setUTCMonth(NaN, {valueOf:function(){global = 40}}); |
|
113 assertEq(global, 40); |
|
114 |
|
115 date = new Date(NaN).setFullYear(NaN, {valueOf:function(){global = 41}}); |
|
116 assertEq(global, 41); |
|
117 |
|
118 date = new Date(NaN).setUTCFullYear(NaN, {valueOf:function(){global = 42}}); |
|
119 assertEq(global, 42); |
|
120 |
|
121 |
|
122 /*Test two methods evaluation*/ |
|
123 var secondGlobal = 0; |
|
124 |
|
125 date = new Date(NaN).setFullYear({valueOf:function(){global = 43}}, {valueOf:function(){secondGlobal = 1}}); |
|
126 assertEq(global, 43); |
|
127 assertEq(secondGlobal, 1); |
|
128 |
|
129 date = new Date(0).setFullYear(NaN, {valueOf:function(){global = 44}}, {valueOf:function(){secondGlobal = 2}}); |
|
130 assertEq(global, 44); |
|
131 assertEq(secondGlobal, 2); |
|
132 |
|
133 |
|
134 /* Test year methods*/ |
|
135 date = new Date(0).setYear({valueOf:function(){global = 45}}); |
|
136 assertEq(global, 45); |
|
137 |
|
138 date = new Date(NaN).setYear({valueOf:function(){global = 46}}); |
|
139 assertEq(global, 46); |
|
140 |
|
141 |
|
142 /******************************************************************************/ |
|
143 |
|
144 if (typeof reportCompare === "function") |
|
145 reportCompare(true, true); |
|
146 |
|
147 print("Tests complete"); |