Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/computed-property-names/class/accessor/setter-duplicates.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 In a class, duplicate computed property setter names produce only a single property of
7 that name, whose value is the value of the last property of that name.
8 ---*/
9 var calls = 0;
10 class C {
11 set ['a'](_) {
12 calls++;
13 }
14 }
15 new C().a = 'A';
16 assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C().a = 'A';`");
17
18 calls = 0;
19 class C2 {
20 set b(_) {
21 $ERROR("The first `b` setter definition in `C2` is unreachable");
22 }
23 set ['b'](_) {
24 calls++;
25 }
26 }
27 new C2().b = 'B';
28 assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C2().b = 'B';`");
29
30 calls = 0;
31 class C3 {
32 set c(_) {
33 $ERROR("The first `c` setter definition in `C3` is unreachable");
34 }
35 set ['c'](_) {
36 $ERROR("The second `c` setter definition in `C3` is unreachable");
37 }
38 set ['c'](_) {
39 calls++
40 }
41 }
42 new C3().c = 'C';
43 assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C3().c = 'C';`");
44
45 calls = 0;
46 class C4 {
47 set ['d'](_) {
48 $ERROR("The first `d` setter definition in `C4` is unreachable");
49 }
50 set d(_) {
51 calls++
52 }
53 }
54 new C4().d = 'D';
55 assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C4().d = 'D';`");