| 1 |
/*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */ |
| 2 |
|
| 3 |
if (!globalThis.DOMException) { |
| 4 |
try { |
| 5 |
const { MessageChannel } = require('worker_threads'), |
| 6 |
port = new MessageChannel().port1, |
| 7 |
ab = new ArrayBuffer() |
| 8 |
port.postMessage(ab, [ab, ab]) |
| 9 |
} catch (err) { |
| 10 |
err.constructor.name === 'DOMException' && ( |
| 11 |
globalThis.DOMException = err.constructor |
| 12 |
) |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
module.exports = globalThis.DOMException |
| 17 |
|
| 18 |
|
| 19 |
const { MessageChannel } = require('worker_threads') |
| 20 |
|
| 21 |
async function hello() { |
| 22 |
const port = new MessageChannel().port1 |
| 23 |
const ab = new ArrayBuffer() |
| 24 |
port.postMessage(ab, [ab, ab]) |
| 25 |
} |
| 26 |
|
| 27 |
hello().catch(err => { |
| 28 |
console.assert(err.name === 'DataCloneError') |
| 29 |
console.assert(err.code === 25) |
| 30 |
console.assert(err instanceof DOMException) |
| 31 |
}) |
| 32 |
|
| 33 |
const e1 = new DOMException('Something went wrong', 'BadThingsError') |
| 34 |
console.assert(e1.name === 'BadThingsError') |
| 35 |
console.assert(e1.code === 0) |
| 36 |
|
| 37 |
const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') |
| 38 |
console.assert(e2.name === 'NoModificationAllowedError') |
| 39 |
console.assert(e2.code === 7) |
| 40 |
|
| 41 |
console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) |