Skip to content

Commit

Permalink
Add Chris Morgan's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Nov 25, 2019
1 parent b279da9 commit 8e465e0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 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 ~580B gzipped
- ✅ Only ~560B gzipped

## Installation

Expand Down
7 changes: 3 additions & 4 deletions rollup-plugins/index-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function({ indexPath, pluginFolder }) {
"",
""
])[1].split(" ");
const module = JSON.stringify([
const moduleBytes = JSON.stringify([
...(await compileWat(
`./src/${pluginFolder}/${plugin}/module.wat`,
flags
Expand All @@ -51,17 +51,16 @@ export default function({ indexPath, pluginFolder }) {
const importName = `${pluginName}_internal`;
return `
import { default as ${importName} } from "./${pluginFolder}/${plugin}/index.js";
export const ${pluginName} = ${importName}.bind(null, new Uint8Array(${module}), validate);
export const ${pluginName} = () => ${importName}(new Uint8Array(${moduleBytes}));
`;
}
return `
export const ${pluginName} = validate.bind(null, new Uint8Array(${module}));
export const ${pluginName} = () => WebAssembly.validate(new Uint8Array(${moduleBytes}));
`;
})
);

return `
import { validate } from './helpers.js';
${sources.join("\n")}
`;
}
Expand Down
6 changes: 3 additions & 3 deletions src/detectors/big-int/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
* limitations under the License.
*/

export default async function(bytes) {
export default async moduleBytes => {
try {
// This will throw a ReferenceError on platforms where BigInt is not
// supported. Please do not change the right hand side value to BigInt
// literal (i.e. 0n), cause in that case a SyntaxError will be thrown
// before an execution.
const n = BigInt(0);
const instance = await WebAssembly.instantiate(bytes);
const instance = await WebAssembly.instantiate(moduleBytes);
return instance.instance.exports.b(n) === n;
} catch (e) {
return false;
}
}
};
6 changes: 3 additions & 3 deletions src/detectors/threads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* limitations under the License.
*/

export default async function(module, validate) {
if (!(await validate(module))) return false;
export default moduleBytes => {
if (!WebAssembly.validate(moduleBytes)) return false;
try {
// Test for transferability of SABs (needed for Firefox)
// https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
Expand All @@ -21,4 +21,4 @@ export default async function(module, validate) {
} catch (e) {
return false;
}
}
};
19 changes: 0 additions & 19 deletions src/helpers.js

This file was deleted.

0 comments on commit 8e465e0

Please sign in to comment.