LibJS: Make sure private identifier is valid in optional chain

If we don't check that a private identifier is valid this can break the
assumption that we have a private environment when evaluation the
private identifier. Also an unknown private identifier this should
be a SyntaxError.
This commit is contained in:
davidot 2022-11-17 10:24:20 +01:00 committed by Linus Groh
commit 16ac43c9d4
Notes: sideshowbarker 2024-07-17 04:24:22 +09:00
2 changed files with 38 additions and 0 deletions

View file

@ -3174,6 +3174,9 @@ NonnullRefPtr<OptionalChain> Parser::parse_optional_chain(NonnullRefPtr<Expressi
} else if (match(TokenType::Period)) {
consume();
if (match(TokenType::PrivateIdentifier)) {
if (!is_private_identifier_valid())
syntax_error(String::formatted("Reference to undeclared private field or method '{}'", m_state.current_token.value()));
auto start = position();
auto private_identifier = consume();
chain.append(OptionalChain::PrivateMemberReference {