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 TestGetOwnPropertySymbolsWithPrivateSymbols() { | 413 function TestRegistry() { |
414 var privateSymbol = %CreatePrivateSymbol("private") | 414 assertFalse(Symbol.for("@@create") === Symbol.create) |
sof
2014/03/19 09:06:47
Worth adding an initial test for keyFor() over wel
Michael Starzinger
2014/03/19 10:15:25
+1
rossberg
2014/03/20 10:40:13
Done. (But note that it just returns undefined.)
| |
415 var publicSymbol = Symbol() | 415 assertFalse(Symbol.for("@@iterator") === Symbol.iterator) |
416 var publicSymbol2 = Symbol() | 416 |
417 var obj = {} | 417 var symbol1 = Symbol.for("x1") |
418 obj[publicSymbol] = 1 | 418 var symbol2 = Symbol.for("x2") |
419 obj[privateSymbol] = 2 | 419 assertFalse(symbol1 === symbol2) |
420 obj[publicSymbol2] = 3 | 420 |
421 var syms = Object.getOwnPropertySymbols(obj) | 421 assertSame(symbol1, Symbol.for("x1")) |
422 assertEquals(syms, [publicSymbol, publicSymbol2]) | 422 assertSame(symbol2, Symbol.for("x2")) |
423 assertSame("x1", Symbol.keyFor(symbol1)) | |
424 assertSame("x2", Symbol.keyFor(symbol2)) | |
425 | |
426 assertSame(Symbol.for("1"), Symbol.for(1)) | |
427 assertThrows(function() { Symbol.keyFor("bla") }, TypeError) | |
428 | |
429 var realm = Realm.create() | |
430 assertFalse(Symbol === Realm.eval(realm, "Symbol")) | |
431 assertFalse(Symbol.for === Realm.eval(realm, "Symbol.for")) | |
432 assertFalse(Symbol.keyFor === Realm.eval(realm, "Symbol.keyFor")) | |
433 assertSame(Symbol.create, Realm.eval(realm, "Symbol.create")) | |
434 assertSame(Symbol.iterator, Realm.eval(realm, "Symbol.iterator")) | |
435 | |
436 assertSame(symbol1, Realm.eval(realm, "Symbol.for")("x1")) | |
437 assertSame(symbol1, Realm.eval(realm, "Symbol.for('x1')")) | |
438 assertSame("x1", Realm.eval(realm, "Symbol.keyFor")(symbol1)) | |
439 Realm.shared = symbol1 | |
440 assertSame("x1", Realm.eval(realm, "Symbol.keyFor(Realm.shared)")) | |
441 | |
442 var symbol3 = Realm.eval(realm, "Symbol.for('x3')") | |
443 assertFalse(symbol1 === symbol3) | |
444 assertFalse(symbol2 === symbol3) | |
445 assertSame(symbol3, Symbol.for("x3")) | |
446 assertSame("x3", Symbol.keyFor(symbol3)) | |
423 } | 447 } |
424 TestGetOwnPropertySymbolsWithPrivateSymbols() | 448 TestRegistry() |
OLD | NEW |