Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/computed-property-names/object/method/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 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 var object = {
18 a() { return 'A'; },
19 [sym1]() { return 'B'; },
20 c() { return 'C'; },
21 [ID(sym2)]() { return 'D'; },
22 };
23 assert.sameValue(object.a(), 'A', "`object.a()` returns `'A'`. Defined as `a() { return 'A'; }`");
24 assert.sameValue(object[sym1](), 'B', "`object[sym1]()` returns `'B'`. Defined as `[sym1]() { return 'B'; }`");
25 assert.sameValue(object.c(), 'C', "`object.c()` returns `'C'`. Defined as `c() { return 'C'; }`");
26 assert.sameValue(object[sym2](), 'D', "`object[sym2]()` returns `'D'`. Defined as `[ID(sym2)]() { return '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 );