mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
Carry full source positions through the Rust bytecode source map so stack traces and other bytecode-backed source lookups can use them directly. This keeps exception-heavy paths from reconstructing line and column information through SourceCode::range_from_offsets(), which can spend a lot of time building SourceCode's position cache on first use. We're trading some space for time here, but I believe it's worth it at this tag, as this saves ~250ms of main thread time while loading https://x.com/ on my Linux machine. :^) Reading the stored Position out of the source map directly also exposed two things masked by the old range_from_offsets() path: a latent off-by-one in Lexer::new_at_offset() (its consume() bumped line_column past the character at offset; only synthesize_binding_pattern() hit it), and a (1,1) fallback in range_from_offsets() that fired whenever the queried range reached EOF. Fix the lexer, then rebaseline both the bytecode dump tests (no more spurious "1:1") and the destructuring AST tests (binding-pattern identifiers now report their real columns).
31 lines
714 B
C++
31 lines
714 B
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Types.h>
|
|
#include <LibJS/Export.h>
|
|
#include <LibJS/Position.h>
|
|
#include <LibJS/SourceCode.h>
|
|
|
|
namespace JS {
|
|
|
|
struct JS_API SourceRange {
|
|
[[nodiscard]] bool contains(Position const& position) const { return position.offset <= end.offset && position.offset >= start.offset; }
|
|
|
|
NonnullRefPtr<SourceCode const> code;
|
|
Position start;
|
|
Position end;
|
|
|
|
ByteString filename() const { return code->filename().to_byte_string(); }
|
|
};
|
|
|
|
}
|