2020-06-24 12:01:48 +00:00
|
|
|
/* eslint-disable camelcase */
|
2020-08-12 13:39:14 +00:00
|
|
|
var MessageChannel = global.MessageChannel
|
|
|
|
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
|
2020-06-24 12:01:48 +00:00
|
|
|
|
|
|
|
function sodium_malloc (n) {
|
|
|
|
return new Uint8Array(n)
|
|
|
|
}
|
|
|
|
|
2020-08-12 13:39:14 +00:00
|
|
|
const sink = new MessageChannel()
|
|
|
|
function sodium_free (n) {
|
|
|
|
sodium_memzero(n)
|
|
|
|
sink.port1.postMessage(n.buffer, [n.buffer])
|
|
|
|
}
|
|
|
|
|
2020-06-24 12:01:48 +00:00
|
|
|
function sodium_memzero (arr) {
|
|
|
|
arr.fill(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
sodium_malloc,
|
2020-08-12 13:39:14 +00:00
|
|
|
sodium_free,
|
2020-06-24 12:01:48 +00:00
|
|
|
sodium_memzero
|
|
|
|
}
|