Skip to content

Commit 4692f0a

Browse files
committed
Fix plain object detection in edge-runtime
1 parent 4017e2d commit 4692f0a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/utils.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import {
1010
stringToUint8Array,
1111
} from "../utils";
1212

13+
class SomeClass {}
14+
1315
describe("isObject()", () => {
1416
it("should return true with objects", (done) => {
1517
expect(isObject({})).toBe(true);
18+
expect(isObject(new Object())).toBe(true);
1619

1720
done();
1821
});
@@ -25,6 +28,8 @@ describe("isObject()", () => {
2528
expect(isObject(false)).toBe(false);
2629
expect(isObject("str")).toBe(false);
2730
expect(isObject(new Uint8Array(1))).toBe(false);
31+
expect(isObject(new Map())).toBe(false);
32+
expect(isObject(new SomeClass())).toBe(false);
2833

2934
done();
3035
});
@@ -45,6 +50,8 @@ describe("isNumeric()", () => {
4550
expect(isNumeric(false)).toBe(false);
4651
expect(isNumeric([])).toBe(false);
4752
expect(isNumeric({})).toBe(false);
53+
expect(isNumeric(new Object())).toBe(false);
54+
expect(isNumeric(new Map())).toBe(false);
4855

4956
done();
5057
});

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export function isNumeric(value: unknown): value is number {
2727
}
2828

2929
export function isObject(value: unknown): value is Record<string, unknown> {
30-
return value instanceof Object && value.constructor === Object;
30+
if (!(value instanceof Object)) {
31+
return false;
32+
}
33+
34+
const proto = Object.getPrototypeOf(value);
35+
return proto == null || proto === Object.prototype;
3136
}
3237

3338
export function isPromise(value: unknown): value is Promise<unknown> {

0 commit comments

Comments
 (0)