timruffles / mobile-drag-drop

A drop-in shim to allow you to use existing html5 drag'n'drop code with mobile browsers
http://timruffles.github.io/mobile-drag-drop/demo/
MIT License
606 stars 149 forks source link

The library can crash if `document.elementFromPoint` returns null #179

Open diesieben07 opened 1 year ago

diesieben07 commented 1 year ago

If document.ElementFromPoint returns null, then this if-statement is skipped and execution falls off the end of the function, without any return. This means the function returns undefined. Callers of this function only check for null, not undefined. Specifically this if-statement makes it so that in this case the controller assumes there is an element causing "Cannot read property X of undefined" errors further down the line. The simplest fix is simply a return null; at the end of elementFromPoint.

I would suggest enabling TypeScript's strictNullChecks option, which can guard against problems like this.