Security News
RubyGems.org Adds New Maintainer Role
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.
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 |
---|---|
bigInt() | BigInt integration |
bulkMemory() | Bulk memory operations |
exceptions() | Exception handling |
extendedConst() | Extented Const Expressesions |
memory64() | Memory64 |
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 |
streamingCompilation() | Streaming Compilation |
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 may contain a module.wat
file, which will be compiled using wabt.js
.
;; Name: <Name of the feature for the README>
;; Proposal: <Link to the proposal’s explainer/repo>
;; Features: <Space-separated list of WasmFeatures from wabt.js>
(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.
It must contain at least one of module.wat
or index.js
.
License Apache-2.0
FAQs
A small library to detect which features of WebAssembly are supported in your current browser.
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
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.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.