| 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 var objectOwnSymbols = Object.getOwnPropertySymbols(object) | 403 var objectOwnSymbols = Object.getOwnPropertySymbols(object) |
| 404 assertEquals(objectOwnSymbols.length, syms.length / 2) | 404 assertEquals(objectOwnSymbols.length, syms.length / 2) |
| 405 | 405 |
| 406 for (var i = 0; i < objectOwnSymbols.length; i++) { | 406 for (var i = 0; i < objectOwnSymbols.length; i++) { |
| 407 assertEquals(objectOwnSymbols[i], syms[i * 2]) | 407 assertEquals(objectOwnSymbols[i], syms[i * 2]) |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 TestGetOwnPropertySymbolsWithProto() | 410 TestGetOwnPropertySymbolsWithProto() |
| 411 | 411 |
| 412 | 412 |
| 413 function TestWellKnown() { |
| 414 var symbols = [ |
| 415 "create", "hasInstance", "isConcatSpreadable", "isRegExp", |
| 416 "iterator", "toStringTag", "unscopables" |
| 417 ] |
| 418 |
| 419 for (var i in symbols) { |
| 420 var name = symbols[i] |
| 421 var desc = Object.getOwnPropertyDescriptor(Symbol, name) |
| 422 assertSame("symbol", typeof desc.value) |
| 423 assertSame("Symbol(Symbol." + name + ")", desc.value.toString()) |
| 424 assertFalse(desc.writable) |
| 425 assertFalse(desc.configurable) |
| 426 assertFalse(desc.enumerable) |
| 427 |
| 428 assertFalse(Symbol.for("Symbol." + name) === desc.value) |
| 429 assertTrue(Symbol.keyFor(desc.value) === undefined) |
| 430 } |
| 431 } |
| 432 TestWellKnown() |
| 433 |
| 434 |
| 413 function TestRegistry() { | 435 function TestRegistry() { |
| 414 assertFalse(Symbol.for("@@create") === Symbol.create) | |
| 415 assertFalse(Symbol.for("@@iterator") === Symbol.iterator) | |
| 416 assertTrue(Symbol.keyFor(Symbol.create) === undefined) | |
| 417 assertTrue(Symbol.keyFor(Symbol.iterator) === undefined) | |
| 418 | |
| 419 var symbol1 = Symbol.for("x1") | 436 var symbol1 = Symbol.for("x1") |
| 420 var symbol2 = Symbol.for("x2") | 437 var symbol2 = Symbol.for("x2") |
| 421 assertFalse(symbol1 === symbol2) | 438 assertFalse(symbol1 === symbol2) |
| 422 | 439 |
| 423 assertSame(symbol1, Symbol.for("x1")) | 440 assertSame(symbol1, Symbol.for("x1")) |
| 424 assertSame(symbol2, Symbol.for("x2")) | 441 assertSame(symbol2, Symbol.for("x2")) |
| 425 assertSame("x1", Symbol.keyFor(symbol1)) | 442 assertSame("x1", Symbol.keyFor(symbol1)) |
| 426 assertSame("x2", Symbol.keyFor(symbol2)) | 443 assertSame("x2", Symbol.keyFor(symbol2)) |
| 427 | 444 |
| 428 assertSame(Symbol.for("1"), Symbol.for(1)) | 445 assertSame(Symbol.for("1"), Symbol.for(1)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 442 Realm.shared = symbol1 | 459 Realm.shared = symbol1 |
| 443 assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)")) | 460 assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)")) |
| 444 | 461 |
| 445 var symbol3 = Realm.eval(realm, "Symbol.for('x3')") | 462 var symbol3 = Realm.eval(realm, "Symbol.for('x3')") |
| 446 assertFalse(symbol1 === symbol3) | 463 assertFalse(symbol1 === symbol3) |
| 447 assertFalse(symbol2 === symbol3) | 464 assertFalse(symbol2 === symbol3) |
| 448 assertSame(symbol3, Symbol.for("x3")) | 465 assertSame(symbol3, Symbol.for("x3")) |
| 449 assertSame("x3", Symbol.keyFor(symbol3)) | 466 assertSame("x3", Symbol.keyFor(symbol3)) |
| 450 } | 467 } |
| 451 TestRegistry() | 468 TestRegistry() |
| OLD | NEW |