Skip to content

Commit 42cdabd

Browse files
committed
feat: Make hasOwn handle null and undefined objects
1 parent 4df7792 commit 42cdabd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/shared/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* @param {String} property
66
*/
77
export function hasOwn (object, property) {
8+
if (object === null || typeof object === 'undefined') {
9+
return false
10+
}
11+
812
return Object.prototype.hasOwnProperty.call(object, property)
913
}
1014

test/shared/utils.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ test('has own checks for own properties', () => {
2020
expect(hasOwn(bar, 'baz')).toBeTruthy()
2121
})
2222

23+
test('has own correctly falsifies on null and undefined', () => {
24+
expect(hasOwn(null, 'foo')).toBeFalsy()
25+
expect(hasOwn(undefined, 'foo')).toBeFalsy()
26+
})
27+
2328
test('tells relative and absolute uris apart', () => {
2429
/**
2530
* List of `uri, is_absolute` pairs for testing.

0 commit comments

Comments
 (0)