diff --git a/memory.js b/memory.js index 4d8aa4f..4d8fefb 100644 --- a/memory.js +++ b/memory.js @@ -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]) } diff --git a/package.json b/package.json index d9a3b4e..518d11a 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ ] }, "browser": { - "crypto": false + "crypto": false, + "worker_threads": false }, "react-native": { "crypto": "crypto"