Skip to content

Commit

Permalink
Add custom prop isOwn to descriptor
Browse files Browse the repository at this point in the history
Makes it possible to see if the descriptor
originates from the object or its prototype chain
  • Loading branch information
fatso83 committed Mar 9, 2020
1 parent 49abbad commit 3031027
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/sinon/util/core/get-property-descriptor.js
Expand Up @@ -3,9 +3,15 @@
module.exports = function getPropertyDescriptor(object, property) {
var proto = object;
var descriptor;
var isOwn = object && Object.getOwnPropertyDescriptor(object, property);

while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
proto = Object.getPrototypeOf(proto);
}

if (descriptor) {
descriptor.isOwn = isOwn;
}

return descriptor;
};

0 comments on commit 3031027

Please sign in to comment.