| 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: 14.5 |
| 5 |
description: > |
| 6 |
class accessors |
| 7 |
---*/ |
| 8 |
|
| 9 |
function assertAccessorDescriptor(object, name) { |
| 10 |
var desc = Object.getOwnPropertyDescriptor(object, name); |
| 11 |
assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`"); |
| 12 |
assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`"); |
| 13 |
assert.sameValue(typeof desc.get, 'function', "`typeof desc.get` is `'function'`"); |
| 14 |
assert.sameValue(typeof desc.set, 'function', "`typeof desc.set` is `'function'`"); |
| 15 |
assert.sameValue( |
| 16 |
'prototype' in desc.get, |
| 17 |
false, |
| 18 |
"The result of `'prototype' in desc.get` is `false`" |
| 19 |
); |
| 20 |
assert.sameValue( |
| 21 |
'prototype' in desc.set, |
| 22 |
false, |
| 23 |
"The result of `'prototype' in desc.set` is `false`" |
| 24 |
); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
class C { |
| 29 |
constructor(x) { |
| 30 |
this._x = x; |
| 31 |
} |
| 32 |
|
| 33 |
get x() { return this._x; } |
| 34 |
set x(v) { this._x = v; } |
| 35 |
|
| 36 |
static get staticX() { return this._x; } |
| 37 |
static set staticX(v) { this._x = v; } |
| 38 |
} |
| 39 |
|
| 40 |
assertAccessorDescriptor(C.prototype, 'x'); |
| 41 |
assertAccessorDescriptor(C, 'staticX'); |
| 42 |
|
| 43 |
var c = new C(1); |
| 44 |
c._x = 1; |
| 45 |
assert.sameValue(c.x, 1, "The value of `c.x` is `1`, after executing `c._x = 1;`"); |
| 46 |
c.x = 2; |
| 47 |
assert.sameValue(c._x, 2, "The value of `c._x` is `2`, after executing `c.x = 2;`"); |
| 48 |
|
| 49 |
C._x = 3; |
| 50 |
assert.sameValue(C.staticX, 3, "The value of `C.staticX` is `3`, after executing `C._x = 3;`"); |
| 51 |
C._x = 4; |
| 52 |
assert.sameValue(C.staticX, 4, "The value of `C.staticX` is `4`, after executing `C._x = 4;`"); |
| 53 |
|
| 54 |
reportCompare(0, 0); |