| 1 |
/ |
| 2 |
|
| 3 |
if (!globalThis.DOMException) { |
| 4 |
const { MessageChannel } = require('worker_threads'), |
| 5 |
port = new MessageChannel().port1, |
| 6 |
ab = new ArrayBuffer() |
| 7 |
try { port.postMessage(ab, [ab, ab]) } |
| 8 |
catch (err) { |
| 9 |
err.constructor.name === 'DOMException' && ( |
| 10 |
globalThis.DOMException = err.constructor |
| 11 |
) |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
module.exports = globalThis.DOMException |
| 16 |
|
| 17 |
const e1 = new DOMException("Something went wrong", "BadThingsError"); |
| 18 |
console.assert(e1.name === "BadThingsError"); |
| 19 |
console.assert(e1.code === 0); |
| 20 |
|
| 21 |
const e2 = new DOMException("Another exciting error message", "NoModificationAllowedError"); |
| 22 |
console.assert(e2.name === "NoModificationAllowedError"); |
| 23 |
console.assert(e2.code === 7); |