A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/GoogleChromeLabs/wasm-feature-detect below:

GoogleChromeLabs/wasm-feature-detect: A small library to detect which features of WebAssembly are supported.

WebAssembly Feature Detection

A small library to detect which features of WebAssembly are supported.

npm install -g wasm-feature-detect
<script type="module">
	import { simd } from "wasm-feature-detect";

	if (await simd()) {
		/* SIMD support */
	} else {
		/* No SIMD support */
	}
</script>
<script type="module">
	import { simd } from "https://unpkg.com/wasm-feature-detect?module";
	// ...
</script>

If required, there’s also a UMD version

<script src="https://unpkg.com/wasm-feature-detect/dist/umd/index.js"></script>
<script>
	if (await wasmFeatureDetect.simd()) {
	  // ...
	}
</script>

All detectors return a Promise<bool>.

Why are all the tests async?

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4