Skip to content

Commit 88dc1e8

Browse files
authored
Merge pull request #1734 from Ilyklem/sync-is-plain-object
2 parents 25435d0 + c8f71b6 commit 88dc1e8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/toolkit/src/isPlainObject.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
export default function isPlainObject(value: unknown): value is object {
1212
if (typeof value !== 'object' || value === null) return false
1313

14-
let proto = value
15-
while (Object.getPrototypeOf(proto) !== null) {
16-
proto = Object.getPrototypeOf(proto)
14+
let proto = Object.getPrototypeOf(value)
15+
if (proto === null) return true
16+
17+
let baseProto = proto
18+
while (Object.getPrototypeOf(baseProto) !== null) {
19+
baseProto = Object.getPrototypeOf(baseProto)
1720
}
1821

19-
return Object.getPrototypeOf(value) === proto
22+
return proto === baseProto
2023
}

packages/toolkit/src/tests/isPlainObject.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ describe('isPlainObject', () => {
2020
expect(isPlainObject(null)).toBe(false)
2121
expect(isPlainObject(undefined)).toBe(false)
2222
expect(isPlainObject({ x: 1, y: 2 })).toBe(true)
23+
expect(isPlainObject(Object.create(null))).toBe(true)
2324
})
2425
})

0 commit comments

Comments
 (0)