OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 14 matching lines...) Expand all Loading... |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 // Flags: --expose-natives_as natives | 29 // Flags: --expose-natives_as natives |
30 // Test the SameValue internal method. | 30 // Test the SameValue internal method. |
31 | 31 |
32 var obj1 = {x: 10, y: 11, z: "test"}; | 32 var obj1 = {x: 10, y: 11, z: "test"}; |
33 var obj2 = {x: 10, y: 11, z: "test"}; | 33 var obj2 = {x: 10, y: 11, z: "test"}; |
34 | 34 |
35 var sameValue = natives.$sameValue; | 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)); |
36 | 51 |
37 assertTrue(sameValue(0, 0)); | 52 assertFalse(natives.SameValue(0,1)); |
38 assertTrue(sameValue(+0, +0)); | 53 assertFalse(natives.SameValue("foo", "bar")); |
39 assertTrue(sameValue(-0, -0)); | 54 assertFalse(natives.SameValue(obj1, obj2)); |
40 assertTrue(sameValue(1, 1)); | 55 assertFalse(natives.SameValue(true, false)); |
41 assertTrue(sameValue(2, 2)); | |
42 assertTrue(sameValue(-1, -1)); | |
43 assertTrue(sameValue(0.5, 0.5)); | |
44 assertTrue(sameValue(true, true)); | |
45 assertTrue(sameValue(false, false)); | |
46 assertTrue(sameValue(NaN, NaN)); | |
47 assertTrue(sameValue(null, null)); | |
48 assertTrue(sameValue("foo", "foo")); | |
49 assertTrue(sameValue(obj1, obj1)); | |
50 // Undefined values. | |
51 assertTrue(sameValue()); | |
52 assertTrue(sameValue(undefined, undefined)); | |
53 | 56 |
54 assertFalse(sameValue(0,1)); | 57 assertFalse(natives.SameValue(obj1, true)); |
55 assertFalse(sameValue("foo", "bar")); | 58 assertFalse(natives.SameValue(obj1, "foo")); |
56 assertFalse(sameValue(obj1, obj2)); | 59 assertFalse(natives.SameValue(obj1, 1)); |
57 assertFalse(sameValue(true, false)); | 60 assertFalse(natives.SameValue(obj1, undefined)); |
| 61 assertFalse(natives.SameValue(obj1, NaN)); |
58 | 62 |
59 assertFalse(sameValue(obj1, true)); | 63 assertFalse(natives.SameValue(undefined, true)); |
60 assertFalse(sameValue(obj1, "foo")); | 64 assertFalse(natives.SameValue(undefined, "foo")); |
61 assertFalse(sameValue(obj1, 1)); | 65 assertFalse(natives.SameValue(undefined, 1)); |
62 assertFalse(sameValue(obj1, undefined)); | 66 assertFalse(natives.SameValue(undefined, obj1)); |
63 assertFalse(sameValue(obj1, NaN)); | 67 assertFalse(natives.SameValue(undefined, NaN)); |
64 | 68 |
65 assertFalse(sameValue(undefined, true)); | 69 assertFalse(natives.SameValue(NaN, true)); |
66 assertFalse(sameValue(undefined, "foo")); | 70 assertFalse(natives.SameValue(NaN, "foo")); |
67 assertFalse(sameValue(undefined, 1)); | 71 assertFalse(natives.SameValue(NaN, 1)); |
68 assertFalse(sameValue(undefined, obj1)); | 72 assertFalse(natives.SameValue(NaN, obj1)); |
69 assertFalse(sameValue(undefined, NaN)); | 73 assertFalse(natives.SameValue(NaN, undefined)); |
70 | 74 |
71 assertFalse(sameValue(NaN, true)); | 75 assertFalse(natives.SameValue("foo", true)); |
72 assertFalse(sameValue(NaN, "foo")); | 76 assertFalse(natives.SameValue("foo", 1)); |
73 assertFalse(sameValue(NaN, 1)); | 77 assertFalse(natives.SameValue("foo", obj1)); |
74 assertFalse(sameValue(NaN, obj1)); | 78 assertFalse(natives.SameValue("foo", undefined)); |
75 assertFalse(sameValue(NaN, undefined)); | 79 assertFalse(natives.SameValue("foo", NaN)); |
76 | 80 |
77 assertFalse(sameValue("foo", true)); | 81 assertFalse(natives.SameValue(true, 1)); |
78 assertFalse(sameValue("foo", 1)); | 82 assertFalse(natives.SameValue(true, obj1)); |
79 assertFalse(sameValue("foo", obj1)); | 83 assertFalse(natives.SameValue(true, undefined)); |
80 assertFalse(sameValue("foo", undefined)); | 84 assertFalse(natives.SameValue(true, NaN)); |
81 assertFalse(sameValue("foo", NaN)); | 85 assertFalse(natives.SameValue(true, "foo")); |
82 | 86 |
83 assertFalse(sameValue(true, 1)); | 87 assertFalse(natives.SameValue(1, true)); |
84 assertFalse(sameValue(true, obj1)); | 88 assertFalse(natives.SameValue(1, obj1)); |
85 assertFalse(sameValue(true, undefined)); | 89 assertFalse(natives.SameValue(1, undefined)); |
86 assertFalse(sameValue(true, NaN)); | 90 assertFalse(natives.SameValue(1, NaN)); |
87 assertFalse(sameValue(true, "foo")); | 91 assertFalse(natives.SameValue(1, "foo")); |
88 | |
89 assertFalse(sameValue(1, true)); | |
90 assertFalse(sameValue(1, obj1)); | |
91 assertFalse(sameValue(1, undefined)); | |
92 assertFalse(sameValue(1, NaN)); | |
93 assertFalse(sameValue(1, "foo")); | |
94 | 92 |
95 // Special string cases. | 93 // Special string cases. |
96 assertFalse(sameValue("1", 1)); | 94 assertFalse(natives.SameValue("1", 1)); |
97 assertFalse(sameValue("true", true)); | 95 assertFalse(natives.SameValue("true", true)); |
98 assertFalse(sameValue("false", false)); | 96 assertFalse(natives.SameValue("false", false)); |
99 assertFalse(sameValue("undefined", undefined)); | 97 assertFalse(natives.SameValue("undefined", undefined)); |
100 assertFalse(sameValue("NaN", NaN)); | 98 assertFalse(natives.SameValue("NaN", NaN)); |
101 | 99 |
102 // -0 and +0 are should be different | 100 // -0 and +0 are should be different |
103 assertFalse(sameValue(+0, -0)); | 101 assertFalse(natives.SameValue(+0, -0)); |
104 assertFalse(sameValue(-0, +0)); | 102 assertFalse(natives.SameValue(-0, +0)); |
OLD | NEW |