You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm reading the source code to understand how it works and I think I found a subtle bug. data.listeners++ will fail the first time with a runtime error because data is undefined.
I haven't verified it during runtime yet. And it's in the middle of the night here and I need to sleep. Will look at it again tomorrow; but thought it wise to report this here lest I forget.
functiononAddListener(originalFn,type,handler,options){// Polyfill scrollend event on any element for which the developer listens// to 'scrollend' explicitly or 'scroll' (so that adding a scrollend listener// from within a scroll listener works).if(type!="scroll"&&type!="scrollend")return;letscrollport=this;letdata=observed.get(scrollport);if(data===undefined){lettimeout=0;data={scrollListener: (evt)=>{clearTimeout(timeout);timeout=setTimeout(()=>{if(pointers.size){// if pointer(s) are down, wait longersetTimeout(data.scrollListener,100);}else{// dispatchif(scrollport){scrollport.dispatchEvent(scrollendEvent);}timeout=0;}},100);},listeners: 0,// Count of number of listeners.};originalFn.apply(scrollport,["scroll",data.scrollListener]);observed.set(scrollport,data);}data.listeners++;}
EDIT: I was wrong.
As promised I looked at it by daylight and see now that the data variable will be initialized within the if (data === undefined) {...} branch. So no bug there. That's why I didn't open an issue in the night; only a question.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm reading the source code to understand how it works and I think I found a subtle bug.
data.listeners++
will fail the first time with a runtime error becausedata
is undefined.I haven't verified it during runtime yet. And it's in the middle of the night here and I need to sleep. Will look at it again tomorrow; but thought it wise to report this here lest I forget.
EDIT: I was wrong.
As promised I looked at it by daylight and see now that the
data
variable will be initialized within theif (data === undefined) {...}
branch. So no bug there. That's why I didn't open an issue in the night; only a question.Beta Was this translation helpful? Give feedback.
All reactions