Skip to content

Commit 07b1574

Browse files
committed
Do not use source map beyond function boundaries
1 parent c45f5f4 commit 07b1574

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/source_map_support.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ function WasmSourceMap(sourceMap) {
5555
}
5656

5757
WasmSourceMap.prototype.lookup = function (offset) {
58-
var info = this.mapping[this.normalizeOffset(offset)];
58+
var normalized = this.normalizeOffset(offset);
59+
#if 'emscripten_generate_pc' in addedLibraryItems
60+
if (!wasmOffsetConverter.isSameFunc(offset, normalized))
61+
return null;
62+
#endif
63+
var info = this.mapping[normalized];
5964
if (!info)
6065
return null;
6166
return {

src/wasm_offset_converter.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function WasmOffsetConverter(wasmBytes) {
1313
var idx = 0;
1414

1515
this.map = {};
16+
this.func_starts = [];
1617

1718
function unsignedLEB128() {
1819
var result = 0;
@@ -69,6 +70,7 @@ function WasmOffsetConverter(wasmBytes) {
6970
while (count --> 0) {
7071
var size = unsignedLEB128();
7172
this.map[idx++] = offset;
73+
this.func_starts.push(offset);
7274
offset += size;
7375
}
7476
return;
@@ -80,3 +82,23 @@ function WasmOffsetConverter(wasmBytes) {
8082
WasmOffsetConverter.prototype.convert = function (funcidx, offset) {
8183
return this.map[funcidx] + offset;
8284
}
85+
86+
WasmOffsetConverter.prototype.isSameFunc = function (offset1, offset2) {
87+
var array = this.func_starts;
88+
function bisect(offset) {
89+
var lo = 0;
90+
var hi = array.length;
91+
var mid;
92+
93+
while (lo < hi) {
94+
mid = Math.floor((lo + hi) / 2);
95+
if (array[mid] > offset) {
96+
hi = mid;
97+
} else {
98+
lo = mid + 1;
99+
}
100+
}
101+
return lo;
102+
}
103+
return bisect(offset1) == bisect(offset2);
104+
}

0 commit comments

Comments
 (0)