blob: 41b6a95e7ada0a8b73e635eb4e40d033a000da9e [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2012 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28
29var flags;
30
31function resetFlags(size) {
32 flags = Array(size);
33 while (size--) flags[size] = 0;
34}
35
36function assertFlags(array) {
37 assertArrayEquals(array, flags);
38}
39
40function object_factory(flag_index, value, expected_flags) {
41 var obj = {};
42 obj.valueOf = function() {
43 assertFlags(expected_flags);
44 flags[flag_index]++;
45 return value;
46 }
47 return obj;
48}
49
50
51assertEquals(-Infinity, Math.max());
52
53resetFlags(1);
54assertEquals(NaN,
55 Math.max(object_factory(0, NaN, [0])));
56assertFlags([1]);
57
58resetFlags(2);
59assertEquals(NaN,
60 Math.max(object_factory(0, NaN, [0, 0]),
61 object_factory(1, 0, [1, 0])));
62assertFlags([1, 1]);
63
64resetFlags(3);
65assertEquals(NaN,
66 Math.max(object_factory(0, NaN, [0, 0, 0]),
67 object_factory(1, 0, [1, 0, 0]),
68 object_factory(2, 1, [1, 1, 0])));
69assertFlags([1, 1, 1]);
70
71resetFlags(3);
72assertEquals(NaN,
73 Math.max(object_factory(0, 2, [0, 0, 0]),
74 object_factory(1, 0, [1, 0, 0]),
75 object_factory(2, NaN, [1, 1, 0])));
76assertFlags([1, 1, 1]);
77
78resetFlags(3);
79assertEquals(2,
80 Math.max(object_factory(0, 2, [0, 0, 0]),
81 object_factory(1, 0, [1, 0, 0]),
82 object_factory(2, 1, [1, 1, 0])));
83assertFlags([1, 1, 1]);
84
85
86assertEquals(+Infinity, Math.min());
87
88resetFlags(1);
89assertEquals(NaN,
90 Math.min(object_factory(0, NaN, [0])));
91assertFlags([1]);
92
93resetFlags(2);
94assertEquals(NaN,
95 Math.min(object_factory(0, NaN, [0, 0]),
96 object_factory(1, 0, [1, 0])));
97assertFlags([1, 1]);
98
99resetFlags(3);
100assertEquals(NaN,
101 Math.min(object_factory(0, NaN, [0, 0, 0]),
102 object_factory(1, 0, [1, 0, 0]),
103 object_factory(2, 1, [1, 1, 0])));
104assertFlags([1, 1, 1]);
105
106resetFlags(3);
107assertEquals(NaN,
108 Math.min(object_factory(0, 2, [0, 0, 0]),
109 object_factory(1, 0, [1, 0, 0]),
110 object_factory(2, NaN, [1, 1, 0])));
111assertFlags([1, 1, 1]);
112
113resetFlags(3);
114assertEquals(0,
115 Math.min(object_factory(0, 2, [0, 0, 0]),
116 object_factory(1, 0, [1, 0, 0]),
117 object_factory(2, 1, [1, 1, 0])));
118assertFlags([1, 1, 1]);