LibJS: Have JS::Lexer take a JS::SourceCode as input

This moves the responsibility of setting up a SourceCode object to the
users of JS::Lexer.

This means Lexer and Parser are free to use string views into the
SourceCode internally while working.

It also means Lexer no longer has to think about anything other than
UTF-16 (or ASCII) inputs. So the unit test for parsing various invalid
UTF-8 sequences is deleted here.
This commit is contained in:
Andreas Kling 2025-11-08 21:21:52 +01:00 committed by Andreas Kling
parent 9ca25e55d7
commit 0dacc94edd
Notes: github-actions[bot] 2025-11-09 11:15:22 +00:00
16 changed files with 59 additions and 227 deletions

View file

@ -55,7 +55,8 @@ static JS::ThrowCompletionOr<JS::Value> execute_a_function_body(HTML::BrowsingCo
}})~~~",
body);
auto parser = JS::Parser { JS::Lexer { source_text } };
auto parser = JS::Parser(JS::Lexer(JS::SourceCode::create({}, Utf16String::from_utf8(source_text))));
;
auto function_expression = parser.parse_function_node<JS::FunctionExpression>();
// 4. If body is not parsable as a FunctionBody or if parsing detects an early error, return Completion { [[Type]]: normal, [[Value]]: null, [[Target]]: empty }.