зеркало из https://github.com/mozilla/gecko-dev.git
Bug 673820 - Rewriting StringToInteger function to match behavior of Rules for parsing Integers specified in spec. r=jonas f=mounir,Ms2ger,dbaron
This commit is contained in:
Родитель
aa7afa50d1
Коммит
68c6dc4c1f
|
@ -1356,70 +1356,70 @@ nsAttrValue::StringToInteger(const nsAString& aValue, bool* aStrict,
|
||||||
bool aCanBePercent,
|
bool aCanBePercent,
|
||||||
bool* aIsPercent) const
|
bool* aIsPercent) const
|
||||||
{
|
{
|
||||||
*aStrict = PR_FALSE;
|
*aStrict = true;
|
||||||
*aErrorCode = NS_ERROR_ILLEGAL_VALUE;
|
*aErrorCode = NS_ERROR_ILLEGAL_VALUE;
|
||||||
if (aCanBePercent) {
|
if (aCanBePercent) {
|
||||||
*aIsPercent = PR_FALSE;
|
*aIsPercent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAString::const_iterator iter, end;
|
nsAString::const_iterator iter, end;
|
||||||
aValue.BeginReading(iter);
|
aValue.BeginReading(iter);
|
||||||
aValue.EndReading(end);
|
aValue.EndReading(end);
|
||||||
|
|
||||||
|
while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
|
||||||
|
*aStrict = false;
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iter == end) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool negate = false;
|
bool negate = false;
|
||||||
|
if (*iter == PRUnichar('-')) {
|
||||||
|
negate = true;
|
||||||
|
++iter;
|
||||||
|
} else if (*iter == PRUnichar('+')) {
|
||||||
|
*aStrict = false;
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
|
||||||
PRInt32 value = 0;
|
PRInt32 value = 0;
|
||||||
if (iter != end) {
|
PRInt32 pValue = 0; // Previous value, used to check integer overflow
|
||||||
if (*iter == PRUnichar('-')) {
|
while (iter != end) {
|
||||||
negate = PR_TRUE;
|
if (*iter >= PRUnichar('0') && *iter <= PRUnichar('9')) {
|
||||||
|
value = (value * 10) + (*iter - PRUnichar('0'));
|
||||||
++iter;
|
++iter;
|
||||||
}
|
// Checking for integer overflow.
|
||||||
if (iter != end) {
|
if (pValue > value) {
|
||||||
if ((*iter >= PRUnichar('1') || (*iter == PRUnichar('0') && !negate)) &&
|
*aStrict = false;
|
||||||
*iter <= PRUnichar('9')) {
|
*aErrorCode = NS_ERROR_ILLEGAL_VALUE;
|
||||||
value = *iter - PRUnichar('0');
|
break;
|
||||||
++iter;
|
} else {
|
||||||
*aStrict = (value != 0 || iter == end ||
|
pValue = value;
|
||||||
(aCanBePercent && *iter == PRUnichar('%')));
|
*aErrorCode = NS_OK;
|
||||||
while (iter != end && *aStrict) {
|
|
||||||
if (*iter >= PRUnichar('0') && *iter <= PRUnichar('9')) {
|
|
||||||
value = (value * 10) + (*iter - PRUnichar('0'));
|
|
||||||
++iter;
|
|
||||||
if (iter != end && value > ((PR_INT32_MAX / 10) - 9)) {
|
|
||||||
*aStrict = PR_FALSE;
|
|
||||||
}
|
|
||||||
} else if (aCanBePercent && *iter == PRUnichar('%')) {
|
|
||||||
++iter;
|
|
||||||
if (iter == end) {
|
|
||||||
*aIsPercent = PR_TRUE;
|
|
||||||
} else {
|
|
||||||
*aStrict = PR_FALSE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*aStrict = PR_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*aStrict) {
|
|
||||||
if (negate) {
|
|
||||||
value = -value;
|
|
||||||
}
|
|
||||||
if (!aCanBePercent || !*aIsPercent) {
|
|
||||||
*aErrorCode = NS_OK;
|
|
||||||
#ifdef DEBUG
|
|
||||||
nsAutoString stringValue;
|
|
||||||
stringValue.AppendInt(value);
|
|
||||||
if (aCanBePercent && *aIsPercent) {
|
|
||||||
stringValue.AppendLiteral("%");
|
|
||||||
}
|
|
||||||
NS_ASSERTION(stringValue.Equals(aValue), "Wrong conversion!");
|
|
||||||
#endif
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if (aCanBePercent && *iter == PRUnichar('%')) {
|
||||||
|
++iter;
|
||||||
|
*aIsPercent = true;
|
||||||
|
if (iter != end) {
|
||||||
|
*aStrict = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*aStrict = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (negate) {
|
||||||
|
value = -value;
|
||||||
|
// Checking the special case of -0.
|
||||||
|
if (!value) {
|
||||||
|
*aStrict = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString tmp(aValue);
|
return value;
|
||||||
return tmp.ToInteger(aErrorCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt64
|
PRInt64
|
||||||
|
|
|
@ -20190,7 +20190,7 @@ function test_size_attributes_parse_badsuffix() {
|
||||||
var canvas = document.getElementById('c637');
|
var canvas = document.getElementById('c637');
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
todo(canvas.width == 100, "canvas.width == 100");
|
is(canvas.width, 100, "canvas.width == 100");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20400,7 +20400,7 @@ var canvas = document.getElementById('c648');
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
canvas.setAttribute('width', '100foo');
|
canvas.setAttribute('width', '100foo');
|
||||||
todo(canvas.width == 100, "canvas.width == 100");
|
is(canvas.width, 100, "canvas.width == 100");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,11 +462,6 @@ function reflectBoolean(aParameters)
|
||||||
*/
|
*/
|
||||||
function reflectInt(aParameters)
|
function reflectInt(aParameters)
|
||||||
{
|
{
|
||||||
//TBD: Bug 673820: .setAttribute(exponential) -> incorrect reflection for element[attr]
|
|
||||||
function testExponential(value) {
|
|
||||||
return !!/^[ \t\n\f\r]*[\+\-]?[0-9]+e[0-9]+/.exec(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expected value returned by .getAttribute() when |value| has been previously passed to .setAttribute().
|
// Expected value returned by .getAttribute() when |value| has been previously passed to .setAttribute().
|
||||||
function expectedGetAttributeResult(value) {
|
function expectedGetAttributeResult(value) {
|
||||||
return (value !== null) ? String(value) : "";
|
return (value !== null) ? String(value) : "";
|
||||||
|
@ -556,34 +551,10 @@ function reflectInt(aParameters)
|
||||||
//TBD: Bug 586761: .setAttribute(attr, -2147483648) --> element[attr] == defaultValue instead of -2147483648
|
//TBD: Bug 586761: .setAttribute(attr, -2147483648) --> element[attr] == defaultValue instead of -2147483648
|
||||||
todo_is(element[attr], intValue, "Bug 586761: " + element.localName +
|
todo_is(element[attr], intValue, "Bug 586761: " + element.localName +
|
||||||
".setAttribute(value, " + v + "), " + element.localName + "[" + attr + "] ");
|
".setAttribute(value, " + v + "), " + element.localName + "[" + attr + "] ");
|
||||||
} else if (testExponential(v)) {
|
} else if ((v === "-0" || v == "-0xABCDEF") && nonNegative) {
|
||||||
//TBD: Bug 673820: .setAttribute(exponential) -> incorrect reflection for element[attr]
|
|
||||||
todo_is(element[attr], intValue, "Bug 673820: " + element.localName +
|
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
|
||||||
} else if (v == "why 567 what") {
|
|
||||||
//TBD: Bug 679672: .setAttribute() is somehow able to parse "why 567 what" into "567"
|
|
||||||
todo_is(element[attr], intValue, "Bug 679672: " + element.localName +
|
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
|
||||||
} else if (v === "-0" && nonNegative) {
|
|
||||||
//TBD: Bug 688093: Non-negative integers should return defaultValue when attempting to reflect "-0"
|
//TBD: Bug 688093: Non-negative integers should return defaultValue when attempting to reflect "-0"
|
||||||
todo_is(element[attr], intValue, "Bug 688093: " + element.localName +
|
todo_is(element[attr], intValue, "Bug 688093: " + element.localName +
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
||||||
} else if (v == "+42foo") {
|
|
||||||
//TBD: Bug: Unable to correctly parse "+" character in front of string
|
|
||||||
todo_is(element[attr], intValue, "Bug: " + element.localName +
|
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
|
||||||
} else if (v == "0x10FFFF" && defaultValue != 0) {
|
|
||||||
//TBD: Bug: Integer attributes should parse "0x10FFFF" as 0, but instead incorrectly return defaultValue
|
|
||||||
todo_is(element[attr], intValue, "Bug: " + element.localName +
|
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
|
||||||
} else if (v == "-0xABCDEF" && !nonNegative && defaultValue != 0) {
|
|
||||||
//TBD: Bug: Signed integer attributes should parse "-0xABCDEF" as -0, but instead incorrectly return defaultValue
|
|
||||||
todo_is(element[attr], intValue, "Bug: " + element.localName +
|
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
|
||||||
} else if ((v == "++2" || v == "+-2" || v == "--2" || v == "-+2") && element[attr] != defaultValue) {
|
|
||||||
//TBD: Bug: Should not be able to parse strings with multiple sign characters, should return defaultValue
|
|
||||||
todo_is(element[attr], intValue, "Bug: " + element.localName +
|
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
|
||||||
} else {
|
} else {
|
||||||
is(element[attr], intValue, element.localName +
|
is(element[attr], intValue, element.localName +
|
||||||
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<th>0</th>
|
<th>0</th>
|
||||||
<td><table cellpadding="4" border="0"><tr><td>border="0"</td></tr></table></td>
|
<td><table cellpadding="4" border="0"><tr><td>border="0"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="0"><tr><td>border="0px"</td></tr></table></td>
|
<td><table cellpadding="4" border="0"><tr><td>border="0px"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="1"><tr><td>border="0em"</td></tr></table></td>
|
<td><table cellpadding="4" border="0"><tr><td>border="0em"</td></tr></table></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>1</th>
|
<th>1</th>
|
||||||
|
@ -18,19 +18,19 @@
|
||||||
<th>2</th>
|
<th>2</th>
|
||||||
<td><table cellpadding="4" border="2"><tr><td>border="2"</td></tr></table></td>
|
<td><table cellpadding="4" border="2"><tr><td>border="2"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="2"><tr><td>border="2px"</td></tr></table></td>
|
<td><table cellpadding="4" border="2"><tr><td>border="2px"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="1"><tr><td>border="2em"</td></tr></table></td>
|
<td><table cellpadding="4" border="2"><tr><td>border="2em"</td></tr></table></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>3</th>
|
<th>3</th>
|
||||||
<td><table cellpadding="4" border="3"><tr><td>border="3"</td></tr></table></td>
|
<td><table cellpadding="4" border="3"><tr><td>border="3"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="3"><tr><td>border="3px"</td></tr></table></td>
|
<td><table cellpadding="4" border="3"><tr><td>border="3px"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="1"><tr><td>border="3em"</td></tr></table></td>
|
<td><table cellpadding="4" border="3"><tr><td>border="3em"</td></tr></table></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>10</th>
|
<th>10</th>
|
||||||
<td><table cellpadding="4" border="10"><tr><td>border="10"</td></tr></table></td>
|
<td><table cellpadding="4" border="10"><tr><td>border="10"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="10"><tr><td>border="10px"</td></tr></table></td>
|
<td><table cellpadding="4" border="10"><tr><td>border="10px"</td></tr></table></td>
|
||||||
<td><table cellpadding="4" border="1"><tr><td>border="10em"</td></tr></table></td>
|
<td><table cellpadding="4" border="10"><tr><td>border="10em"</td></tr></table></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче