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