setter-duplicates.js (1292B)
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 an object, duplicate computed property getter 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 var A = { 11 set ['a'](_) { 12 calls++; 13 } 14 }; 15 A.a = 'A'; 16 assert.sameValue(calls, 1, "The value of `calls` is `1`"); 17 18 calls = 0; 19 var B = { 20 set b(_) { 21 throw new Test262Error("The `b` setter definition in `B` is unreachable"); 22 }, 23 set ['b'](_) { 24 calls++; 25 } 26 }; 27 B.b = 'B'; 28 assert.sameValue(calls, 1, "The value of `calls` is `1`"); 29 30 calls = 0; 31 var C = { 32 set c(_) { 33 throw new Test262Error("The `c` setter definition in `C` is unreachable"); 34 }, 35 set ['c'](_) { 36 throw new Test262Error("The first `['c']` setter definition in `C` is unreachable"); 37 }, 38 set ['c'](_) { 39 calls++ 40 } 41 }; 42 C.c = 'C'; 43 assert.sameValue(calls, 1, "The value of `calls` is `1`"); 44 45 calls = 0; 46 var D = { 47 set ['d'](_) { 48 throw new Test262Error("The `['d']` setter definition in `D` is unreachable"); 49 }, 50 set d(_) { 51 calls++ 52 } 53 }; 54 D.d = 'D'; 55 assert.sameValue(calls, 1, "The value of `calls` is `1`"); 56 57 reportCompare(0, 0);