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