Skip to content

Commit

Permalink
Handle undescribed own properties
Browse files Browse the repository at this point in the history
Fixes #71.
  • Loading branch information
ninevra authored Jul 25, 2021
1 parent b30e7c8 commit 791d2a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/getObjectKeys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const isEnumerable = require('./isEnumerable')

function getObjectKeys (obj, excludeListItemAccessorsBelowLength) {
const keys = []
let size = 0
Expand All @@ -17,13 +19,13 @@ function getObjectKeys (obj, excludeListItemAccessorsBelowLength) {
accept = !Number.isInteger(index) || index < 0 || index >= excludeListItemAccessorsBelowLength
}

if (accept && Object.getOwnPropertyDescriptor(obj, name).enumerable) {
if (accept && isEnumerable(obj, name)) {
keys[size++] = name
}
}

for (const symbol of symbolCandidates) {
if (Object.getOwnPropertyDescriptor(obj, symbol).enumerable) {
if (isEnumerable(obj, symbol)) {
keys[size++] = symbol
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/odd-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const test = require('ava')
const { compare } = require('..')

test('ignores undescribed own properties', t => {
const a = new Proxy({ a: 1 }, {
getOwnPropertyDescriptor (target, prop) {},
})
t.true(compare(a, {}).pass)
})

0 comments on commit 791d2a8

Please sign in to comment.