Problem with `instanceof` checks
brettz9 opened this issue · 1 comments
Hi,
Great library!
Been doing a little retooling (for a PR on SVGEdit to allow our version of canvg to add as a module), mostly to convert to ES6 Modules, and I noticed your instanceof
checks were off.
https://github.com/flozz/StackBlur/blob/master/src/stackblur.js#L85
has:
else if (typeof HTMLImageElement !== 'undefined' && !img instanceof HTMLImageElement) {
You want img instanceof HTMLImageElement
wrapped in parentheses here (and in the other 2 instances where this occurs) since otherwise the precedence will have !
applied first to img
, ensuring that this part of the expression will always render `true. In other words, your code always returns silently, even when an image element is provided (unless the previous block was reached by the user having supplied a string ID).
But for cross-frame support, not to mention easier Node support, you might want to avoid instanceof
checks and just duck-type here, e.g., checking for:
else if (!('naturalWidth' in img)) {
or, for the canvas:
else if (!('getContext' in canvas)) {
Also FYI, with the netscape privilege code removed, you've been left with an extra try-catch block.
Hello,
Please open a pull request with the changes you think useful, I will review and merge it as soon as possible :)