Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
wasm-feature-detect
Advanced tools
A small library to detect which features of WebAssembly are supported in your current browser.
The wasm-feature-detect npm package is designed to help developers detect the availability of various WebAssembly (Wasm) features in the user's environment. This can be particularly useful for ensuring compatibility and optimizing performance by leveraging specific Wasm capabilities when they are available.
Detect SIMD Support
This feature allows you to detect if SIMD (Single Instruction, Multiple Data) is supported in the user's environment. SIMD can significantly improve performance for certain types of computations.
const wasmFeatureDetect = require('wasm-feature-detect');
wasmFeatureDetect.simd().then(supported => {
if (supported) {
console.log('SIMD is supported');
} else {
console.log('SIMD is not supported');
}
});
Detect Bulk Memory Operations Support
This feature checks if bulk memory operations are supported. Bulk memory operations can be used to efficiently manage memory in WebAssembly.
const wasmFeatureDetect = require('wasm-feature-detect');
wasmFeatureDetect.bulkMemory().then(supported => {
if (supported) {
console.log('Bulk Memory Operations are supported');
} else {
console.log('Bulk Memory Operations are not supported');
}
});
Detect Multi-Value Support
This feature detects if the multi-value extension is supported. Multi-value allows WebAssembly functions to return multiple values, which can simplify certain programming patterns.
const wasmFeatureDetect = require('wasm-feature-detect');
wasmFeatureDetect.multiValue().then(supported => {
if (supported) {
console.log('Multi-Value is supported');
} else {
console.log('Multi-Value is not supported');
}
});
The wasm-check package is another alternative for detecting WebAssembly features. It provides a simple API to check for the availability of specific Wasm capabilities. While it covers many of the same features as wasm-feature-detect, it may have a different set of supported features and a different API design.
A small library to detect which features of WebAssembly are supported.
npm install -g wasm-feature-detect
<script type="module">
import { simd } from "https://unpkg.com/wasm-feature-detect?module";
simd().then(simdSupported => {
if (simdSupported) {
/* SIMD support */
} else {
/* No SIMD support */
}
});
</script>
If required, there’s also a UMD version
<script src="https://unpkg.com/wasm-feature-detect/dist/umd/index.js"></script>
<script>
wasmFeatureDetect.simd().then(/* same as above */);
</script>
All detectors return a Promise<bool>
.
Function | Proposal |
---|---|
bulkMemory() | Bulk memory operations |
exceptions() | Exception handling |
multiValue() | Multi-value |
mutableGlobals() | Importable/Exportable mutable globals |
referenceTypes() | Reference Types |
saturatedFloatToInt() | Non-trapping float-to-int conversions |
signExtensions() | Sign-extension operators |
simd() | Fixed-Width SIMD |
tailCall() | Tail call |
threads() | Threads |
The technical reason is that some tests might have to be augmented to be asynchronous in the future. For example, Firefox is planning to make a change that would require a postMessage
call to detect SABs, which are required for threads.
The other reason is that you should be using WebAssembly.compile
, WebAssembly.instantiate
, or their streaming versions WebAssembly.compileStreaming
and WebAssembly.instantiateStreaming
, which are all asynchronous. You should already be prepared for asynchronous code when using WebAssembly!
If you want to contribute a new feature test, all you need to do is create a new folder in src/detectors
and it will be automatically picked up. The folder must contain a module.wat
file, which will be compiled using wat2wasm
.
;; Name: <Name of the feature for the README>
;; Proposal: <Link to the proposal’s explainer/repo>
;; Flags: <CLI flags for `wat2wasm`>
(module
;; More WAT code here
)
The folder can also contain an optional index.js
file, whose default export must be an async function. This function can do additional testing in JavaScript and must return a boolean. See the “threads” detector as an example.
License Apache-2.0
FAQs
A small library to detect which features of WebAssembly are supported in your current browser.
The npm package wasm-feature-detect receives a total of 118,424 weekly downloads. As such, wasm-feature-detect popularity was classified as popular.
We found that wasm-feature-detect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.