File size: 3,553 Bytes
00df61d | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | /**
* @license
* Copyright 2019 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
class WasmSourceMap {
mapping = {};
offsets = [];
constructor(sourceMap) {
this.version = sourceMap.version;
this.sources = sourceMap.sources;
this.names = sourceMap.names;
var vlqMap = {};
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split('').forEach((c, i) => vlqMap[c] = i);
// based on https://github.com/Rich-Harris/vlq/blob/master/src/vlq.ts
function decodeVLQ(string) {
var result = [];
var shift = 0;
var value = 0;
for (var ch of string) {
var integer = vlqMap[ch];
if (integer === undefined) {
throw new Error(`Invalid character (${ch})`);
}
value += (integer & 31) << shift;
if (integer & 32) {
shift += 5;
} else {
var negate = value & 1;
value >>= 1;
result.push(negate ? -value : value);
value = shift = 0;
}
}
return result;
}
var offset = 0, src = 0, line = 1, col = 1, name = 0;
for (const [index, segment] of sourceMap.mappings.split(',').entries()) {
if (!segment) continue;
var data = decodeVLQ(segment);
var info = {};
offset += data[0];
if (data.length >= 2) info.source = src += data[1];
if (data.length >= 3) info.line = line += data[2];
if (data.length >= 4) info.column = col += data[3];
if (data.length >= 5) info.name = name += data[4];
this.mapping[offset] = info;
this.offsets.push(offset);
}
this.offsets.sort((a, b) => a - b);
}
lookup(offset) {
var normalized = this.normalizeOffset(offset);
var info = this.mapping[normalized];
if (!info) {
return null;
}
return {
file: this.sources[info.source],
line: info.line,
column: info.column,
name: this.names[info.name],
};
}
normalizeOffset(offset) {
var lo = 0;
var hi = this.offsets.length;
var mid;
while (lo < hi) {
mid = Math.floor((lo + hi) / 2);
if (this.offsets[mid] > offset) {
hi = mid;
} else {
lo = mid + 1;
}
}
return this.offsets[lo - 1];
}
}
var wasmSourceMap;
#if MINIMAL_RUNTIME
var wasmSourceMapFile = '{{{ WASM_BINARY_FILE }}}.map';
#else
var wasmSourceMapFile = locateFile('{{{ WASM_BINARY_FILE }}}.map');
#endif
function receiveSourceMapJSON(sourceMap) {
wasmSourceMap = new WasmSourceMap(sourceMap);
}
function getSourceMap() {
var buf = readBinary(wasmSourceMapFile);
return JSON.parse(UTF8ArrayToString(buf));
}
async function getSourceMapAsync() {
if (ENVIRONMENT_IS_WEB
#if ENVIRONMENT_MAY_BE_WORKER
|| ENVIRONMENT_IS_WORKER
#endif
) {
try {
var response = await fetch(wasmSourceMapFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}});
return response.json();
} catch {
// Fall back to getSourceMap below
}
}
return getSourceMap();
}
#if PTHREADS || WASM_WORKERS
// Source map is received via postMessage on worker threads.
if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) {
#endif
#if !MINIMAL_RUNTIME // MINIMAL_RUNTIME integrates source map loading into postamble_minimal.js
#if WASM_ASYNC_COMPILATION
addRunDependency('source-map');
getSourceMapAsync().then((json) => {
receiveSourceMapJSON(json);
removeRunDependency('source-map');
});
#else
receiveSourceMapJSON(getSourceMap());
#endif
#endif
#if PTHREADS || WASM_WORKERS
}
#endif
|