mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 970356 - neither getSubStringLength, nor selectSubString should throw if nchars is too large. r=cam
This commit is contained in:
parent
1c5d30fc3b
commit
28340364f9
@ -59,12 +59,13 @@ function runTests(text, charWidth)
|
||||
}
|
||||
}
|
||||
|
||||
expectThrow(-1, 2);
|
||||
expectThrow(-1, 0);
|
||||
expectThrow(1, 3);
|
||||
expectThrow(0, 4);
|
||||
expectThrow(100, 2);
|
||||
expectThrow(100, 0);
|
||||
expectThrow(3, 0);
|
||||
expectThrow(3, 1);
|
||||
|
||||
expectValue(1, 3, chars(2));
|
||||
expectValue(0, 4, chars(3));
|
||||
expectValue(0, 0, chars(0));
|
||||
expectValue(1, 0, chars(0));
|
||||
expectValue(2, 0, chars(0));
|
||||
@ -74,12 +75,8 @@ function runTests(text, charWidth)
|
||||
expectValue(0, 2, chars(2));
|
||||
expectValue(1, 2, chars(2));
|
||||
expectValue(0, 3, chars(3));
|
||||
|
||||
expectThrow(1, -1);
|
||||
expectThrow(2, -1);
|
||||
expectThrow(3, -1);
|
||||
expectThrow(3, -3);
|
||||
expectThrow(-1, -1);
|
||||
expectValue(1, 100, chars(2));
|
||||
expectValue(2, 100, chars(1));
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,31 +30,48 @@ function runTests()
|
||||
{
|
||||
text.selectSubString(charnum, nchars);
|
||||
ok(false,
|
||||
"text.selectSubString(" + charnum + "," + nchars + ") " +
|
||||
"should have thrown");
|
||||
"text.selectSubString(" + charnum + "," + nchars + ") " +
|
||||
"should have thrown");
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
is(e.name, "IndexSizeError",
|
||||
"expected an index error for " +
|
||||
"text.selectSubString(" + charnum + "," + nchars + ")");
|
||||
"expected an index error for " +
|
||||
"text.selectSubString(" + charnum + "," + nchars + ")");
|
||||
is(e.code, DOMException.INDEX_SIZE_ERR,
|
||||
"expected an index error for " +
|
||||
"text.selectSubString(" + charnum + "," + nchars + ")");
|
||||
"expected an index error for " +
|
||||
"text.selectSubString(" + charnum + "," + nchars + ")");
|
||||
}
|
||||
}
|
||||
|
||||
function expectNoThrow(charnum, nchars, expected)
|
||||
{
|
||||
try
|
||||
{
|
||||
text.selectSubString(charnum, nchars);
|
||||
ok(true,
|
||||
"text.selectSubString(" + charnum + "," + nchars + ") " +
|
||||
"should not have thrown");
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
ok(false,
|
||||
"unexpected exception for " +
|
||||
"text.selectSubString(" + charnum + "," + nchars + ")");
|
||||
}
|
||||
}
|
||||
|
||||
expectThrow(-1, 2);
|
||||
expectThrow(-1, 0);
|
||||
expectThrow(1, 3);
|
||||
expectThrow(0, 4);
|
||||
expectThrow(100, 2);
|
||||
expectThrow(100, 0);
|
||||
expectThrow(3, 0);
|
||||
expectThrow(3, 100);
|
||||
expectThrow(3, 100);
|
||||
expectThrow(100, 100);
|
||||
|
||||
expectThrow(1, -1);
|
||||
expectThrow(2, -1);
|
||||
expectThrow(3, -1);
|
||||
expectThrow(3, -3);
|
||||
expectThrow(-1, -1);
|
||||
expectNoThrow(1, 100);
|
||||
expectNoThrow(2, 100);
|
||||
expectNoThrow(1, 3);
|
||||
expectNoThrow(0, 4);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -2119,10 +2119,9 @@ public:
|
||||
bool Next(uint32_t aCount);
|
||||
|
||||
/**
|
||||
* Advances ahead up to aCount matching characters, returns true if there
|
||||
* were enough characters to advance to.
|
||||
* Advances ahead up to aCount matching characters.
|
||||
*/
|
||||
bool NextWithinSubtree(uint32_t aCount);
|
||||
void NextWithinSubtree(uint32_t aCount);
|
||||
|
||||
/**
|
||||
* Advances to the character with the specified index. The index is in the
|
||||
@ -2421,16 +2420,15 @@ CharIterator::Next(uint32_t aCount)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
CharIterator::NextWithinSubtree(uint32_t aCount)
|
||||
{
|
||||
while (IsWithinSubtree() && aCount) {
|
||||
--aCount;
|
||||
if (!Next()) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return !aCount;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -4015,9 +4013,7 @@ SVGTextFrame::SelectSubString(nsIContent* aContent,
|
||||
}
|
||||
charnum = chit.TextElementCharIndex();
|
||||
nsIContent* content = chit.TextFrame()->GetContent();
|
||||
if (!chit.NextWithinSubtree(nchars)) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
chit.NextWithinSubtree(nchars);
|
||||
nchars = chit.TextElementCharIndex() - charnum;
|
||||
|
||||
nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
||||
@ -4053,9 +4049,7 @@ SVGTextFrame::GetSubStringLength(nsIContent* aContent,
|
||||
}
|
||||
|
||||
charnum = chit.TextElementCharIndex();
|
||||
if (!chit.NextWithinSubtree(nchars)) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
chit.NextWithinSubtree(nchars);
|
||||
nchars = chit.TextElementCharIndex() - charnum;
|
||||
|
||||
// Find each rendered run that intersects with the range defined
|
||||
|
Loading…
Reference in New Issue
Block a user