-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
44 lines (37 loc) · 1.2 KB
/
index.html
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
<!doctype html>
<!--
Copyright 2018 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<meta charset="utf-8">
<title>TinyGo WASM</title>
</head>
<body>
<!--
Add the following polyfill for Microsoft Edge 17/18 support:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/encoding.min.js"></script>
(see https://caniuse.com/#feat=textencoder)
-->
<!-- cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js ./tinygo_wasm_exec.js -->
<script src="tinygo_wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
;(async () => {
const go = new Go()
const moduleBytes = fetch("./tinygo.wasm");
const module = await WebAssembly.instantiateStreaming(moduleBytes, go.importObject);
go.run(module.instance)
console.log( 'add res: ', module.instance.exports.add(1, 2) )
console.log( 'Keccak256 res:', window['Keccak256']('hello world') )
})()
</script>
</body>
</html>