diff --git a/src/utils/isPlainObject.ts b/src/utils/isPlainObject.ts index 9d1956328a..2767112254 100644 --- a/src/utils/isPlainObject.ts +++ b/src/utils/isPlainObject.ts @@ -5,10 +5,6 @@ export default function isPlainObject(obj: any): boolean { if (typeof obj !== 'object' || obj === null) return false - let proto = obj - while (Object.getPrototypeOf(proto) !== null) { - proto = Object.getPrototypeOf(proto) - } - - return Object.getPrototypeOf(obj) === proto + const proto = obj.__proto__ + return !proto || !Object.getPrototypeOf(proto) } diff --git a/test/utils/isPlainObject.spec.ts b/test/utils/isPlainObject.spec.ts index 62fe216152..2c984ea8ba 100644 --- a/test/utils/isPlainObject.spec.ts +++ b/test/utils/isPlainObject.spec.ts @@ -10,7 +10,11 @@ describe('isPlainObject', () => { expect(isPlainObject(new Date())).toBe(false) expect(isPlainObject([1, 2, 3])).toBe(false) expect(isPlainObject(null)).toBe(false) + expect(isPlainObject('')).toBe(false) + expect(isPlainObject(true)).toBe(false) expect(isPlainObject(undefined)).toBe(false) + expect(isPlainObject(false)).toBe(false) expect(isPlainObject({ x: 1, y: 2 })).toBe(true) + expect(isPlainObject(Object.create(null))).toBe(true) }) })