1// Copyright 2010 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// Flags: --expose-natives_as natives 30// Test the SameValue internal method. 31 32var obj1 = {x: 10, y: 11, z: "test"}; 33var obj2 = {x: 10, y: 11, z: "test"}; 34 35assertTrue(natives.SameValue(0, 0)); 36assertTrue(natives.SameValue(+0, +0)); 37assertTrue(natives.SameValue(-0, -0)); 38assertTrue(natives.SameValue(1, 1)); 39assertTrue(natives.SameValue(2, 2)); 40assertTrue(natives.SameValue(-1, -1)); 41assertTrue(natives.SameValue(0.5, 0.5)); 42assertTrue(natives.SameValue(true, true)); 43assertTrue(natives.SameValue(false, false)); 44assertTrue(natives.SameValue(NaN, NaN)); 45assertTrue(natives.SameValue(null, null)); 46assertTrue(natives.SameValue("foo", "foo")); 47assertTrue(natives.SameValue(obj1, obj1)); 48// Undefined values. 49assertTrue(natives.SameValue()); 50assertTrue(natives.SameValue(undefined, undefined)); 51 52assertFalse(natives.SameValue(0,1)); 53assertFalse(natives.SameValue("foo", "bar")); 54assertFalse(natives.SameValue(obj1, obj2)); 55assertFalse(natives.SameValue(true, false)); 56 57assertFalse(natives.SameValue(obj1, true)); 58assertFalse(natives.SameValue(obj1, "foo")); 59assertFalse(natives.SameValue(obj1, 1)); 60assertFalse(natives.SameValue(obj1, undefined)); 61assertFalse(natives.SameValue(obj1, NaN)); 62 63assertFalse(natives.SameValue(undefined, true)); 64assertFalse(natives.SameValue(undefined, "foo")); 65assertFalse(natives.SameValue(undefined, 1)); 66assertFalse(natives.SameValue(undefined, obj1)); 67assertFalse(natives.SameValue(undefined, NaN)); 68 69assertFalse(natives.SameValue(NaN, true)); 70assertFalse(natives.SameValue(NaN, "foo")); 71assertFalse(natives.SameValue(NaN, 1)); 72assertFalse(natives.SameValue(NaN, obj1)); 73assertFalse(natives.SameValue(NaN, undefined)); 74 75assertFalse(natives.SameValue("foo", true)); 76assertFalse(natives.SameValue("foo", 1)); 77assertFalse(natives.SameValue("foo", obj1)); 78assertFalse(natives.SameValue("foo", undefined)); 79assertFalse(natives.SameValue("foo", NaN)); 80 81assertFalse(natives.SameValue(true, 1)); 82assertFalse(natives.SameValue(true, obj1)); 83assertFalse(natives.SameValue(true, undefined)); 84assertFalse(natives.SameValue(true, NaN)); 85assertFalse(natives.SameValue(true, "foo")); 86 87assertFalse(natives.SameValue(1, true)); 88assertFalse(natives.SameValue(1, obj1)); 89assertFalse(natives.SameValue(1, undefined)); 90assertFalse(natives.SameValue(1, NaN)); 91assertFalse(natives.SameValue(1, "foo")); 92 93// Special string cases. 94assertFalse(natives.SameValue("1", 1)); 95assertFalse(natives.SameValue("true", true)); 96assertFalse(natives.SameValue("false", false)); 97assertFalse(natives.SameValue("undefined", undefined)); 98assertFalse(natives.SameValue("NaN", NaN)); 99 100// -0 and +0 are should be different 101assertFalse(natives.SameValue(+0, -0)); 102assertFalse(natives.SameValue(-0, +0)); 103