| 
									
										
										
										
											2018-03-04 13:53:50 +01:00
										 |  |  | <!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>Go wasm</title> | 
					
						
							|  |  |  | </head> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body> | 
					
						
							| 
									
										
										
										
											2018-10-02 19:11:14 +02:00
										 |  |  | 	<!--
 | 
					
						
							|  |  |  | 	Add the following polyfill for Microsoft Edge 17/18 support: | 
					
						
							|  |  |  | 	<script src="https://cdn.jsdelivr.net/npm/text-encoding@0.7.0/lib/encoding.min.js"></script> | 
					
						
							|  |  |  | 	(see https://caniuse.com/#feat=textencoder) | 
					
						
							|  |  |  | 	--> | 
					
						
							| 
									
										
										
										
											2018-03-04 13:53:50 +01:00
										 |  |  | 	<script src="wasm_exec.js"></script> | 
					
						
							|  |  |  | 	<script> | 
					
						
							| 
									
										
										
										
											2018-05-17 12:33:01 +02:00
										 |  |  | 		if (!WebAssembly.instantiateStreaming) { // polyfill | 
					
						
							|  |  |  | 			WebAssembly.instantiateStreaming = async (resp, importObject) => { | 
					
						
							|  |  |  | 				const source = await (await resp).arrayBuffer(); | 
					
						
							|  |  |  | 				return await WebAssembly.instantiate(source, importObject); | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2018-03-04 13:53:50 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 12:33:01 +02:00
										 |  |  | 		const go = new Go(); | 
					
						
							|  |  |  | 		let mod, inst; | 
					
						
							|  |  |  | 		WebAssembly.instantiateStreaming(fetch("test.wasm"), go.importObject).then((result) => { | 
					
						
							|  |  |  | 			mod = result.module; | 
					
						
							|  |  |  | 			inst = result.instance; | 
					
						
							|  |  |  | 			document.getElementById("runButton").disabled = false; | 
					
						
							| 
									
										
										
										
											2018-09-03 12:02:25 +05:30
										 |  |  | 		}).catch((err) => { | 
					
						
							|  |  |  | 			console.error(err); | 
					
						
							| 
									
										
										
										
											2018-05-17 12:33:01 +02:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		async function run() { | 
					
						
							|  |  |  | 			console.clear(); | 
					
						
							|  |  |  | 			await go.run(inst); | 
					
						
							|  |  |  | 			inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-04 13:53:50 +01:00
										 |  |  | 	</script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 12:33:01 +02:00
										 |  |  | 	<button onClick="run();" id="runButton" disabled>Run</button> | 
					
						
							| 
									
										
										
										
											2018-03-04 13:53:50 +01:00
										 |  |  | </body> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 12:33:01 +02:00
										 |  |  | </html> |