Bug 773296 - Part 24: Recognize variables in CSS.supports("var-blah", "whatever") calls. r=dbaron

This commit is contained in:
Cameron McCormack 2013-12-12 13:09:46 +11:00
parent 44dcde583f
commit 57f7c4a4c8

View File

@ -1561,14 +1561,27 @@ CSSParserImpl::EvaluateSupportsDeclaration(const nsAString& aProperty,
InitScanner(scanner, reporter, aDocURL, aBaseURL, aDocPrincipal); InitScanner(scanner, reporter, aDocURL, aBaseURL, aDocPrincipal);
nsAutoSuppressErrors suppressErrors(this); nsAutoSuppressErrors suppressErrors(this);
bool parsedOK = ParseProperty(propID) && !GetToken(true); bool parsedOK;
if (propID == eCSSPropertyExtra_variable) {
MOZ_ASSERT(Substring(aProperty,
0, VAR_PREFIX_LENGTH).EqualsLiteral("var-"));
const nsDependentSubstring varName =
Substring(aProperty, VAR_PREFIX_LENGTH); // remove 'var-'
CSSVariableDeclarations::Type variableType;
nsString variableValue;
parsedOK = ParseVariableDeclaration(&variableType, variableValue) &&
!GetToken(true);
} else {
parsedOK = ParseProperty(propID) && !GetToken(true);
mTempData.ClearProperty(propID);
mTempData.AssertInitialState();
}
CLEAR_ERROR(); CLEAR_ERROR();
ReleaseScanner(); ReleaseScanner();
mTempData.ClearProperty(propID);
mTempData.AssertInitialState();
return parsedOK; return parsedOK;
} }
@ -12341,25 +12354,32 @@ CSSParserImpl::ParseVariableDeclaration(CSSVariableDeclarations::Type* aType,
nsString impliedCharacters; nsString impliedCharacters;
// Record the token stream while parsing a variable value. // Record the token stream while parsing a variable value.
mScanner->StartRecording(); if (!mInSupportsCondition) {
mScanner->StartRecording();
}
if (!ParseValueWithVariables(&type, &dropBackslash, impliedCharacters, if (!ParseValueWithVariables(&type, &dropBackslash, impliedCharacters,
nullptr, nullptr)) { nullptr, nullptr)) {
mScanner->StopRecording(); if (!mInSupportsCondition) {
mScanner->StopRecording();
}
return false; return false;
} }
if (type == CSSVariableDeclarations::eTokenStream) { if (!mInSupportsCondition) {
// This was indeed a token stream value, so store it in variableValue. if (type == CSSVariableDeclarations::eTokenStream) {
mScanner->StopRecording(variableValue); // This was indeed a token stream value, so store it in variableValue.
if (dropBackslash) { mScanner->StopRecording(variableValue);
MOZ_ASSERT(!variableValue.IsEmpty() && if (dropBackslash) {
variableValue[variableValue.Length() - 1] == '\\'); MOZ_ASSERT(!variableValue.IsEmpty() &&
variableValue.Truncate(variableValue.Length() - 1); variableValue[variableValue.Length() - 1] == '\\');
variableValue.Truncate(variableValue.Length() - 1);
}
variableValue.Append(impliedCharacters);
} else {
// This was either 'inherit' or 'initial'; we don't need the recorded
// input.
mScanner->StopRecording();
} }
variableValue.Append(impliedCharacters);
} else {
// This was either 'inherit' or 'initial'; we don't need the recorded input.
mScanner->StopRecording();
} }
if (mHavePushBack && type == CSSVariableDeclarations::eTokenStream) { if (mHavePushBack && type == CSSVariableDeclarations::eTokenStream) {
@ -12371,9 +12391,11 @@ CSSParserImpl::ParseVariableDeclaration(CSSVariableDeclarations::Type* aType,
mToken.IsSymbol(';') || mToken.IsSymbol(';') ||
mToken.IsSymbol(']') || mToken.IsSymbol(']') ||
mToken.IsSymbol('}')); mToken.IsSymbol('}'));
MOZ_ASSERT(!variableValue.IsEmpty()); if (!mInSupportsCondition) {
MOZ_ASSERT(variableValue[variableValue.Length() - 1] == mToken.mSymbol); MOZ_ASSERT(!variableValue.IsEmpty());
variableValue.Truncate(variableValue.Length() - 1); MOZ_ASSERT(variableValue[variableValue.Length() - 1] == mToken.mSymbol);
variableValue.Truncate(variableValue.Length() - 1);
}
} }
*aType = type; *aType = type;