Support environments without MessageChannel or worker_threads

This commit is contained in:
mauve 2020-10-15 19:26:21 -04:00
parent 7febc97986
commit 90308dacd3
2 changed files with 11 additions and 3 deletions

View File

@ -1,13 +1,20 @@
/* eslint-disable camelcase */
var MessageChannel = global.MessageChannel
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
if (MessageChannel == null) {
try {
({ MessageChannel } = require('worker' + '_threads'))
} catch (e) {
// Must not be supported
}
}
function sodium_malloc (n) {
return new Uint8Array(n)
}
const sink = new MessageChannel()
const sink = MessageChannel ? new MessageChannel() : null
function sodium_free (n) {
if (!sink) return
sodium_memzero(n)
sink.port1.postMessage(n.buffer, [n.buffer])
}

View File

@ -24,7 +24,8 @@
]
},
"browser": {
"crypto": false
"crypto": false,
"worker_threads": false
},
"react-native": {
"crypto": "crypto"