symbol.js (1194B)
1 // Copyright (C) 2014 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 es6id: 12.2.5 5 description: > 6 computed property class method names can be a symbol 7 includes: [compareArray.js] 8 features: [Symbol] 9 ---*/ 10 11 function ID(x) { 12 return x; 13 } 14 15 var sym1 = Symbol(); 16 var sym2 = Symbol(); 17 class C { 18 a() { return 'A'; } 19 [sym1]() { return 'B'; } 20 c() { return 'C'; } 21 [ID(sym2)]() { return 'D'; } 22 } 23 assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'; }`"); 24 assert.sameValue(new C()[sym1](), 'B', "`new C()[sym1]()` returns `'B'`. Defined as `[sym1]() { return 'B'; }`"); 25 assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`"); 26 assert.sameValue(new C()[sym2](), 'D', "`new C()[sym2]()` returns `'D'`. Defined as `[ID(sym2)]() { return 'D'; }`"); 27 assert.sameValue(Object.keys(C.prototype).length, 0, "No enum keys from C.prototype"); 28 assert.compareArray( 29 Object.getOwnPropertyNames(C.prototype), 30 ['constructor', 'a', 'c'] 31 ); 32 assert.compareArray( 33 Object.getOwnPropertySymbols(C.prototype), 34 [sym1, sym2] 35 ); 36 37 reportCompare(0, 0);