| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 assertSame(Symbol, Object(Symbol()).__proto__.constructor) | 95 assertSame(Symbol, Object(Symbol()).__proto__.constructor) |
| 96 for (var i in symbols) { | 96 for (var i in symbols) { |
| 97 assertSame(Symbol, symbols[i].__proto__.constructor) | 97 assertSame(Symbol, symbols[i].__proto__.constructor) |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 TestConstructor() | 100 TestConstructor() |
| 101 | 101 |
| 102 | 102 |
| 103 function TestValueOf() { | 103 function TestValueOf() { |
| 104 for (var i in symbols) { | 104 for (var i in symbols) { |
| 105 assertTrue(symbols[i] === Object(symbols[i]).valueOf()) |
| 105 assertTrue(symbols[i] === symbols[i].valueOf()) | 106 assertTrue(symbols[i] === symbols[i].valueOf()) |
| 107 assertTrue(Symbol.prototype.valueOf.call(Object(symbols[i])) === symbols[i]) |
| 106 assertTrue(Symbol.prototype.valueOf.call(symbols[i]) === symbols[i]) | 108 assertTrue(Symbol.prototype.valueOf.call(symbols[i]) === symbols[i]) |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 TestValueOf() | 111 TestValueOf() |
| 110 | 112 |
| 111 | 113 |
| 112 function TestToString() { | 114 function TestToString() { |
| 113 for (var i in symbols) { | 115 for (var i in symbols) { |
| 114 assertThrows(function() { String(symbols[i]) }, TypeError) | 116 assertThrows(function() { String(symbols[i]) }, TypeError) |
| 115 assertThrows(function() { symbols[i] + "" }, TypeError) | 117 assertThrows(function() { symbols[i] + "" }, TypeError) |
| 116 assertTrue(isValidSymbolString(String(Object(symbols[i])))) | 118 assertThrows(function() { String(Object(symbols[i])) }, TypeError) |
| 117 assertTrue(isValidSymbolString(symbols[i].toString())) | 119 assertTrue(isValidSymbolString(symbols[i].toString())) |
| 118 assertTrue(isValidSymbolString(Object(symbols[i]).toString())) | 120 assertTrue(isValidSymbolString(Object(symbols[i]).toString())) |
| 119 assertTrue( | 121 assertTrue( |
| 120 isValidSymbolString(Symbol.prototype.toString.call(symbols[i]))) | 122 isValidSymbolString(Symbol.prototype.toString.call(symbols[i]))) |
| 121 assertEquals( | 123 assertEquals( |
| 122 "[object Symbol]", Object.prototype.toString.call(symbols[i])) | 124 "[object Symbol]", Object.prototype.toString.call(symbols[i])) |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 TestToString() | 127 TestToString() |
| 126 | 128 |
| 127 | 129 |
| 128 function TestToBoolean() { | 130 function TestToBoolean() { |
| 129 for (var i in symbols) { | 131 for (var i in symbols) { |
| 132 assertTrue(Boolean(Object(symbols[i]))) |
| 133 assertFalse(!Object(symbols[i])) |
| 130 assertTrue(Boolean(symbols[i]).valueOf()) | 134 assertTrue(Boolean(symbols[i]).valueOf()) |
| 131 assertFalse(!symbols[i]) | 135 assertFalse(!symbols[i]) |
| 132 assertTrue(!!symbols[i]) | 136 assertTrue(!!symbols[i]) |
| 133 assertTrue(symbols[i] && true) | 137 assertTrue(symbols[i] && true) |
| 134 assertFalse(!symbols[i] && false) | 138 assertFalse(!symbols[i] && false) |
| 135 assertTrue(!symbols[i] || true) | 139 assertTrue(!symbols[i] || true) |
| 136 assertEquals(1, symbols[i] ? 1 : 2) | 140 assertEquals(1, symbols[i] ? 1 : 2) |
| 137 assertEquals(2, !symbols[i] ? 1 : 2) | 141 assertEquals(2, !symbols[i] ? 1 : 2) |
| 138 if (!symbols[i]) assertUnreachable(); | 142 if (!symbols[i]) assertUnreachable(); |
| 139 if (symbols[i]) {} else assertUnreachable(); | 143 if (symbols[i]) {} else assertUnreachable(); |
| 140 } | 144 } |
| 141 } | 145 } |
| 142 TestToBoolean() | 146 TestToBoolean() |
| 143 | 147 |
| 144 | 148 |
| 145 function TestToNumber() { | 149 function TestToNumber() { |
| 146 for (var i in symbols) { | 150 for (var i in symbols) { |
| 151 assertThrows(function() { Number(Object(symbols[i])) }, TypeError) |
| 152 assertThrows(function() { +Object(symbols[i]) }, TypeError) |
| 147 assertSame(NaN, Number(symbols[i]).valueOf()) | 153 assertSame(NaN, Number(symbols[i]).valueOf()) |
| 148 assertSame(NaN, symbols[i] + 0) | 154 assertSame(NaN, symbols[i] + 0) |
| 149 } | 155 } |
| 150 } | 156 } |
| 151 TestToNumber() | 157 TestToNumber() |
| 152 | 158 |
| 153 | 159 |
| 154 function TestEquality() { | 160 function TestEquality() { |
| 155 // Every symbol should equal itself, and non-strictly equal its wrapper. | 161 // Every symbol should equal itself, and non-strictly equal its wrapper. |
| 156 for (var i in symbols) { | 162 for (var i in symbols) { |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 Realm.shared = symbol1 | 493 Realm.shared = symbol1 |
| 488 assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)")) | 494 assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)")) |
| 489 | 495 |
| 490 var symbol3 = Realm.eval(realm, "Symbol.for('x3')") | 496 var symbol3 = Realm.eval(realm, "Symbol.for('x3')") |
| 491 assertFalse(symbol1 === symbol3) | 497 assertFalse(symbol1 === symbol3) |
| 492 assertFalse(symbol2 === symbol3) | 498 assertFalse(symbol2 === symbol3) |
| 493 assertSame(symbol3, Symbol.for("x3")) | 499 assertSame(symbol3, Symbol.for("x3")) |
| 494 assertSame("x3", Symbol.keyFor(symbol3)) | 500 assertSame("x3", Symbol.keyFor(symbol3)) |
| 495 } | 501 } |
| 496 TestRegistry() | 502 TestRegistry() |
| OLD | NEW |