Skip to content

Commit

Permalink
[Fix] Update implementation to not return undefined descriptors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 26, 2016
1 parent 4624f47 commit 864ac07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ module.exports = function getOwnPropertyDescriptors(value) {

var O = ES.ToObject(value);
return reduce(getAll(O), function (acc, key) {
safePut(acc, key, getDescriptor(O, key));
var descriptor = getDescriptor(O, key);
if (typeof descriptor !== 'undefined') {
safePut(acc, key, descriptor);
}
return acc;
}, {});
};
17 changes: 17 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,21 @@ module.exports = function (getDescriptors, t) {
});
st.end();
});

var supportsProxy = typeof Proxy === 'function';
t.test('Proxies that return an undefined descriptor', { skip: !supportsProxy }, function (st) {
var obj = { foo: true };
var fooDescriptor = Object.getOwnPropertyDescriptor(obj, 'foo');

var proxy = new Proxy(obj, {
ownKeys: function () {
return ['foo', 'bar'];
},
getOwnPropertyDescriptor: function (target, key) {
return Object.getOwnPropertyDescriptor(target, key);
}
});
st.deepEqual(getDescriptors(proxy), { foo: fooDescriptor }, 'object has no descriptors');
st.end();
});
};

0 comments on commit 864ac07

Please sign in to comment.