Skip to content

Commit

Permalink
Replace 3 proposals checks with a single
Browse files Browse the repository at this point in the history
  • Loading branch information
JSMonk authored Jul 2, 2024
1 parent 8479e3a commit 978c9ef
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions shared/src/webMain/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,36 @@
<script type="application/javascript">
const body = document.body

const hasWasmGcSupport = () =>
WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 95, 1, 120, 0]))

const hasWasmExceptionSupport = () =>
WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 8, 1, 6, 0, 6, 64, 25, 11, 11])
);

const hasWasmReferenceTypeSupport = () =>
WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 208, 112, 26, 11]))
/*
Represents the next Wasm module:
(module
(type $type0 (struct (field $field0 i8))) ;; check [Garbage Collector](https://github.com/WebAssembly/gc/blob/main/proposals/gc/Overview.md) support
(func $func0 ;; check [Exception Handling](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md) support
try
catch_all
end
)
(func $func1 ;; check [Function References](https://github.com/WebAssembly/function-references/blob/main/proposals/function-references/Overview.md) support
ref.null func
drop
)
)
*/
const simpleWasmModule = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 95,
1, 120, 0, 96, 0, 0, 3, 3, 2, 1, 1, 10,
14, 2, 6, 0, 6, 64, 25, 11, 11, 5, 0, 208,
112, 26, 11, 0, 45, 4, 110, 97, 109, 101, 1, 15,
2, 0, 5, 102, 117, 110, 99, 48, 1, 5, 102, 117,
110, 99, 49, 4, 8, 1, 0, 5, 116, 121, 112, 101,
48, 10, 11, 1, 0, 1, 0, 6, 102, 105, 101, 108,
100, 48
])

const hasSupportOfAllRequiredWasmFeatures = () =>
typeof WebAssembly !== "undefined" &&
typeof WebAssembly?.validate === "function" &&
WebAssembly.validate(simpleWasmModule)

const createScript = (src) => {
const script = document.createElement("script")
Expand All @@ -166,13 +187,7 @@
return script
}

if (
typeof WebAssembly !== "undefined" &&
typeof WebAssembly?.validate === "function" &&
hasWasmGcSupport() &&
hasWasmExceptionSupport() &&
hasWasmReferenceTypeSupport()
) {
if (hasSupportOfAllRequiredWasmFeatures()) {
body.appendChild(createScript("kotlin-app-wasm-js.js"))
} else {
body.appendChild(createScript("skiko.js"))
Expand Down

0 comments on commit 978c9ef

Please sign in to comment.