Skip to content

Avoid deferring to the base type for object equality.#470

Closed
alexjeffburke wants to merge 1 commit intounexpectedjs:masterfrom
alexjeffburke:fix/enumerablePropertyEdgeCaseInToEqualError
Closed

Avoid deferring to the base type for object equality.#470
alexjeffburke wants to merge 1 commit intounexpectedjs:masterfrom
alexjeffburke:fix/enumerablePropertyEdgeCaseInToEqualError

Conversation

@alexjeffburke
Copy link
Member

Move checking object equality into a separate common function
utils.checkObjectEqualityUsingType(). Use this within the base object
type but also when comparing Error keys - since this function accepts
the type, in the case of the Error type it ensures equality is
evaluated using the subtype getKeys() thus addressing the mismatching
keys issue.

Move checking object equality into a separate common function
utils.checkObjectEqualityUsingType(). Use this within the base object
type but also when comparing Error keys - since this function accepts
the type, in the case of the Error type it ensures equality is
evaluated using the subtype getKeys() thus addressing the mismatching
keys issue.
@alexjeffburke
Copy link
Member Author

This is another take on fixing #439: as compared to the other PR, this avoids the nastiness of calling into the super type equal() but overriding the type being used by making evaluating object equality a common utility function and calling it directly and it feels somewhat cleaner. cc @papandreou @sunesimonsen

});
});

describe('when comparing Error objects with differing enumarable keys', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enumerable

@papandreou
Copy link
Member

Hmm, I'm not sure I understand why calling this.baseType.equal(...) is nasty?

@alexjeffburke
Copy link
Member Author

Hmmm. It’s calling the parent equal() but then telling it to use another type - that’s what led to my thinking it’s more like a utility method. It seemed like Sune wasn’t too keen on the original either, hence this version.. which were you leaning towards?

@papandreou
Copy link
Member

papandreou commented May 12, 2018

I'd really like to get a fix in for the general case. This seems to work and cover all the cases we've discussed, but the indexOf probably makes it too expensive for huge objects. We could handle that by building an index of either object has more than X keys.

@alexjeffburke
Copy link
Member Author

Hmm. I’m not disagreeing about fixing the general case, but I think I like the idea of getting s fix out for Error ahead of that given node will fix that mishap at some point and I’d like to remove the hacks done in plugins asap.

As for the general thing, I guess the reason I’m hesitant is I think we should be a little cautious papering over enumerability differences silently. If pushed, I think my personal preference would be to make it explicit as a job of getKeys() - in the case of Error that’s actually what we already do as the type adds message unconditionally. But note the type specified those semantics.

@alexjeffburke
Copy link
Member Author

@papandreou to follow up - if properties have been attached in a special way, isn’t it arguable that it has special meaning thus is better defined as a custom type? At least that roughly captures the debate I’m having internally.

@papandreou
Copy link
Member

@alexjeffburke, for the record the linked commit also fixes the Error#message enumerability thing (I stole your test, too :).

I’ve thought about it for a bit and couldn’t come up with any reason why papering over enumerability differences would be bad. If you really meant to compare two objects including the enumerability of the keys, I think you’d instinctively check the enumerability in a separate assertion anyway. It feels much too edge casey to be the default, even more so than a missing property vs. a present property with a value of undefined that we’re also papering over.

@sunesimonsen
Copy link
Member

I'll make up some time to look into this.

@sunesimonsen
Copy link
Member

@alexjeffburke I'm very sorry for being so late to the party. I agree with @papandreou that a general solution would be preferable and that papering over enumerability probably is fine. I think the spike @papandreou did looks interesting, but we need to make it faster with key indexes if possible. Otherwise I'm a bit worried that it will be too slow.

@sunesimonsen
Copy link
Member

sunesimonsen commented Jun 20, 2018

Strike that @papandreou just informed me that there is an even better solution around :-)

#482

@papandreou
Copy link
Member

IMO this is fixed better by #482, OK to close this?

@alexjeffburke
Copy link
Member Author

This issue has been addressed by comprehensive enumerable property support that has now been merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants