From bc701658f881d4546c5478db9b5b90e1af486640 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 4 Oct 2020 14:53:15 +0100 Subject: [PATCH] LibJS: Use String::formatted() for parser error messages --- Libraries/LibJS/Parser.cpp | 14 +++++++------- Libraries/LibJS/Parser.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 7383277f3f..834a42b8bf 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -658,7 +658,7 @@ NonnullRefPtr Parser::parse_unary_prefixed_expression() // FIXME: Apparently for functions this should also not be enforced on a parser level, // other engines throw ReferenceError for ++foo() if (!rhs->is_identifier() && !rhs->is_member_expression()) - syntax_error(String::format("Right-hand side of prefix increment operator must be identifier or member expression, got %s", rhs->class_name()), rhs_start_line, rhs_start_column); + syntax_error(String::formatted("Right-hand side of prefix increment operator must be identifier or member expression, got {}", rhs->class_name()), rhs_start_line, rhs_start_column); return create_ast_node(UpdateOp::Increment, move(rhs), true); } case TokenType::MinusMinus: { @@ -669,7 +669,7 @@ NonnullRefPtr Parser::parse_unary_prefixed_expression() // FIXME: Apparently for functions this should also not be enforced on a parser level, // other engines throw ReferenceError for --foo() if (!rhs->is_identifier() && !rhs->is_member_expression()) - syntax_error(String::format("Right-hand side of prefix decrement operator must be identifier or member expression, got %s", rhs->class_name()), rhs_start_line, rhs_start_column); + syntax_error(String::formatted("Right-hand side of prefix decrement operator must be identifier or member expression, got {}", rhs->class_name()), rhs_start_line, rhs_start_column); return create_ast_node(UpdateOp::Decrement, move(rhs), true); } case TokenType::ExclamationMark: @@ -856,7 +856,7 @@ NonnullRefPtr Parser::parse_string_literal(Token token) String message; if (status == Token::StringValueStatus::MalformedHexEscape || status == Token::StringValueStatus::MalformedUnicodeEscape) { auto type = status == Token::StringValueStatus::MalformedUnicodeEscape ? "unicode" : "hexadecimal"; - message = String::format("Malformed %s escape sequence", type); + message = String::formatted("Malformed {} escape sequence", type); } else if (status == Token::StringValueStatus::UnicodeEscapeOverflow) { message = "Unicode code_point must not be greater than 0x10ffff in escape sequence"; } @@ -1084,7 +1084,7 @@ NonnullRefPtr Parser::parse_secondary_expression(NonnullRefPtr(*lhs).string(); if (name == "eval" || name == "arguments") { syntax_error( - String::format("'%s' cannot be assigned to in strict mode code", name.characters()), + String::formatted("'{}' cannot be assigned to in strict mode code", name), m_parser_state.m_current_token.line_number(), m_parser_state.m_current_token.line_column()); } @@ -1105,14 +1105,14 @@ NonnullRefPtr Parser::parse_secondary_expression(NonnullRefPtris_identifier() && !lhs->is_member_expression()) - syntax_error(String::format("Left-hand side of postfix increment operator must be identifier or member expression, got %s", lhs->class_name())); + syntax_error(String::formatted("Left-hand side of postfix increment operator must be identifier or member expression, got {}", lhs->class_name())); consume(); return create_ast_node(UpdateOp::Increment, move(lhs)); case TokenType::MinusMinus: // FIXME: Apparently for functions this should also not be enforced on a parser level, // other engines throw ReferenceError for foo()-- if (!lhs->is_identifier() && !lhs->is_member_expression()) - syntax_error(String::format("Left-hand side of postfix increment operator must be identifier or member expression, got %s", lhs->class_name())); + syntax_error(String::formatted("Left-hand side of postfix increment operator must be identifier or member expression, got {}", lhs->class_name())); consume(); return create_ast_node(UpdateOp::Decrement, move(lhs)); case TokenType::DoubleAmpersand: @@ -1790,7 +1790,7 @@ Token Parser::consume(TokenType expected_type) void Parser::expected(const char* what) { - syntax_error(String::format("Unexpected token %s. Expected %s", m_parser_state.m_current_token.name(), what)); + syntax_error(String::formatted("Unexpected token {}. Expected {}", m_parser_state.m_current_token.name(), what)); } void Parser::syntax_error(const String& message, size_t line, size_t column) diff --git a/Libraries/LibJS/Parser.h b/Libraries/LibJS/Parser.h index e3ee817c64..d5e113e677 100644 --- a/Libraries/LibJS/Parser.h +++ b/Libraries/LibJS/Parser.h @@ -94,7 +94,7 @@ public: { if (line == 0 || column == 0) return message; - return String::format("%s (line: %zu, column: %zu)", message.characters(), line, column); + return String::formatted("{} (line: {}, column: {})", message, line, column); } String source_location_hint(const StringView& source, const char spacer = ' ', const char indicator = '^') const