Skip to content

Commit fa44fd5

Browse files
committed
LibJS: Remove ParserState::lookahead_lexer
The lookahead lexer used by next_token() no longer needs to be kept alive, since tokens created by Parser::next_token() now have any string views guaranteed safe by the fact that they point into the one true SourceCode provided by whoever set up the lexer.
1 parent 0dacc94 commit fa44fd5

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

Libraries/LibJS/Parser.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,10 +4291,8 @@ bool Parser::match_declaration(AllowUsingDeclaration allow_using) const
42914291

42924292
Token Parser::next_token() const
42934293
{
4294-
// We need to keep the lookahead lexer alive to prevent UAF on the lookahead token, as the token may hold a view
4295-
// into a short string stored on the stack.
4296-
m_state.lookahead_lexer = m_state.lexer;
4297-
return m_state.lookahead_lexer->next();
4294+
auto lookahead_lexer = m_state.lexer;
4295+
return lookahead_lexer.next();
42984296
}
42994297

43004298
bool Parser::try_match_let_declaration() const

Libraries/LibJS/Parser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ class JS_API Parser {
288288

289289
struct ParserState {
290290
Lexer lexer;
291-
mutable Optional<Lexer> lookahead_lexer;
292291
[[nodiscard]] Token const& current_token() const { return lexer.current_token(); }
293292
bool previous_token_was_period { false };
294293
Vector<ParserError> errors;

0 commit comments

Comments
 (0)