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 33function lt(a, b) { 34 return a < b; 35} 36 37function gt(a, b) { 38 return a > b; 39} 40 41function eq(a, b) { 42 return a == b; 43} 44 45function eq_strict(a, b) { 46 return a === b; 47} 48 49function 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 63var obj1 = {toString: function() {return "1";}}; 64var obj2 = {toString: function() {return "2";}}; 65 66var less = obj1 < obj2; 67var greater = obj1 > obj2; 68 69test(obj1, obj2, less, greater); 70test(obj1, obj2, less, greater); 71test(obj1, obj2, less, greater); 72%OptimizeFunctionOnNextCall(test); 73test(obj1, obj2, less, greater); 74test(obj1, obj2, less, greater); 75 76obj1.x = 1; 77test(obj1, obj2, less, greater); 78 79obj2.y = 2; 80test(obj1, obj2, less, greater); 81 82var obj1 = {test: 3}; 83var obj2 = {test2: 3}; 84 85var less = obj1 < obj2; 86var greater = obj1 > obj2; 87 88test(obj1, obj2, less, greater); 89test(obj1, obj2, less, greater); 90test(obj1, obj2, less, greater); 91%OptimizeFunctionOnNextCall(test); 92test(obj1, obj2, less, greater); 93test(obj1, obj2, less, greater); 94 95obj1.toString = function() {return "1"}; 96var less = obj1 < obj2; 97var greater = obj1 > obj2; 98test(obj1, obj2, less, greater); 99%OptimizeFunctionOnNextCall(test); 100test(obj1, obj2, less, greater); 101 102obj2.toString = function() {return "2"}; 103var less = true; 104var greater = false; 105 106test(obj1, obj2, less, greater); 107obj2.y = 2; 108test(obj1, obj2, less, greater); 109