|
534 | 534 |
|
535 | 535 | Event._isCustomEvent = isCustomEvent;
|
536 | 536 |
|
537 |
| - function getRegistryForElement(element) { |
| 537 | + // These two functions take an optional UID as a second argument so that we |
| 538 | + // can skip lookup if we've already got the element's UID. |
| 539 | + function getRegistryForElement(element, uid) { |
538 | 540 | var CACHE = GLOBAL.Event.cache;
|
539 |
| - var uid = getUniqueElementID(element); |
| 541 | + if (Object.isUndefined(uid)) |
| 542 | + uid = getUniqueElementID(element); |
540 | 543 | if (!CACHE[uid]) CACHE[uid] = { element: element };
|
541 | 544 | return CACHE[uid];
|
542 | 545 | }
|
543 | 546 |
|
544 |
| - function destroyRegistryForElement(element) { |
545 |
| - var uid = getUniqueElementID(element); |
| 547 | + function destroyRegistryForElement(element, uid) { |
| 548 | + if (Object.isUndefined(uid)) |
| 549 | + uid = getUniqueElementID(element); |
546 | 550 | delete GLOBAL.Event.cache[uid];
|
547 | 551 | }
|
548 | 552 |
|
|
897 | 901 |
|
898 | 902 | // Stop observing _all_ listeners on an element.
|
899 | 903 | function stopObservingElement(element) {
|
900 |
| - var registry = getRegistryForElement(element); |
901 |
| - destroyRegistryForElement(element); |
| 904 | + var uid = getUniqueElementID(element), |
| 905 | + registry = getRegistryForElement(element, uid); |
| 906 | + |
| 907 | + destroyRegistryForElement(element, uid); |
902 | 908 |
|
903 | 909 | var entries, i;
|
904 | 910 | for (var eventName in registry) {
|
| 911 | + // Explicitly skip elements so we don't accidentally find one with a |
| 912 | + // `length` property. |
| 913 | + if (eventName === 'element') continue; |
| 914 | + |
905 | 915 | entries = registry[eventName];
|
906 | 916 | i = entries.length;
|
907 | 917 | while (i--)
|
|
0 commit comments