| 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --harmony-symbols --harmony-collections | 28 // Flags: --harmony-symbols --harmony-collections |
| 29 // Flags: --expose-gc --allow-natives-syntax | 29 // Flags: --expose-gc --allow-natives-syntax |
| 30 | 30 |
| 31 var symbols = [] | 31 var symbols = [] |
| 32 | 32 |
| 33 // Test different forms of constructor calls, all equivalent. | 33 // Test different forms of constructor calls, all equivalent. |
| 34 function TestNew() { | 34 function TestNew() { |
| 35 function IndirectSymbol() { return new Symbol } | |
| 36 function indirect() { return new IndirectSymbol() } | |
| 37 for (var i = 0; i < 2; ++i) { | 35 for (var i = 0; i < 2; ++i) { |
| 38 for (var j = 0; j < 5; ++j) { | 36 for (var j = 0; j < 5; ++j) { |
| 39 symbols.push(Symbol()) | 37 symbols.push(%CreatePrivateSymbol("66")) |
| 40 symbols.push(Symbol(undefined)) | 38 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf()) |
| 41 symbols.push(Symbol("66")) | |
| 42 symbols.push(Symbol(66)) | |
| 43 symbols.push(Symbol(Symbol())) | |
| 44 symbols.push((new Symbol).valueOf()) | |
| 45 symbols.push((new Symbol()).valueOf()) | |
| 46 symbols.push((new Symbol(Symbol())).valueOf()) | |
| 47 symbols.push(Object(Symbol()).valueOf()) | |
| 48 symbols.push((indirect()).valueOf()) | |
| 49 } | 39 } |
| 50 %OptimizeFunctionOnNextCall(indirect) | 40 gc() // Promote existing symbols and then allocate some more. |
| 51 indirect() // Call once before GC throws away type feedback. | |
| 52 gc() // Promote existing symbols and then allocate some more. | |
| 53 } | 41 } |
| 54 } | 42 } |
| 55 TestNew() | 43 TestNew() |
| 56 | 44 |
| 57 | 45 |
| 58 function TestType() { | 46 function TestType() { |
| 59 for (var i in symbols) { | 47 for (var i in symbols) { |
| 60 assertEquals("symbol", typeof symbols[i]) | 48 assertEquals("symbol", typeof symbols[i]) |
| 61 assertTrue(typeof symbols[i] === "symbol") | 49 assertTrue(typeof symbols[i] === "symbol") |
| 50 assertTrue(%SymbolIsPrivate(symbols[i])) |
| 62 assertEquals(null, %_ClassOf(symbols[i])) | 51 assertEquals(null, %_ClassOf(symbols[i])) |
| 63 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i]))) | 52 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i]))) |
| 64 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) | 53 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) |
| 65 } | 54 } |
| 66 } | 55 } |
| 67 TestType() | 56 TestType() |
| 68 | 57 |
| 69 | 58 |
| 70 function TestPrototype() { | 59 function TestPrototype() { |
| 71 assertSame(Object.prototype, Symbol.prototype.__proto__) | |
| 72 assertSame(Symbol.prototype, Symbol().__proto__) | |
| 73 assertSame(Symbol.prototype, Symbol(Symbol()).__proto__) | |
| 74 assertSame(Symbol.prototype, (new Symbol).__proto__) | |
| 75 assertSame(Symbol.prototype, (new Symbol()).__proto__) | |
| 76 assertSame(Symbol.prototype, (new Symbol(Symbol())).__proto__) | |
| 77 assertSame(Symbol.prototype, Object(Symbol()).__proto__) | |
| 78 for (var i in symbols) { | 60 for (var i in symbols) { |
| 79 assertSame(Symbol.prototype, symbols[i].__proto__) | 61 assertSame(Symbol.prototype, symbols[i].__proto__) |
| 80 } | 62 } |
| 81 } | 63 } |
| 82 TestPrototype() | 64 TestPrototype() |
| 83 | 65 |
| 84 | 66 |
| 85 function TestConstructor() { | 67 function TestConstructor() { |
| 86 assertFalse(Object === Symbol.prototype.constructor) | |
| 87 assertFalse(Symbol === Object.prototype.constructor) | |
| 88 assertSame(Symbol, Symbol.prototype.constructor) | |
| 89 assertSame(Symbol, Symbol().__proto__.constructor) | |
| 90 assertSame(Symbol, Symbol(Symbol()).__proto__.constructor) | |
| 91 assertSame(Symbol, (new Symbol).__proto__.constructor) | |
| 92 assertSame(Symbol, (new Symbol()).__proto__.constructor) | |
| 93 assertSame(Symbol, (new Symbol(Symbol())).__proto__.constructor) | |
| 94 assertSame(Symbol, Object(Symbol()).__proto__.constructor) | |
| 95 for (var i in symbols) { | 68 for (var i in symbols) { |
| 96 assertSame(Symbol, symbols[i].__proto__.constructor) | 69 assertSame(Symbol, symbols[i].__proto__.constructor) |
| 97 } | 70 } |
| 98 } | 71 } |
| 99 TestConstructor() | 72 TestConstructor() |
| 100 | 73 |
| 101 | 74 |
| 102 function TestName() { | 75 function TestName() { |
| 103 for (var i in symbols) { | 76 for (var i in symbols) { |
| 104 var name = symbols[i].name | 77 var name = symbols[i].name |
| 105 assertTrue(name === undefined || name === "66") | 78 assertTrue(name === "66") |
| 106 } | 79 } |
| 107 } | 80 } |
| 108 TestName() | 81 TestName() |
| 109 | 82 |
| 110 | 83 |
| 111 function TestToString() { | 84 function TestToString() { |
| 112 for (var i in symbols) { | 85 for (var i in symbols) { |
| 113 assertThrows(function() { String(symbols[i]) }, TypeError) | 86 assertThrows(function() { String(symbols[i]) }, TypeError) |
| 114 assertThrows(function() { symbols[i] + "" }, TypeError) | 87 assertThrows(function() { symbols[i] + "" }, TypeError) |
| 115 assertThrows(function() { symbols[i].toString() }, TypeError) | 88 assertThrows(function() { symbols[i].toString() }, TypeError) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // but not between scavenges. This must also apply for symbol keys. | 315 // but not between scavenges. This must also apply for symbol keys. |
| 343 var key = Symbol("key"); | 316 var key = Symbol("key"); |
| 344 var a = {}; | 317 var a = {}; |
| 345 a[key] = "abc"; | 318 a[key] = "abc"; |
| 346 | 319 |
| 347 for (var i = 0; i < 1000000; i++) { | 320 for (var i = 0; i < 1000000; i++) { |
| 348 a[key] += "a"; // Allocations cause a scavenge. | 321 a[key] += "a"; // Allocations cause a scavenge. |
| 349 } | 322 } |
| 350 } | 323 } |
| 351 TestCachedKeyAfterScavenge(); | 324 TestCachedKeyAfterScavenge(); |
| OLD | NEW |