Bug 950497 - Make self-referencing CSS variables invalid even if they have fallback. r=dbaron

This commit is contained in:
Cameron McCormack 2013-12-17 16:16:42 +11:00
parent 12910b47d0
commit ebb7bfe9b8
4 changed files with 25 additions and 1 deletions

View File

@ -99,6 +99,7 @@ default-preferences pref(layout.css.variables.enabled,true)
== variable-reference-36.html variable-reference-36-ref.html
== variable-reference-37.html variable-reference-37-ref.html
== variable-reference-38.html variable-reference-38-ref.html
== variable-reference-39.html support/color-green-ref.html
== variable-supports-01.html support/color-green-ref.html
== variable-supports-02.html support/color-green-ref.html
== variable-supports-03.html support/color-green-ref.html

View File

@ -0,0 +1,17 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<title>CSS Test: Test declaring a variable that references itself but uses fallback.</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au">
<link rel="help" href="http://dev.w3.org/csswg/css-variables/#cycles">
<link rel="match" href="support/color-green-ref.html">
<style>
p {
color: red;
var-a: var(a, red);
color: var(a, green);
}
</style>
<p>This text must be green.</p>

View File

@ -193,6 +193,12 @@ CSSVariableResolver::Resolve(const CSSVariableValues* aInherited,
mReferences[id].AppendElement(i);
}
}
// If a variable references itself, it is invalid. (RemoveCycles
// does not check for cycles consisting of a single variable, so we
// check here.)
if (data.HasReferenceToVariable(id)) {
mVariables[id].mValue.Truncate();
}
// Also record whether it referenced any variables that don't exist
// in the resolver, so that we can ensure we still resolve its value
// in ResolveVariable, even though its mReferences list is empty.

View File

@ -25,7 +25,7 @@ var values = [
["var-a: var(b)", "var-a", ""],
["var-a: var(b); var-b: 1px", "var-a", " 1px"],
["var-a: var(b, 1px)", "var-a", " 1px"],
["var-a: var(a, 1px)", "var-a", " 1px"],
["var-a: var(a, 1px)", "var-a", ""],
["var-a: something 3px url(whereever) calc(var(a) + 1px)", "var-a", ""],
["var-a: something 3px url(whereever) calc(var(b,1em) + 1px)", "var-a", " something 3px url(whereever) calc(1em + 1px)"],
["var-a: var(b, var(c, var(d, Black)))", "var-a", " Black"],