OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 function TestToNumber() { | 124 function TestToNumber() { |
125 for (var i in symbols) { | 125 for (var i in symbols) { |
126 assertSame(NaN, Number(symbols[i]).valueOf()) | 126 assertSame(NaN, Number(symbols[i]).valueOf()) |
127 assertSame(NaN, symbols[i] + 0) | 127 assertSame(NaN, symbols[i] + 0) |
128 } | 128 } |
129 } | 129 } |
130 TestToNumber() | 130 TestToNumber() |
131 | 131 |
132 | 132 |
133 function TestEquality() { | 133 function TestEquality() { |
134 // Every symbol should equal itself. | 134 // Every symbol should equal itself, and non-strictly equal its wrapper. |
135 for (var i in symbols) { | 135 for (var i in symbols) { |
136 assertSame(symbols[i], symbols[i]) | 136 assertSame(symbols[i], symbols[i]) |
137 assertEquals(symbols[i], symbols[i]) | 137 assertEquals(symbols[i], symbols[i]) |
138 assertTrue(Object.is(symbols[i], symbols[i])) | 138 assertTrue(Object.is(symbols[i], symbols[i])) |
139 assertTrue(symbols[i] === symbols[i]) | 139 assertTrue(symbols[i] === symbols[i]) |
140 assertTrue(symbols[i] == symbols[i]) | 140 assertTrue(symbols[i] == symbols[i]) |
| 141 assertFalse(symbols[i] === new Symbol(symbols[i])) |
| 142 assertFalse(new Symbol(symbols[i]) === symbols[i]) |
| 143 assertTrue(symbols[i] == new Symbol(symbols[i])) |
| 144 assertTrue(new Symbol(symbols[i]) == symbols[i]) |
141 } | 145 } |
142 | 146 |
143 // All symbols should be distinct. | 147 // All symbols should be distinct. |
144 for (var i = 0; i < symbols.length; ++i) { | 148 for (var i = 0; i < symbols.length; ++i) { |
145 for (var j = i + 1; j < symbols.length; ++j) { | 149 for (var j = i + 1; j < symbols.length; ++j) { |
146 assertFalse(Object.is(symbols[i], symbols[j])) | 150 assertFalse(Object.is(symbols[i], symbols[j])) |
147 assertFalse(symbols[i] === symbols[j]) | 151 assertFalse(symbols[i] === symbols[j]) |
148 assertFalse(symbols[i] == symbols[j]) | 152 assertFalse(symbols[i] == symbols[j]) |
149 } | 153 } |
150 } | 154 } |
| 155 |
| 156 // Symbols should not be equal to any other value (and the test terminates). |
| 157 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] |
| 158 for (var i in symbols) { |
| 159 for (var j in values) { |
| 160 assertFalse(symbols[i] === values[j]) |
| 161 assertFalse(values[j] === symbols[i]) |
| 162 assertFalse(symbols[i] == values[j]) |
| 163 assertFalse(values[j] == symbols[i]) |
| 164 } |
| 165 } |
151 } | 166 } |
152 TestEquality() | 167 TestEquality() |
153 | 168 |
154 | 169 |
155 function TestGet() { | 170 function TestGet() { |
156 for (var i in symbols) { | 171 for (var i in symbols) { |
157 assertThrows(function() { symbols[i].toString() }, TypeError) | 172 assertThrows(function() { symbols[i].toString() }, TypeError) |
158 assertEquals(symbols[i], symbols[i].valueOf()) | 173 assertEquals(symbols[i], symbols[i].valueOf()) |
159 assertEquals(undefined, symbols[i].a) | 174 assertEquals(undefined, symbols[i].a) |
160 assertEquals(undefined, symbols[i]["a" + "b"]) | 175 assertEquals(undefined, symbols[i]["a" + "b"]) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 var obj = objs[i] | 306 var obj = objs[i] |
292 TestKeySet(obj) | 307 TestKeySet(obj) |
293 TestKeyDefine(obj) | 308 TestKeyDefine(obj) |
294 TestKeyGet(obj) | 309 TestKeyGet(obj) |
295 TestKeyHas(obj) | 310 TestKeyHas(obj) |
296 TestKeyEnum(obj) | 311 TestKeyEnum(obj) |
297 TestKeyNames(obj) | 312 TestKeyNames(obj) |
298 TestKeyDescriptor(obj) | 313 TestKeyDescriptor(obj) |
299 TestKeyDelete(obj) | 314 TestKeyDelete(obj) |
300 } | 315 } |
OLD | NEW |