| 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 19 matching lines...) Expand all Loading... |
| 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 } | 35 function IndirectSymbol() { return new Symbol } |
| 36 function indirect() { return new IndirectSymbol() } | 36 function indirect() { return new IndirectSymbol() } |
| 37 for (var i = 0; i < 2; ++i) { | 37 for (var i = 0; i < 2; ++i) { |
| 38 for (var j = 0; j < 5; ++j) { | 38 for (var j = 0; j < 5; ++j) { |
| 39 symbols.push(Symbol()) | 39 symbols.push(Symbol()) |
| 40 symbols.push(Symbol(undefined)) |
| 41 symbols.push(Symbol("66")) |
| 42 symbols.push(Symbol(66)) |
| 40 symbols.push(Symbol(Symbol())) | 43 symbols.push(Symbol(Symbol())) |
| 41 symbols.push((new Symbol).valueOf()) | 44 symbols.push((new Symbol).valueOf()) |
| 42 symbols.push((new Symbol()).valueOf()) | 45 symbols.push((new Symbol()).valueOf()) |
| 43 symbols.push((new Symbol(Symbol())).valueOf()) | 46 symbols.push((new Symbol(Symbol())).valueOf()) |
| 44 symbols.push(Object(Symbol()).valueOf()) | 47 symbols.push(Object(Symbol()).valueOf()) |
| 45 symbols.push((indirect()).valueOf()) | 48 symbols.push((indirect()).valueOf()) |
| 46 } | 49 } |
| 47 %OptimizeFunctionOnNextCall(indirect) | 50 %OptimizeFunctionOnNextCall(indirect) |
| 48 indirect() // Call once before GC throws away type feedback. | 51 indirect() // Call once before GC throws away type feedback. |
| 49 gc() // Promote existing symbols and then allocate some more. | 52 gc() // Promote existing symbols and then allocate some more. |
| 50 } | 53 } |
| 51 } | 54 } |
| 52 TestNew() | 55 TestNew() |
| 53 | 56 |
| 54 | 57 |
| 55 function TestType() { | 58 function TestType() { |
| 56 for (var i in symbols) { | 59 for (var i in symbols) { |
| 57 assertEquals("symbol", typeof symbols[i]) | 60 assertEquals("symbol", typeof symbols[i]) |
| 58 assertTrue(typeof symbols[i] === "symbol") | 61 assertTrue(typeof symbols[i] === "symbol") |
| 59 assertEquals(null, %_ClassOf(symbols[i])) | 62 assertEquals(null, %_ClassOf(symbols[i])) |
| 60 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i]))) | 63 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i]))) |
| 61 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) | 64 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) |
| 62 } | 65 } |
| 63 } | 66 } |
| 64 TestType() | 67 TestType() |
| 65 | 68 |
| 66 | 69 |
| 70 function TestName() { |
| 71 for (var i in symbols) { |
| 72 var name = symbols[i].name |
| 73 assertTrue(name === undefined || name === "66") |
| 74 } |
| 75 } |
| 76 TestName() |
| 77 |
| 78 |
| 67 function TestToString() { | 79 function TestToString() { |
| 68 for (var i in symbols) { | 80 for (var i in symbols) { |
| 69 assertThrows(function() { String(symbols[i]) }, TypeError) | 81 assertThrows(function() { String(symbols[i]) }, TypeError) |
| 70 assertThrows(function() { symbols[i] + "" }, TypeError) | 82 assertThrows(function() { symbols[i] + "" }, TypeError) |
| 71 assertThrows(function() { symbols[i].toString() }, TypeError) | 83 assertThrows(function() { symbols[i].toString() }, TypeError) |
| 72 assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError) | 84 assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError) |
| 73 assertThrows(function() { Object(symbols[i]).toString() }, TypeError) | 85 assertThrows(function() { Object(symbols[i]).toString() }, TypeError) |
| 74 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i])) | 86 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i])) |
| 75 } | 87 } |
| 76 } | 88 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 var obj = objs[i] | 286 var obj = objs[i] |
| 275 TestKeySet(obj) | 287 TestKeySet(obj) |
| 276 TestKeyDefine(obj) | 288 TestKeyDefine(obj) |
| 277 TestKeyGet(obj) | 289 TestKeyGet(obj) |
| 278 TestKeyHas(obj) | 290 TestKeyHas(obj) |
| 279 TestKeyEnum(obj) | 291 TestKeyEnum(obj) |
| 280 TestKeyNames(obj) | 292 TestKeyNames(obj) |
| 281 TestKeyDescriptor(obj) | 293 TestKeyDescriptor(obj) |
| 282 TestKeyDelete(obj) | 294 TestKeyDelete(obj) |
| 283 } | 295 } |
| OLD | NEW |