| 1 |
// Copyright (C) 2016 Jordan Harband. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Object.getOwnPropertyDescriptors does not see inherited properties. |
| 6 |
esid: sec-object.getownpropertydescriptors |
| 7 |
author: Jordan Harband |
| 8 |
---*/ |
| 9 |
|
| 10 |
var F = function() {}; |
| 11 |
F.prototype.a = {}; |
| 12 |
F.prototype.b = {}; |
| 13 |
|
| 14 |
var f = new F(); |
| 15 |
var bValue = {}; |
| 16 |
f.b = bValue; // shadow the prototype |
| 17 |
Object.defineProperty(f, 'c', { |
| 18 |
enumerable: false, |
| 19 |
configurable: true, |
| 20 |
writable: false, |
| 21 |
value: {} |
| 22 |
}); // solely an own property |
| 23 |
|
| 24 |
var result = Object.getOwnPropertyDescriptors(f); |
| 25 |
|
| 26 |
assert.sameValue(!!result.b, true, 'b has a descriptor'); |
| 27 |
assert.sameValue(!!result.c, true, 'c has a descriptor'); |
| 28 |
|
| 29 |
assert.sameValue(result.b.enumerable, true, 'b is enumerable'); |
| 30 |
assert.sameValue(result.b.configurable, true, 'b is configurable'); |
| 31 |
assert.sameValue(result.b.writable, true, 'b is writable'); |
| 32 |
assert.sameValue(result.b.value, bValue, 'b’s value is `bValue`'); |
| 33 |
|
| 34 |
assert.sameValue(result.c.enumerable, false, 'c is enumerable'); |
| 35 |
assert.sameValue(result.c.configurable, true, 'c is configurable'); |
| 36 |
assert.sameValue(result.c.writable, false, 'c is writable'); |
| 37 |
assert.sameValue(result.c.value, f.c, 'c’s value is `f.c`'); |
| 38 |
|
| 39 |
assert.sameValue( |
| 40 |
Object.keys(result).length, |
| 41 |
2, |
| 42 |
'result has same number of own property names as f' |
| 43 |
); |