Issue #2486 - Part 4: Ensure layer statement rule is appended and invalid tokens are restored

This commit is contained in:
FranklinDM 2024-07-15 08:32:49 +08:00 • committed by roytam1
commit 2fc2056be7

View file

@ -4947,6 +4947,7 @@ bool
CSSParserImpl::ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData) CSSParserImpl::ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData)
{ {
nsString layerName; nsString layerName;
nsTArray<nsString>* nameList = new nsTArray<nsString>();
uint32_t linenum, colnum; uint32_t linenum, colnum;
if (!GetNextTokenLocation(true, &linenum, &colnum)) { if (!GetNextTokenLocation(true, &linenum, &colnum)) {
@ -4960,8 +4961,8 @@ CSSParserImpl::ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData)
// Parse the layer name or name list if we aren't immediately // Parse the layer name or name list if we aren't immediately
// followed by a "{", which indicates an anonymous layer. // followed by a "{", which indicates an anonymous layer.
bool isStatement = false;
if (tk->mType == eCSSToken_Ident) { if (tk->mType == eCSSToken_Ident) {
nsTArray<nsString>* nameList = new nsTArray<nsString>();
nameList->AppendElement(tk->mIdent); nameList->AppendElement(tk->mIdent);
bool parsing = true; bool parsing = true;
@ -4975,27 +4976,29 @@ CSSParserImpl::ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData)
case eCSSToken_Symbol: { case eCSSToken_Symbol: {
if (',' == tk->mSymbol) { if (',' == tk->mSymbol) {
if (expectIdent) { if (expectIdent) {
return false; parsing = false;
break;
} }
expectIdent = true; expectIdent = true;
continue; continue;
} else if (';' == tk->mSymbol) { } else if (';' == tk->mSymbol) {
if (expectIdent) { if (expectIdent) {
return false; parsing = false;
break;
} }
RefPtr<CSSLayerStatementRule> rule = isStatement = true;
new CSSLayerStatementRule(*nameList, linenum, colnum); parsing = false;
return true; break;
} else if ('{' == tk->mSymbol) { } else if ('{' == tk->mSymbol) {
if (expectIdent) { if (expectIdent) {
return false; parsing = false;
break;
} }
uint32_t nameListLength = nameList->Length(); uint32_t nameListLength = nameList->Length();
if (nameListLength == 0 || nameListLength > 1) { if (nameListLength == 0 || nameListLength > 1) {
return false; return false;
} }
layerName.Assign(nameList->ElementAt(0)); layerName.Assign(nameList->ElementAt(0));
UngetToken();
parsing = false; parsing = false;
break; break;
} }
@ -5010,10 +5013,23 @@ CSSParserImpl::ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData)
} }
} }
} }
if (expectIdent) {
UngetToken();
return false;
}
} else if (tk->mType == eCSSToken_Symbol && '{' != tk->mSymbol) { } else if (tk->mType == eCSSToken_Symbol && '{' != tk->mSymbol) {
return false; return false;
} }
if (isStatement) {
RefPtr<CSSLayerStatementRule> rule =
new CSSLayerStatementRule(*nameList, linenum, colnum);
(*aAppendFunc)(rule, aProcessData);
return true;
}
UngetToken();
RefPtr<css::GroupRule> rule = RefPtr<css::GroupRule> rule =
new CSSLayerBlockRule(layerName, linenum, colnum); new CSSLayerBlockRule(layerName, linenum, colnum);
return ParseGroupRule(rule, aAppendFunc, aProcessData); return ParseGroupRule(rule, aAppendFunc, aProcessData);