Skip to content

Commit

Permalink
Don't call assert.deepEqual.format when the assertion will succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
anba authored and Ms2ger committed Dec 18, 2024
1 parent c3cbc32 commit ee14d73
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions harness/deepEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ defines: [assert.deepEqual]

assert.deepEqual = function(actual, expected, message) {
var format = assert.deepEqual.format;
assert(
assert.deepEqual._compare(actual, expected),
`Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}`
);
var mustBeTrue = assert.deepEqual._compare(actual, expected);

// format can be slow when `actual` or `expected` are large objects, like for
// example the global object, so only call it when the assertion will fail.
if (mustBeTrue !== true) {
message = `Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}`;
}

assert(mustBeTrue, message);
};

(function() {
Expand Down

0 comments on commit ee14d73

Please sign in to comment.