getters-prop-desc.js (1494B)
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 - "get" accessors 7 includes: [propertyHelper.js] 8 ---*/ 9 10 function assertGetterDescriptor(object, name) { 11 var desc = Object.getOwnPropertyDescriptor(object, name); 12 verifyProperty(object, name, { 13 enumerable: false, 14 configurable: true, 15 }); 16 assert.sameValue(typeof desc.get, 'function', "`typeof desc.get` is `'function'`"); 17 assert.sameValue('prototype' in desc.get, false, "The result of `'prototype' in desc.get` is `false`"); 18 assert.sameValue(desc.set, undefined, "The value of `desc.set` is `undefined`"); 19 } 20 21 class C { 22 get x() { return 1; } 23 static get staticX() { return 2; } 24 get y() { return 3; } 25 static get staticY() { return 4; } 26 } 27 28 assert.sameValue(new C().x, 1, "The value of `new C().x` is `1`. Defined as `get x() { return 1; }`"); 29 assert.sameValue(C.staticX, 2, "The value of `C.staticX` is `2`. Defined as `static get staticX() { return 2; }`"); 30 assert.sameValue(new C().y, 3, "The value of `new C().y` is `3`. Defined as `get y() { return 3; }`"); 31 assert.sameValue(C.staticY, 4, "The value of `C.staticY` is `4`. Defined as `static get staticY() { return 4; }`"); 32 33 assertGetterDescriptor(C.prototype, 'x'); 34 assertGetterDescriptor(C.prototype, 'y'); 35 assertGetterDescriptor(C, 'staticX'); 36 assertGetterDescriptor(C, 'staticY'); 37 38 reportCompare(0, 0);