1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00

LibJS+LibWeb: Let JS::Script::parse() return a list of errors (on error)

These are really supposed to be a list of SyntaxError objects, but for
now we simply return all the Parser::Error objects we got from Parser.
This commit is contained in:
Andreas Kling 2021-09-14 20:56:57 +02:00
parent 5fa02b8a9e
commit 10c489713d
3 changed files with 17 additions and 8 deletions

View file

@ -13,7 +13,7 @@
namespace JS {
// 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script
NonnullRefPtr<Script> Script::parse(StringView source_text, Realm& realm, StringView filename)
Result<NonnullRefPtr<Script>, Vector<Parser::Error>> Script::parse(StringView source_text, Realm& realm, StringView filename)
{
auto timer = Core::ElapsedTimer::start_new();
ScopeGuard timer_guard([&] {
@ -21,9 +21,12 @@ NonnullRefPtr<Script> Script::parse(StringView source_text, Realm& realm, String
});
// 1. Let body be ParseText(sourceText, Script).
auto body = Parser(Lexer(source_text, filename)).parse_program();
auto parser = Parser(Lexer(source_text, filename));
auto body = parser.parse_program();
// FIXME: 2. If body is a List of errors, return body.
// 2. If body is a List of errors, return body.
if (parser.has_errors())
return parser.errors();
// 3. Return Script Record { [[Realm]]: realm, [[ECMAScriptCode]]: body, [[HostDefined]]: hostDefined }.
return adopt_ref(*new Script(realm, move(body)));