forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc-wasm-sourcemaps.html
More file actions
60 lines (54 loc) · 1.75 KB
/
Copy pathdoc-wasm-sourcemaps.html
File metadata and controls
60 lines (54 loc) · 1.75 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Wasm+sourcemaps</title>
<script src="wasm-sourcemaps/utils.js"></script>
<script>
function test() {
// Create memory and populate int32 array with some data.
var buf = Module._malloc(16);
var arr = new Int32Array(Module['buffer'], buf, 4);
arr.set(new Int32Array([1, 2, 3, 4]));
var average = Module.ccall(
'average',
'i32',
['*', 'u32'],
[buf, arr.length]
);
console.log(average);
}
// WebAssembly module is part of the emscripten generated one,
// loading emscripten module via script tag.
var Module = {
wasmBinary: null,
postRun: [],
};
function loadWasm(emscriptenWrapper, wasmUrl, sourceMapUrl) {
return fetch(wasmUrl).then(res => res.arrayBuffer()).then(buffer => {
if (!sourceMapUrl) return buffer;
return updateSourceMappingURLSection(buffer, sourceMapUrl);
}).then(buffer => {
return new Promise(resolve => {
Module.wasmBinary = buffer;
Module.postRun.push(resolve);
let script = document.createElement('script');
script.src = emscriptenWrapper;
document.head.appendChild(script);
});
});
}
loadWasm('wasm-sourcemaps/average.js',
'wasm-sourcemaps/average.wasm',
new URL('wasm-sourcemaps/average.wasm.map', document.location).href).then(() => {
debugger;
test();
});
</script>
</head>
<body>
</body>
</html>