Skip to content

Commit cd0e158

Browse files
committed
Use the WebAssembly API manually, to try to make it compatible with both browser and tests. Doesn't work for tests yet.
1 parent 0a92680 commit cd0e158

6 files changed

Lines changed: 108 additions & 7 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"common-tags": "^1.7.2",
4848
"copy-to-clipboard": "^3.0.8",
4949
"escape-string-regexp": "^1.0.5",
50-
"gecko-profiler-demangle": "^0.1.0",
5150
"jszip": "^3.1.5",
5251
"memoize-immutable": "^3.0.0",
5352
"mixedtuplemap": "^1.0.0",
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import wasm_path from 'file-loader!./gecko_profiler_demangle_bg.wasmpleaseignoremewebpack';
2+
3+
// The code below was generated using `wasm-bindgen --no-modules`, except for
4+
// the export statement at the very end which I added manually, and except for
5+
// the fact that the init() function now no longer takes a parameter and instead
6+
// uses the wasm_path variable that I'm declaring at the top.
7+
8+
(function() {
9+
var wasm;
10+
const __exports = {};
11+
12+
13+
let cachedEncoder = new TextEncoder('utf-8');
14+
15+
let cachegetUint8Memory = null;
16+
function getUint8Memory() {
17+
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
18+
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
19+
}
20+
return cachegetUint8Memory;
21+
}
22+
23+
function passStringToWasm(arg) {
24+
25+
const buf = cachedEncoder.encode(arg);
26+
const ptr = wasm.__wbindgen_malloc(buf.length);
27+
getUint8Memory().set(buf, ptr);
28+
return [ptr, buf.length];
29+
}
30+
31+
let cachedDecoder = new TextDecoder('utf-8');
32+
33+
function getStringFromWasm(ptr, len) {
34+
return cachedDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
35+
}
36+
37+
let cachedGlobalArgumentPtr = null;
38+
function globalArgumentPtr() {
39+
if (cachedGlobalArgumentPtr === null) {
40+
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
41+
}
42+
return cachedGlobalArgumentPtr;
43+
}
44+
45+
let cachegetUint32Memory = null;
46+
function getUint32Memory() {
47+
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
48+
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
49+
}
50+
return cachegetUint32Memory;
51+
}
52+
/**
53+
* Takes an input string and runs it through a sequence of demanglers. Returns
54+
* the demangled string if a match was found, or the original string if not.
55+
* @param {string} arg0
56+
* @returns {string}
57+
*/
58+
__exports.demangle_any = function(arg0) {
59+
const [ptr0, len0] = passStringToWasm(arg0);
60+
const retptr = globalArgumentPtr();
61+
try {
62+
wasm.demangle_any(retptr, ptr0, len0);
63+
const mem = getUint32Memory();
64+
const rustptr = mem[retptr / 4];
65+
const rustlen = mem[retptr / 4 + 1];
66+
67+
const realRet = getStringFromWasm(rustptr, rustlen).slice();
68+
wasm.__wbindgen_free(rustptr, rustlen * 1);
69+
return realRet;
70+
71+
72+
} finally {
73+
wasm.__wbindgen_free(ptr0, len0 * 1);
74+
75+
}
76+
77+
};
78+
79+
__exports.__wbindgen_throw = function(ptr, len) {
80+
throw new Error(getStringFromWasm(ptr, len));
81+
};
82+
83+
function init() {
84+
const fetchPromise = fetch(wasm_path);
85+
let resultPromise;
86+
if (typeof WebAssembly.instantiateStreaming === 'function') {
87+
resultPromise = WebAssembly.instantiateStreaming(fetchPromise, { './gecko_profiler_demangle': __exports });
88+
} else {
89+
resultPromise = fetchPromise
90+
.then(response => response.arrayBuffer())
91+
.then(buffer => WebAssembly.instantiate(buffer, { './gecko_profiler_demangle': __exports }));
92+
}
93+
return resultPromise.then(({instance}) => {
94+
wasm = init.wasm = instance.exports;
95+
return;
96+
});
97+
};
98+
self.wasm_bindgen = Object.assign(init, __exports);
99+
})();
100+
101+
export default wasm_bindgen;
Binary file not shown.

src/profile-logic/symbol-store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import SymbolStoreDB from './symbol-store-db';
77
import { SymbolsNotFoundError } from './errors';
88
import bisection from 'bisection';
99

10-
const demanglerModulePromise = import('gecko-profiler-demangle');
10+
import demanglerModule from './gecko_profiler_demangle';
11+
const demanglerModulePromise = demanglerModule();
1112

1213
import type { RequestedLib } from '../types/actions';
1314
import type { SymbolTableAsTuple } from './symbol-store-db';

webpack.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const config = {
1818
'redux-devtools': path.join(__dirname, '..', '..', 'src'),
1919
react: path.join(__dirname, 'node_modules', 'react'),
2020
},
21-
extensions: ['.js', '.wasm'],
21+
extensions: ['.js'],
2222
},
2323
devtool: 'source-map',
2424
module: {
@@ -52,6 +52,10 @@ const config = {
5252
test: /\.svg$/,
5353
loader: 'file-loader',
5454
},
55+
{
56+
test: /\.wasm$/,
57+
loader: 'file-loader',
58+
},
5559
],
5660
},
5761
node: {

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,10 +3916,6 @@ gauge@~2.7.3:
39163916
strip-ansi "^3.0.1"
39173917
wide-align "^1.1.0"
39183918

3919-
gecko-profiler-demangle@^0.1.0:
3920-
version "0.1.0"
3921-
resolved "https://registry.yarnpkg.com/gecko-profiler-demangle/-/gecko-profiler-demangle-0.1.0.tgz#7bc08d43e3572e64a6c09c4ed6680e4bc4ce356e"
3922-
39233919
get-caller-file@^1.0.1:
39243920
version "1.0.3"
39253921
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"

0 commit comments

Comments
 (0)