-
-
Notifications
You must be signed in to change notification settings - Fork 273
Description
Current behavior
If, when using the .on
function, the event type equals any of the properties of Object.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
and eventsHover
are defined and used. The getEventNameBubbling
function returns eventsHover[name]
if this is not a falsey value. However, when name === "valueOf"
, for example, this property is found in Object.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]
and eventsHover[name]
should return undefined
, and the execution should continue.
Solution
Create eventsFocus
and eventsHover
using Object.create(null)
to disable any prototype inheritance.