-
Notifications
You must be signed in to change notification settings - Fork 15
/
example.js
40 lines (37 loc) · 1.05 KB
/
example.js
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
var initialTitle = document.title;
var maxDep = 0;
var Module = {
arguments: ['build/example'],
preRun: [],
postRun: [],
print: function(text) {
console.log(text);
},
printErr: function(text) {
console.error(text);
},
setStatus: function(text) {
document.title = initialTitle + (text ? ' - ' + text : '');
},
monitorRunDependencies: function(remaining) {
maxDep = Math.max(maxDep, remaining);
Module.setStatus(remaining ? '' + (maxDep - remaining) + '/' + maxDep + ')' : '');
}
};
Module.setStatus('Downloading...');
window.onerror = function(event) {
Module.setStatus('Exception thrown, see JavaScript console');
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
var xhr = new XMLHttpRequest();
xhr.open('GET', 'ocamlrun.wasm', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
Module.wasmBinary = xhr.response;
var script = document.createElement('script');
script.src = 'ocamlrun.js';
document.body.appendChild(script);
};
xhr.send(null);