Home | History | Annotate | Download | only in mjsunit
      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 // Flags: --allow-natives-syntax
     29 
     30 // Test CompareIC stubs for normal and strict equality comparison of known
     31 // objects in hydrogen.
     32 
     33 function lt(a, b) {
     34   return a < b;
     35 }
     36 
     37 function gt(a, b) {
     38   return a > b;
     39 }
     40 
     41 function eq(a, b) {
     42   return a == b;
     43 }
     44 
     45 function eq_strict(a, b) {
     46   return a === b;
     47 }
     48 
     49 function test(a, b, less, greater) {
     50   // Check CompareIC for equality of known objects.
     51   assertTrue(eq(a, a));
     52   assertTrue(eq(b, b));
     53   assertFalse(eq(a, b));
     54   assertTrue(eq_strict(a, a));
     55   assertTrue(eq_strict(b, b));
     56   assertFalse(eq_strict(a, b));
     57   assertEquals(lt(a, b), less);
     58   assertEquals(gt(a, b), greater);
     59   assertEquals(lt(b, a), greater);
     60   assertEquals(gt(b, a), less);
     61 }
     62 
     63 var obj1 = {toString: function() {return "1";}};
     64 var obj2 = {toString: function() {return "2";}};
     65 
     66 var less = obj1 < obj2;
     67 var greater = obj1 > obj2;
     68 
     69 test(obj1, obj2, less, greater);
     70 test(obj1, obj2, less, greater);
     71 test(obj1, obj2, less, greater);
     72 %OptimizeFunctionOnNextCall(test);
     73 test(obj1, obj2, less, greater);
     74 test(obj1, obj2, less, greater);
     75 
     76 obj1.x = 1;
     77 test(obj1, obj2, less, greater);
     78 
     79 obj2.y = 2;
     80 test(obj1, obj2, less, greater);
     81 
     82 var obj1 = {test: 3};
     83 var obj2 = {test2: 3};
     84 
     85 var less = obj1 < obj2;
     86 var greater = obj1 > obj2;
     87 
     88 test(obj1, obj2, less, greater);
     89 test(obj1, obj2, less, greater);
     90 test(obj1, obj2, less, greater);
     91 %OptimizeFunctionOnNextCall(test);
     92 test(obj1, obj2, less, greater);
     93 test(obj1, obj2, less, greater);
     94 
     95 obj1.toString = function() {return "1"};
     96 var less = obj1 < obj2;
     97 var greater = obj1 > obj2;
     98 test(obj1, obj2, less, greater);
     99 %OptimizeFunctionOnNextCall(test);
    100 test(obj1, obj2, less, greater);
    101 
    102 obj2.toString = function() {return "2"};
    103 var less = true;
    104 var greater = false;
    105 
    106 test(obj1, obj2, less, greater);
    107 obj2.y = 2;
    108 test(obj1, obj2, less, greater);
    109