Giter Club home page Giter Club logo

wasm-feature-detect's Introduction

WebAssembly Feature Detection

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

  • ✅ Runs in all major browsers
  • ✅ Runs in Node
  • ✅ Provided as an ES6 module, CommonJS and UMD module.
  • ✅ CSP compatible
  • ✅ Only ~520B gzipped

Installation

npm install -g wasm-feature-detect

Usage

<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>

Detectors

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

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!

Contributing

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

wasm-feature-detect's People

Contributors

surma avatar rreverser avatar devsnek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.