Debian Codegraph @

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