a338ae9f9d
* Detach buffers by sending to an empty message channel * Move helpers out * fix import * export helpers * Try browser testing * messagechannel check * xvfb-run --auto-servernum npm run test-browser fails weirdly on ci, removing Co-authored-by: Mathias Buus <mathiasbuus@gmail.com>
24 lines
466 B
JavaScript
24 lines
466 B
JavaScript
/* eslint-disable camelcase */
|
|
var MessageChannel = global.MessageChannel
|
|
if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads'))
|
|
|
|
function sodium_malloc (n) {
|
|
return new Uint8Array(n)
|
|
}
|
|
|
|
const sink = new MessageChannel()
|
|
function sodium_free (n) {
|
|
sodium_memzero(n)
|
|
sink.port1.postMessage(n.buffer, [n.buffer])
|
|
}
|
|
|
|
function sodium_memzero (arr) {
|
|
arr.fill(0)
|
|
}
|
|
|
|
module.exports = {
|
|
sodium_malloc,
|
|
sodium_free,
|
|
sodium_memzero
|
|
}
|