-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
assert: use Same-value equality in deepStrictEqual #15398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,12 +118,13 @@ function areSimilarRegExps(a, b) { | |
| // For small buffers it's faster to compare the buffer in a loop. The c++ | ||
| // barrier including the Uint8Array operation takes the advantage of the faster | ||
| // binary compare otherwise. The break even point was at about 300 characters. | ||
| function areSimilarTypedArrays(a, b) { | ||
| // NOTE: Floats should only use binary comparison in non strict mode! | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Will this comment be clear to implementers? Would it be better to remove it and let tests catch any errors introduced by maintainers?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likely
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I removed the comment and the tests already include cases for this, so there is nothing to add anymore. |
||
| function areSimilarTypedArrays(a, b, max) { | ||
| const len = a.byteLength; | ||
| if (len !== b.byteLength) { | ||
| return false; | ||
| } | ||
| if (len < 300) { | ||
| if (len < max) { | ||
| for (var offset = 0; offset < len; offset++) { | ||
| if (a[offset] !== b[offset]) { | ||
| return false; | ||
|
|
@@ -160,10 +161,7 @@ function isObjectOrArrayTag(tag) { | |
| // reasonable to interpret their underlying memory in the same way, | ||
| // which is checked by comparing their type tags. | ||
| // (e.g. a Uint8Array and a Uint16Array with the same memory content | ||
| // could still be different because they will be interpreted differently) | ||
| // Never perform binary comparisons for Float*Arrays, though, | ||
| // since e.g. +0 === -0 is true despite the two values' bit patterns | ||
| // not being identical. | ||
| // could still be different because they will be interpreted differently). | ||
| // | ||
| // For strict comparison, objects should have | ||
| // a) The same built-in type tags | ||
|
|
@@ -211,8 +209,9 @@ function strictDeepEqual(actual, expected) { | |
| if (actual.message !== expected.message) { | ||
| return false; | ||
| } | ||
| } else if (!isFloatTypedArrayTag(actualTag) && ArrayBuffer.isView(actual)) { | ||
| if (!areSimilarTypedArrays(actual, expected)) { | ||
| } else if (ArrayBuffer.isView(actual)) { | ||
| if (!areSimilarTypedArrays(actual, expected, | ||
| isFloatTypedArrayTag(actualTag) ? 0 : 300)) { | ||
| return false; | ||
| } | ||
| // Buffer.compare returns true, so actual.length === expected.length | ||
|
|
@@ -266,9 +265,10 @@ function looseDeepEqual(actual, expected) { | |
| const actualTag = objectToString(actual); | ||
| const expectedTag = objectToString(expected); | ||
| if (actualTag === expectedTag) { | ||
| if (!isObjectOrArrayTag(actualTag) && !isFloatTypedArrayTag(actualTag) && | ||
| ArrayBuffer.isView(actual)) { | ||
| return areSimilarTypedArrays(actual, expected); | ||
| if (!isObjectOrArrayTag(actualTag) && ArrayBuffer.isView(actual)) { | ||
| return areSimilarTypedArrays(actual, expected, | ||
| isFloatTypedArrayTag(actualTag) ? | ||
| Infinity : 300); | ||
| } | ||
| // Ensure reflexivity of deepEqual with `arguments` objects. | ||
| // See https://github.com/nodejs/node-v0.x-archive/pull/7178 | ||
|
|
@@ -280,7 +280,9 @@ function looseDeepEqual(actual, expected) { | |
| function innerDeepEqual(actual, expected, strict, memos) { | ||
| // All identical values are equivalent, as determined by ===. | ||
| if (actual === expected) { | ||
| return true; | ||
| if (actual !== 0) | ||
| return true; | ||
| return strict ? Object.is(actual, expected) : true; | ||
| } | ||
|
|
||
| // Returns a boolean if (not) equal and undefined in case we have to check | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The fact that
Object.is()is used under the hood is probably not of interest to the end user compared to what the impact is for the end user. Like, if the big change is that+0and-0are no longer considered equal, maybe let's say that instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done