Skip to content

Commit

Permalink
Merge pull request #35 from GoogleChromeLabs/node-workers
Browse files Browse the repository at this point in the history
Add support for node worker threads
  • Loading branch information
surma committed Sep 23, 2020
2 parents 8cda3c6 + 5877efb commit b98ccbf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A small library to detect which features of WebAssembly are supported.
- ✅ Runs in Node
- ✅ Provided as an ES6 module, CommonJS and UMD module.
- ✅ CSP compatible
- ✅ Only ~520B gzipped
- ✅ Only ~570B gzipped

## Installation

Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default ["esm", "cjs", "umd"].map(format => ({
preferConst: true,
esModule: false
},
external: ["worker_threads"],
plugins: [
indexGenerator({
indexPath: "./src/index.js",
Expand Down
6 changes: 5 additions & 1 deletion src/detectors/threads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

export default async moduleBytes => {
try {
const MessageChannelConstructor =
typeof MessageChannel !== "undefined"
? MessageChannel
: await import("worker_threads").then(m => m.MessageChannel);
// Test for transferability of SABs (needed for Firefox)
// https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
new MessageChannel().port1.postMessage(new SharedArrayBuffer(1));
new MessageChannelConstructor().port1.postMessage(new SharedArrayBuffer(1));
return WebAssembly.validate(moduleBytes);
} catch (e) {
return false;
Expand Down

0 comments on commit b98ccbf

Please sign in to comment.