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 TestRegistry() { | 413 function TestGetOwnPropertySymbolsWithPrivateSymbols() { |
414 assertFalse(Symbol.for("@@create") === Symbol.create) | 414 var privateSymbol = %CreatePrivateSymbol("private") |
415 assertFalse(Symbol.for("@@iterator") === Symbol.iterator) | 415 var publicSymbol = Symbol() |
416 assertTrue(Symbol.keyFor(Symbol.create) === undefined) | 416 var publicSymbol2 = Symbol() |
417 assertTrue(Symbol.keyFor(Symbol.iterator) === undefined) | 417 var obj = {} |
418 | 418 obj[publicSymbol] = 1 |
419 var symbol1 = Symbol.for("x1") | 419 obj[privateSymbol] = 2 |
420 var symbol2 = Symbol.for("x2") | 420 obj[publicSymbol2] = 3 |
421 assertFalse(symbol1 === symbol2) | 421 var syms = Object.getOwnPropertySymbols(obj) |
422 | 422 assertEquals(syms, [publicSymbol, publicSymbol2]) |
423 assertSame(symbol1, Symbol.for("x1")) | |
424 assertSame(symbol2, Symbol.for("x2")) | |
425 assertSame("x1", Symbol.keyFor(symbol1)) | |
426 assertSame("x2", Symbol.keyFor(symbol2)) | |
427 | |
428 assertSame(Symbol.for("1"), Symbol.for(1)) | |
429 assertThrows(function() { Symbol.keyFor("bla") }, TypeError) | |
430 assertThrows(function() { Symbol.keyFor({}) }, TypeError) | |
431 | |
432 var realm = Realm.create() | |
433 assertFalse(Symbol === Realm.eval(realm, "Symbol")) | |
434 assertFalse(Symbol.for === Realm.eval(realm, "Symbol.for")) | |
435 assertFalse(Symbol.keyFor === Realm.eval(realm, "Symbol.keyFor")) | |
436 assertSame(Symbol.create, Realm.eval(realm, "Symbol.create")) | |
437 assertSame(Symbol.iterator, Realm.eval(realm, "Symbol.iterator")) | |
438 | |
439 assertSame(symbol1, Realm.eval(realm, "Symbol.for")("x1")) | |
440 assertSame(symbol1, Realm.eval(realm, "Symbol.for('x1')")) | |
441 assertSame("x1", Realm.eval(realm, "Symbol.keyFor")(symbol1)) | |
442 Realm.shared = symbol1 | |
443 assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)")) | |
444 | |
445 var symbol3 = Realm.eval(realm, "Symbol.for('x3')") | |
446 assertFalse(symbol1 === symbol3) | |
447 assertFalse(symbol2 === symbol3) | |
448 assertSame(symbol3, Symbol.for("x3")) | |
449 assertSame("x3", Symbol.keyFor(symbol3)) | |
450 } | 423 } |
451 TestRegistry() | 424 TestGetOwnPropertySymbolsWithPrivateSymbols() |
OLD | NEW |