Revisit DOMException
jimmywarting opened this issue · 0 comments
jimmywarting commented
Okey, so i have been playing around with blobFrom
. It's annoying to have to install DOMException
and it's easy to forget to add that optional dependency
So i investigated in nodejs core, (cuz i know they have been implementing some web-idl stuff that depends on DOMexception to be thrown) and found this hack
They don't expose it in anyway but you can still obtain it!
import { MessageChannel } from 'worker_threads'
if (!globalThis.DOMException) {
const port = new MessageChannel().port1
const ab = new ArrayBuffer()
try { port.postMessage(ab, [ab, ab]) }
catch (err) { globalThis.DOMException = err.constructor }
}
I was thinking instead of depending on the DOMException package, then we could go with this hack instead - it's way smaller in size, and you will use the same instance as NodeJS.
Thoughts?