Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit DOMException #96

Closed
jimmywarting opened this issue May 25, 2021 · 0 comments · Fixed by #97
Closed

Revisit DOMException #96

jimmywarting opened this issue May 25, 2021 · 0 comments · Fixed by #97

Comments

@jimmywarting
Copy link
Contributor

jimmywarting commented May 25, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant