Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/computed-property-names/to-name-side-effects/numbers-class.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 to name, accessor side effects numbers 2
7 includes: [compareArray.js]
8 ---*/
9 var counter = 0;
10 var key1 = {
11 valueOf: function() {
12 assert.sameValue(counter++, 0, "The result of `counter++` is `0`");
13 return 1;
14 },
15 toString: null
16 };
17 var key2 = {
18 valueOf: function() {
19 assert.sameValue(counter++, 1, "The result of `counter++` is `1`");
20 return 2;
21 },
22 toString: null
23 };
24
25 class C {
26 a() { return 'A'; }
27 [key1]() { return 'B'; }
28 c() { return 'C'; }
29 [key2]() { return 'D'; }
30 }
31 assert.sameValue(counter, 2, "The value of `counter` is `2`");
32 assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'; }`");
33 assert.sameValue(new C()[1](), 'B', "`new C()[1]()` returns `'B'`. Defined as `[key1]() { return 'B'; }`");
34 assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`");
35 assert.sameValue(new C()[2](), 'D', "`new C()[2]()` returns `'D'`. Defined as `[key2]() { return 'D'; }`");
36 assert(
37 compareArray(Object.keys(C.prototype), []),
38 "`compareArray(Object.keys(C.prototype), [])` returns `true`"
39 );
40 assert(
41 compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c']),
42 "`compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c'])` returns `true`"
43 );