Debian Codegraph @

js/src/tests/test262/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 key1ToString = [];
11 var key2ToString = [];
12 var key1 = {
13 toString: function() {
14 key1ToString.push(counter);
15 counter += 1;
16 return 'b';
17 }
18 };
19 var key2 = {
20 toString: function() {
21 key2ToString.push(counter);
22 counter += 1;
23 return 'd';
24 }
25 };
26 class C {
27 a() { return 'A'; }
28 [key1]() { return 'B'; }
29 c() { return 'C'; }
30 [key2]() { return 'D'; }
31 }
32
33 assert.compareArray(key1ToString, [0], "order set for key1");
34 assert.compareArray(key2ToString, [1], "order set for key2");
35
36 assert.sameValue(counter, 2, "The value of `counter` is `2`");
37 assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'; }`");
38 assert.sameValue(new C().b(), 'B', "`new C().b()` returns `'B'`. Defined as `[key1]() { return 'B'; }`");
39 assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`");
40 assert.sameValue(new C().d(), 'D', "`new C().d()` returns `'D'`. Defined as `[key2]() { return 'D'; }`");
41 assert.sameValue(Object.keys(C.prototype).length, 0, "No enum keys from C.prototype");
42 assert(
43 compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd']),
44 "`compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd'])` returns `true`"
45 );
46
47 reportCompare(0, 0);