Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/computed-property-names/basics/symbol.js

raw
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(
28 compareArray(Object.keys(object), ['a', 'c']),
29 "`compareArray(Object.keys(object), ['a', 'c'])` returns `true`"
30 );
31 assert(
32 compareArray(Object.getOwnPropertySymbols(object), [sym1, sym2]),
33 "`compareArray(Object.getOwnPropertySymbols(object), [sym1, sym2])` returns `true`"
34 );