diff --git a/assert/equal.ts b/assert/equal.ts index 20146e96076e..4091ab66e00a 100644 --- a/assert/equal.ts +++ b/assert/equal.ts @@ -9,9 +9,7 @@ function isKeyedCollection(x: unknown): x is KeyedCollection { function prototypesEqual(a: object, b: object) { const pa = Object.getPrototypeOf(a); const pb = Object.getPrototypeOf(b); - return pa === pb || - pa === Object.prototype && pb === null || - pa === null && pb === Object.prototype; + return pa === pb; } function isBasicObjectOrArray(obj: object) { diff --git a/assert/equal_test.ts b/assert/equal_test.ts index c068e04aefda..0179cdd07142 100644 --- a/assert/equal_test.ts +++ b/assert/equal_test.ts @@ -383,6 +383,18 @@ Deno.test("equal() with constructor and prototype", async (t) => { }); }); +Deno.test("equal() considers object with prototype Object.prototype not equal to object with no prototype", () => { + const a = Object.create(Object.prototype); + const b = Object.create(null); + assertFalse(equal(a, b)); + assertFalse(equal(b, a)); + + // ensure the only difference is the prototype + Object.setPrototypeOf(b, Object.prototype); + assert(equal(a, b)); + assert(equal(b, a)); +}); + Deno.test("equal() with dynamic properties defined on the prototype", async (t) => { await t.step("built-in web APIs", async (t) => { await t.step("URLPattern", () => {