mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): improve comparison of faked objects in deepStrictEqual
(#29819)
This commit improves the handling of objects with faked prototypes in `deepStrictEqual`. This enables `parallel/test-assert-checktag.js` - `Date` objects are checked by `core.isDate` - In object comparison, now it checks `obj.toString()` output (The difference of `Symbol.toStringTag` is now detected). - Stoped using std's assertion error message for `deepStrictEqual`, but started using Node.js version of diff string. Now the diff expression is more compatible with Node.
This commit is contained in:
parent
1e9415cda8
commit
c538f44fa0
8 changed files with 109 additions and 19 deletions
|
@ -1,9 +1,8 @@
|
|||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
// vendored from std/assert/mod.ts
|
||||
|
||||
import { primordials } from "ext:core/mod.js";
|
||||
import { core, primordials } from "ext:core/mod.js";
|
||||
const {
|
||||
DatePrototype,
|
||||
ArrayPrototypeJoin,
|
||||
ArrayPrototypeMap,
|
||||
DatePrototypeGetTime,
|
||||
|
@ -13,6 +12,7 @@ const {
|
|||
ObjectIs,
|
||||
ObjectKeys,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
ObjectPrototypeToString,
|
||||
ReflectHas,
|
||||
ReflectOwnKeys,
|
||||
RegExpPrototype,
|
||||
|
@ -89,10 +89,10 @@ export function equal(c: unknown, d: unknown): boolean {
|
|||
) {
|
||||
return String(a) === String(b);
|
||||
}
|
||||
if (
|
||||
ObjectPrototypeIsPrototypeOf(DatePrototype, a) &&
|
||||
ObjectPrototypeIsPrototypeOf(DatePrototype, b)
|
||||
) {
|
||||
if (core.isDate(a) || core.isDate(b)) {
|
||||
if (!core.isDate(a) || !core.isDate(b)) {
|
||||
return false;
|
||||
}
|
||||
const aTime = DatePrototypeGetTime(a);
|
||||
const bTime = DatePrototypeGetTime(b);
|
||||
// Check for NaN equality manually since NaN is not
|
||||
|
@ -112,6 +112,9 @@ export function equal(c: unknown, d: unknown): boolean {
|
|||
if (a && b && !constructorsEqual(a, b)) {
|
||||
return false;
|
||||
}
|
||||
if (ObjectPrototypeToString(a) !== ObjectPrototypeToString(b)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
ObjectPrototypeIsPrototypeOf(WeakMapPrototype, a) ||
|
||||
ObjectPrototypeIsPrototypeOf(WeakMapPrototype, b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue