forked from GoogleChromeLabs/wasm-feature-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.md.ejs
79 lines (56 loc) · 2.42 KB
/
README.md.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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 ~<%= gzippedSize %>B gzipped
## Installation
```
npm install -g wasm-feature-detect
```
## Usage
```html
<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
```html
<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 |
| --- | --- |
<% for (let detector of detectors) { _%>
| `<%= detector.func %>()` | [<%= detector.name %>](<%= detector.proposal %>) |
<%_ } %>
## 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][ff coop] 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`][wat2wasm].
```wat
;; 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.
[ff coop]: https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
[wat2wasm]: https://github.com/webassembly/wabt
---
License Apache-2.0