mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibJS: Add to_string definitions to CodeGenerationError and ParserError
This commit is contained in:
parent
f7458b3e17
commit
93ad25fbe5
Notes:
sideshowbarker
2024-07-17 06:46:15 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/93ad25fbe5 Pull-request: https://github.com/SerenityOS/serenity/pull/17494 Reviewed-by: https://github.com/linusg ✅
5 changed files with 30 additions and 0 deletions
17
Userland/Libraries/LibJS/Bytecode/CodeGenerationError.cpp
Normal file
17
Userland/Libraries/LibJS/Bytecode/CodeGenerationError.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Bytecode/CodeGenerationError.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
ErrorOr<String> CodeGenerationError::to_string() const
|
||||
{
|
||||
return String::formatted("CodeGenerationError in {}: {}", failing_node ? failing_node->class_name() : "<unknown node>", reason_literal);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
||||
|
@ -16,6 +17,7 @@ struct CodeGenerationError {
|
|||
ASTNode const* failing_node { nullptr };
|
||||
StringView reason_literal;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
DeprecatedString to_deprecated_string();
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ set(SOURCES
|
|||
AST.cpp
|
||||
Bytecode/ASTCodegen.cpp
|
||||
Bytecode/BasicBlock.cpp
|
||||
Bytecode/CodeGenerationError.cpp
|
||||
Bytecode/Executable.cpp
|
||||
Bytecode/Generator.cpp
|
||||
Bytecode/IdentifierTable.cpp
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
ErrorOr<String> ParserError::to_string() const
|
||||
{
|
||||
if (!position.has_value())
|
||||
return String::from_deprecated_string(message);
|
||||
return String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column);
|
||||
}
|
||||
|
||||
DeprecatedString ParserError::to_deprecated_string() const
|
||||
{
|
||||
if (!position.has_value())
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/SourceRange.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -17,6 +19,7 @@ struct ParserError {
|
|||
DeprecatedString message;
|
||||
Optional<Position> position;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
DeprecatedString source_location_hint(StringView source, char const spacer = ' ', char const indicator = '^') const;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue