Support environments without MessageChannel or worker_threads
This commit is contained in:
parent
7febc97986
commit
90308dacd3
11
memory.js
11
memory.js
@ -1,13 +1,20 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
var MessageChannel = global.MessageChannel
|
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) {
|
function sodium_malloc (n) {
|
||||||
return new Uint8Array(n)
|
return new Uint8Array(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sink = new MessageChannel()
|
const sink = MessageChannel ? new MessageChannel() : null
|
||||||
function sodium_free (n) {
|
function sodium_free (n) {
|
||||||
|
if (!sink) return
|
||||||
sodium_memzero(n)
|
sodium_memzero(n)
|
||||||
sink.port1.postMessage(n.buffer, [n.buffer])
|
sink.port1.postMessage(n.buffer, [n.buffer])
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"browser": {
|
"browser": {
|
||||||
"crypto": false
|
"crypto": false,
|
||||||
|
"worker_threads": false
|
||||||
},
|
},
|
||||||
"react-native": {
|
"react-native": {
|
||||||
"crypto": "crypto"
|
"crypto": "crypto"
|
||||||
|
Loading…
Reference in New Issue
Block a user