Skip to content

Commit 2aabf29

Browse files
authored
Merge pull request #15 from webxdc/wasm-check
add check for wasm
2 parents 5fd5d93 + df5ebc1 commit 2aabf29

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<div class="card" id="races-output"></div>
3838
<script src="js/races.js"></script>
3939

40+
<div class="card" id="wasm-output"></div>
41+
<script src="js/wasm.js"></script>
42+
4043
<iframe id="iframe-regular" style="display: none"></iframe>
4144
<iframe id="iframe-allow-same-origin" sandbox="allow-same-origin" style="display: none"></iframe>
4245
<div class="card" id="webrtc-output"></div>

js/wasm.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
window.addEventListener("load", () => {
2+
let container = h("div", { class: "container" });
3+
const supported = (() => {
4+
// thanks to https://stackoverflow.com/a/47880734 for this check
5+
try {
6+
if (
7+
typeof WebAssembly === "object" &&
8+
typeof WebAssembly.instantiate === "function"
9+
) {
10+
const module = new WebAssembly.Module(
11+
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
12+
);
13+
if (module instanceof WebAssembly.Module)
14+
return (
15+
new WebAssembly.Instance(module) instanceof WebAssembly.Instance
16+
);
17+
}
18+
} catch (e) {}
19+
return false;
20+
})();
21+
22+
let result = h("div", {
23+
class: "wasm-support-dot",
24+
style: `background-color:${supported ? "green" : "grey"}`,
25+
});
26+
27+
container.append(result);
28+
container.append(
29+
supported ? "WebAssembly is supported" : "WebAssembly is not supported"
30+
);
31+
document
32+
.getElementById("wasm-output")
33+
.append(createHeader("Wasm Support"), container);
34+
});

styles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ button {
3434
padding: 0.5em;
3535
margin: 0.3em;
3636
}
37+
38+
.wasm-support-dot {
39+
width: 1em;
40+
height: 1em;
41+
border-radius: 100%;
42+
display: inline-block;
43+
margin-right: 4px;
44+
}

0 commit comments

Comments
 (0)