source: node_modules/node-domexception/.history/index_20210527214654.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
2
3if (!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
16module.exports = globalThis.DOMException
17
18
19const { MessageChannel } = require('worker_threads')
20
21async function hello() {
22 const port = new MessageChannel().port1
23 const ab = new ArrayBuffer()
24 port.postMessage(ab, [ab, ab])
25}
26
27hello().catch(err => {
28 console.assert(err.name === 'DataCloneError')
29 console.assert(err.code === 21)
30 console.assert(err instanceof DOMException)
31})
32
33const e1 = new DOMException('Something went wrong', 'BadThingsError')
34console.assert(e1.name === 'BadThingsError')
35console.assert(e1.code === 0)
36
37const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError')
38console.assert(e2.name === 'NoModificationAllowedError')
39console.assert(e2.code === 7)
40
41console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10)
Note: See TracBrowser for help on using the repository browser.