setters-prop-desc.js (1571B)
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 esid: sec-class-definitions 5 es6id: 14.5 6 description: Class methods - "set" accessors 7 includes: [propertyHelper.js] 8 ---*/ 9 10 function assertSetterDescriptor(object, name) { 11 var descr = Object.getOwnPropertyDescriptor(object, name); 12 verifyProperty(object, name, { 13 enumerable: false, 14 configurable: true, 15 }); 16 assert.sameValue(typeof descr.set, 'function', "`typeof descr.set` is `'function'`"); 17 assert.sameValue('prototype' in descr.set, false, "The result of `'prototype' in descr.set` is `false`"); 18 assert.sameValue(descr.get, undefined, "The value of `descr.get` is `undefined`"); 19 } 20 21 var x, staticX, y, staticY; 22 class C { 23 set x(v) { x = v; } 24 static set staticX(v) { staticX = v; } 25 set y(v) { y = v; } 26 static set staticY(v) { staticY = v; } 27 } 28 29 assert.sameValue(new C().x = 1, 1, "`new C().x = 1` is `1`"); 30 assert.sameValue(x, 1, "The value of `x` is `1`"); 31 assert.sameValue(C.staticX = 2, 2, "`C.staticX = 2` is `2`"); 32 assert.sameValue(staticX, 2, "The value of `staticX` is `2`"); 33 assert.sameValue(new C().y = 3, 3, "`new C().y = 3` is `3`"); 34 assert.sameValue(y, 3, "The value of `y` is `3`"); 35 assert.sameValue(C.staticY = 4, 4, "`C.staticY = 4` is `4`"); 36 assert.sameValue(staticY, 4, "The value of `staticY` is `4`"); 37 38 assertSetterDescriptor(C.prototype, 'x'); 39 assertSetterDescriptor(C.prototype, 'y'); 40 assertSetterDescriptor(C, 'staticX'); 41 assertSetterDescriptor(C, 'staticY'); 42 43 reportCompare(0, 0);