symbol.js (1031B)
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 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 var object = { 18 a: 'A', 19 [sym1]: 'B', 20 c: 'C', 21 [ID(sym2)]: 'D', 22 }; 23 assert.sameValue(object.a, 'A', "The value of `object.a` is `'A'`. Defined in `object` as `a: 'A'`"); 24 assert.sameValue(object[sym1], 'B', "The value of `object[sym1]` is `'B'`. Defined in `object` as `[sym1]: 'B'`"); 25 assert.sameValue(object.c, 'C', "The value of `object.c` is `'C'`. Defined in `object` as `c: 'C'`"); 26 assert.sameValue(object[sym2], 'D', "The value of `object[sym2]` is `'D'`. Defined in `object` as `[ID(sym2)]: 'D'`"); 27 assert.compareArray( 28 Object.getOwnPropertyNames(object), 29 ['a', 'c'] 30 ); 31 assert.compareArray( 32 Object.getOwnPropertySymbols(object), 33 [sym1, sym2] 34 ); 35 36 reportCompare(0, 0);