mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-06-27 19:51:03 +00:00
LibJS: Deduplicate adjacent source map entries during codegen
Avoid emitting consecutive source map entries when they carry the same source range. The bytecode offset for the previous entry remains valid for later PCs because source lookup now uses the largest source map entry whose offset is not greater than the program counter. This keeps stack traces stable while allowing statement-sized runs of bytecode to share one source map entry.
This commit is contained in:
parent
e926e86f8d
commit
b6ac36c200
Notes:
github-actions[bot]
2026-05-14 07:42:09 +00:00
Author: https://github.com/awesomekling
Commit: b6ac36c200
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/9395
3 changed files with 80 additions and 48 deletions
|
|
@ -405,19 +405,24 @@ Optional<SourceRange> Executable::source_range_at(size_t offset) const
|
|||
{
|
||||
if (offset >= bytecode.size())
|
||||
return {};
|
||||
auto* entry = binary_search(source_map, offset, nullptr, [](size_t needle, SourceMapEntry const& entry) -> int {
|
||||
if (needle < entry.bytecode_offset)
|
||||
return -1;
|
||||
if (needle > entry.bytecode_offset)
|
||||
return 1;
|
||||
return 0;
|
||||
});
|
||||
if (!entry)
|
||||
if (source_map.is_empty())
|
||||
return {};
|
||||
size_t low = 0;
|
||||
size_t high = source_map.size();
|
||||
while (low < high) {
|
||||
auto middle = low + (high - low) / 2;
|
||||
if (source_map[middle].bytecode_offset <= offset)
|
||||
low = middle + 1;
|
||||
else
|
||||
high = middle;
|
||||
}
|
||||
if (low == 0)
|
||||
return {};
|
||||
auto& entry = source_map[low - 1];
|
||||
return SourceRange {
|
||||
.code = source_code,
|
||||
.start = entry->source_record.start,
|
||||
.end = entry->source_record.end,
|
||||
.start = entry.source_record.start,
|
||||
.end = entry.source_record.end,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue