-
-
Notifications
You must be signed in to change notification settings - Fork 272
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
Prototype inheritance bug #317
Comments
I don't see why anybody would have an event called "valueOf" but this is a bug nonetheless, I never thought of that, I must have introduced similar bugs many times across the things I maintain 🤔 |
Agreed, this is not very likely to be triggered in this setting. We have found similar bugs in several codebases, including one belonging to a major company. jQuery hasn't fixed it yet, also. |
Fixing this, via This is a bug nonetheless though, so I'm also keeping this open so that users can learn about it. |
I'm sorry, I don't quite follow your reasoning. These are just two objects, created statically. How often are they created and what are the times precisely that are being doubled? They are surely in terms of milliseconds or microseconds, are they not? |
I counted 6 objects affected by the same issue across the codebase, they are only created once. If I remember correctly my crappy benchmark for this said that instantiating those objects without a prototype would require about 0.03ms more on my machine (but this isn't accounting for potentially greater time required to download and parse a slight bigger library). Pretty negligible, at least on my machine, but it'd say that and the increased size of the library costs more than what fixing this issue is worth 🤷♂ |
Actually we may use |
Current behavior
If, when using the
.on
function, the event type equals any of the properties ofObject.prototype
(in particular,constructor
,hasOwnProperty
,isPrototypeOf
,propertyIsEnumerable
,toLocaleString
,toString
,valueOf
), a JavaScript native TypeError is thrown by the framework.This is because of how
eventsFocus
andeventsHover
are defined and used. ThegetEventNameBubbling
function returnseventsHover[name]
if this is not a falsey value. However, whenname === "valueOf"
, for example, this property is found inObject.prototype
and the corresponding function object is returned. Later, a.split
will be invoked on that object, assuming incorrectly that it is a string, resulting in the error.This is a common error when using objects as maps in JavaScript, and TypeScript types are not strong enough to catch it.
Expected behavior
No TypeError should be thrown,
eventsFocus[name]
andeventsHover[name]
should returnundefined
, and the execution should continue.Solution
Create
eventsFocus
andeventsHover
usingObject.create(null)
to disable any prototype inheritance.The text was updated successfully, but these errors were encountered: