-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix: check array's custom properties #38
base: main
Are you sure you want to change the base?
fix: check array's custom properties #38
Conversation
I'm on the fence about this, but regardless of those opinions, I would say this is probably a The code itself is fine, again regardless of my fence-sitting. But I would also say that if this is true:
Then we should write tests that validate against these cases to ensure that later on a PR is not made to optimise this path and use Sidebar: Also, looks like node 0.12 is failing, but as it is EOL maybe this PR (especially if it is a breaking change) could drop Node 0.12 support? |
Hey @lucasfcosta, great job! The most common case of having to deal with non-index keys is result of Please, consider /a/.exec("a").should.eql(["a"]) If I read correctly, PR makes that throw. Is this something we are OK with? It is impossible to special-case |
@keithamus Thanks for your feedback 😄. We already have tests that deal with this. The IMO we should indeed drop v0.12. I've just ammended a change to my commit for that. @shvaikalesh that's a good question. I'd like it to pass, but I think it's more adequate to let people deal with this by adding the missing properties to the expected result than to throw incorrectly on the other cases, after all, this is how the real result of running |
return false; | ||
} | ||
|
||
for (var prop in rightHandProps) { |
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.
Maybe we can do
return rightHandProps.every(function(prop) {
return deepEqual(leftHandOperand[prop], rightHandOperand[prop], options);
});
to avoid for in
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.
I'll try this and run the benchmarks to see if it's worth it, but I do agree it would be a lot more clean.
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.
Using for ... in
the way it is used here would actually open up another bug as it would also test for inherited properties.
The fasted way to check this properly is to use Object.keys
with a plain for loop.
@lucasfcosta I'm late to the party but this change makes sense to me. Were you able to compare the performance of |
Hi @meeber, unfortunately I didn't. I've been very busy in the last few weeks because I'll be moving to London in the next two months so I'm kind of getting things done around here in Brazil so that I can be ready to move ASAP. So I'd like to say sorry for not being able to be as present as I've been before. Hopefully I'll have some free time this weekend so that I can check this and finish this PR and get back to contributing more frequently as soon as things are set up. Btw, thanks everyone for keeping things going, I've seen you've done some amazing work recently. |
@lucasfcosta Sounds exciting! Congrats on the big move! Take your time with things, Chai will still be here when you're ready. |
Hi, folks!
While working on sinonjs/sinon#1322 I've found out that we're not checking for custom properties in arrays when doing deep equality on them.
While this might be considered a bad practice, it is indeed possible and more common that we'd like it to be, so this fix may come in handy.
Before this commit, two different arrays, like these ones, would yield false positives:
Also, I didn't use
getEnumerableKeys
when getting the Array's properties because we don't want to check the Array prototype, because when dealing with Buffers orTypedArrays
, they might have different offsets due to the fact of being binary data and this could cause problems. Especially when usingBuffer
itself.If you don't mind I could add a check to avoid comparing the
offset
property onTypedArrays
only so that we can compare the other properties in the array prototype, but I don't that would be productive.I also added tests for this behavior.