Commit 827de05c authored by Huáng Jùnliàng's avatar Huáng Jùnliàng Committed by Commit Bot

[class] Throw syntax error on deleting optional private property

Bug: v8:10564
Change-Id: Ibeaa43d9db087d02d8f4d3688fc1f6da41691a60
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2216931Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68373}
parent b6a4f494
......@@ -541,10 +541,14 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return property != nullptr && property->obj()->IsThisExpression();
}
// Returns true if the expression is of type "obj.#foo".
// Returns true if the expression is of type "obj.#foo" or "obj?.#foo".
V8_INLINE static bool IsPrivateReference(Expression* expression) {
DCHECK_NOT_NULL(expression);
Property* property = expression->AsProperty();
if (expression->IsOptionalChain()) {
Expression* expr_inner = expression->AsOptionalChain()->expression();
property = expr_inner->AsProperty();
}
return property != nullptr && property->IsPrivateReference();
}
......
......@@ -575,6 +575,10 @@ class PreParserFactory {
}
PreParserExpression NewOptionalChain(const PreParserExpression& expr) {
// Needed to track `delete a?.#b` early errors
if (expr.IsPrivateReference()) {
return PreParserExpression::PrivateReference();
}
return PreParserExpression::Default();
}
......
......@@ -6225,10 +6225,22 @@ TEST(PrivateClassFieldsErrors) {
"foo() { delete this.x.#a }",
"foo() { delete this.x().#a }",
"foo() { delete this?.#a }",
"foo() { delete this.x?.#a }",
"foo() { delete this?.x.#a }",
"foo() { delete this.x()?.#a }",
"foo() { delete this?.x().#a }",
"foo() { delete f.#a }",
"foo() { delete f.x.#a }",
"foo() { delete f.x().#a }",
"foo() { delete f?.#a }",
"foo() { delete f.x?.#a }",
"foo() { delete f?.x.#a }",
"foo() { delete f.x()?.#a }",
"foo() { delete f?.x().#a }",
// ASI requires a linebreak
"#a b",
"#a = 0 b",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment