-
-
Notifications
You must be signed in to change notification settings - Fork 34.9k
Description
Affected URL(s)
https://nodejs.org/docs/latest-v24.x/api/assert.html#comparison-details_1
Description of the problem
I’ve been running into an bug in my code where assert.deepStrictEqual(a, b) was throwing unexpectedly.
To make a long story short, a and b were instances of a derived class that returned a new Proxy object in its constructor. The handler for this proxy set a new Function.prototype.bind call on any function object from the target, but this accidentally caught the target.constructor property in the line of fire — the intent was to only rebind instance methods. Basically, a and b shared the same prototype, but had unequal .constructor properties due to the incorrect binding.
The docs for assert.deepStrictEqual say that only the [[Prototype]] and enumerable own properties are checked, so I was scratching my head trying to track down the bug, meticulously checking my code against the docs point by point. Only by stepping through the Node.JS source code did I see where .constructor is accessed. Then I found the new docs for util.isDeepStrictEqual, which in v24 has been updated to mention explicitly that constructors are checked. This would’ve been good to know!
So this issue is a request to update the assert.deepStrictEqual docs by adding a bullet point stating how object constructors are included in the comparison algorithm. Thank you!