Check nullity for __eq__ and __ne__
__eq__ for Array checks for the lenght of b, but b could be null
I do not understand the reason for this special case. Should objects with custom equality checks not be allowed to decide if they are equal to null (and undefined)?
What problems are caused by permitting null (or undefined) to pass through in here? Do they outweigh the possible benefits of being able to have a class which compares equal to them?
These are genuine questions: I don't know, I haven't done enough work with Transcrypt to say.
But my intuition is that classes should be able to receive raw null and undefined in their custom comparison methods, because this is more flexible and obvious to me than a special case where those specific values bypass custom comparison logic.
Also, possibly related: independent of this change, I don't understand why these built-in __eq__ and __ne__ functions are one-sided (they have a case for calling a.__eq__(b) but not a symmetric case for calling b.__eq__(a)).
Couple possibilities:
-
That's not implemented at all. If class A implements
__eq__and you do a comparison likenative_js_object == instance_of_A, Transcrypt never triesinstance_of_A.__eq__(native_js_object). That seems like such a profound gap in functionality, that I don't think that's likely to be the case. -
That's implemented inside the
.__eq__and.__ne__that are on the objects. If so, then I would expect anif(typeof b == 'object' && '__eq__' in b)check to happen in those methods before tryingb.__eq__(a), and that should protect against any inherent problem with lettingnullorundefinedfall through.