b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
423 stars 48 forks source link

The monkeypatched Array[Symbol.hasInstance] and Array.isArray throw when passed null or undefined #5

Open andreubotella opened 4 years ago

andreubotella commented 4 years ago

The monkeypatched versions of Array[Symbol.hasInstance] and Array.isArray defined in src/api.ts will throw when passed null or undefined. This is problematic because those monkeypatched versions pollute the global namespace, and can cause hard-to-debug action at a distance across modules.

b-fuze commented 4 years ago

Yeah, I'm honestly not sure of the best way forward with that. A NodeList and HTMLCollection aren't arrays, so they shouldn't be identified as such. I'd really like some way to keep an implementation based on arrays for that magical performance they get, but this Javascript limitation is quite frustrating to say the least.

I'll fix the current behavior, and will look into an alternative implementation for the actual NodeList/HTMLCollection.

b-fuze commented 4 years ago

Fixed in f51eafcace70587eb1bc88ac8a16edcb5db142e9. However, the issue of global pollution still stands so I'll leave this open for now.