Home | History | Annotate | Download | only in regress
      1 // 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 
     29 var flags;
     30 
     31 function resetFlags(size) {
     32   flags = Array(size);
     33   while (size--) flags[size] = 0;
     34 }
     35 
     36 function assertFlags(array) {
     37   assertArrayEquals(array, flags);
     38 }
     39 
     40 function 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 
     51 assertEquals(-Infinity, Math.max());
     52 
     53 resetFlags(1);
     54 assertEquals(NaN,
     55              Math.max(object_factory(0, NaN, [0])));
     56 assertFlags([1]);
     57 
     58 resetFlags(2);
     59 assertEquals(NaN,
     60              Math.max(object_factory(0, NaN, [0, 0]),
     61                       object_factory(1,   0, [1, 0])));
     62 assertFlags([1, 1]);
     63 
     64 resetFlags(3);
     65 assertEquals(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])));
     69 assertFlags([1, 1, 1]);
     70 
     71 resetFlags(3);
     72 assertEquals(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])));
     76 assertFlags([1, 1, 1]);
     77 
     78 resetFlags(3);
     79 assertEquals(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])));
     83 assertFlags([1, 1, 1]);
     84 
     85 
     86 assertEquals(+Infinity, Math.min());
     87 
     88 resetFlags(1);
     89 assertEquals(NaN,
     90              Math.min(object_factory(0, NaN, [0])));
     91 assertFlags([1]);
     92 
     93 resetFlags(2);
     94 assertEquals(NaN,
     95              Math.min(object_factory(0, NaN, [0, 0]),
     96                       object_factory(1,   0, [1, 0])));
     97 assertFlags([1, 1]);
     98 
     99 resetFlags(3);
    100 assertEquals(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])));
    104 assertFlags([1, 1, 1]);
    105 
    106 resetFlags(3);
    107 assertEquals(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])));
    111 assertFlags([1, 1, 1]);
    112 
    113 resetFlags(3);
    114 assertEquals(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])));
    118 assertFlags([1, 1, 1]);
    119