Backed out changesets 01de929d4b85 and b9c5750d818a (bug 943519) for suspicion of causing B2G mochitest-2 failures.

CLOSED TREE
This commit is contained in:
Ryan VanderMeulen 2013-12-16 13:41:15 -05:00
parent 17faaf8597
commit 8adbb71ea4
4 changed files with 37 additions and 61 deletions

View File

@ -313,13 +313,11 @@ nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount,
if (aOffset == 0 && endOffset == textLength) {
// Replacing whole text or old text was empty. Don't bother to check for
// bidi in this string if the document already has bidi enabled.
bool ok = mText.SetTo(aBuffer, aLength, !document || !document->GetBidiEnabled());
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
mText.SetTo(aBuffer, aLength, !document || !document->GetBidiEnabled());
}
else if (aOffset == textLength) {
// Appending to existing
bool ok = mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled());
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled());
}
else {
// Merging old and new
@ -340,11 +338,10 @@ nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount,
mText.CopyTo(to + aOffset + aLength, endOffset, textLength - endOffset);
}
bool ok = mText.SetTo(to, newLength, !document || !document->GetBidiEnabled());
// XXX Add OOM checking to this
mText.SetTo(to, newLength, !document || !document->GetBidiEnabled());
delete [] to;
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
}
UnsetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);

View File

@ -84,7 +84,7 @@ void
nsTextFragment::ReleaseText()
{
if (mState.mLength && m1b && mState.mInHeap) {
moz_free(m2b); // m1b == m2b as far as moz_free is concerned
nsMemory::Free(m2b); // m1b == m2b as far as nsMemory is concerned
}
m1b = nullptr;
@ -104,20 +104,9 @@ nsTextFragment::operator=(const nsTextFragment& aOther)
m1b = aOther.m1b; // This will work even if aOther is using m2b
}
else {
size_t m2bSize = aOther.mState.mLength *
(aOther.mState.mIs2b ? sizeof(PRUnichar) : sizeof(char));
m2b = static_cast<PRUnichar*>(moz_malloc(m2bSize));
if (m2b) {
memcpy(m2b, aOther.m2b, m2bSize);
} else {
// allocate a buffer for a single REPLACEMENT CHARACTER
m2b = static_cast<PRUnichar*>(moz_xmalloc(sizeof(PRUnichar)));
m2b[0] = 0xFFFD; // REPLACEMENT CHARACTER
mState.mIs2b = true;
mState.mInHeap = true;
mState.mLength = 1;
}
m2b = static_cast<PRUnichar*>
(nsMemory::Clone(aOther.m2b, aOther.mState.mLength *
(aOther.mState.mIs2b ? sizeof(PRUnichar) : sizeof(char))));
}
if (m1b) {
@ -190,13 +179,13 @@ FirstNon8Bit(const PRUnichar *str, const PRUnichar *end)
return FirstNon8BitUnvectorized(str, end);
}
bool
void
nsTextFragment::SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBidi)
{
ReleaseText();
if (aLength == 0) {
return true;
return;
}
PRUnichar firstChar = *aBuffer;
@ -206,7 +195,7 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBid
mState.mIs2b = false;
mState.mLength = 1;
return true;
return;
}
const PRUnichar *ucp = aBuffer;
@ -245,7 +234,7 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBid
mState.mIs2b = false;
mState.mLength = aLength;
return true;
return;
}
}
@ -254,12 +243,11 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBid
if (first16bit != -1) { // aBuffer contains no non-8bit character
// Use ucs2 storage because we have to
size_t m2bSize = aLength * sizeof(PRUnichar);
m2b = (PRUnichar *)moz_malloc(m2bSize);
m2b = (PRUnichar *)nsMemory::Clone(aBuffer,
aLength * sizeof(PRUnichar));
if (!m2b) {
return false;
return;
}
memcpy(m2b, aBuffer, m2bSize);
mState.mIs2b = true;
if (aUpdateBidi) {
@ -268,9 +256,9 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBid
} else {
// Use 1 byte storage because we can
char* buff = (char *)moz_malloc(aLength * sizeof(char));
char* buff = (char *)nsMemory::Alloc(aLength * sizeof(char));
if (!buff) {
return false;
return;
}
// Copy data
@ -283,8 +271,6 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBid
// Setup our fields
mState.mInHeap = true;
mState.mLength = aLength;
return true;
}
void
@ -313,22 +299,24 @@ nsTextFragment::CopyTo(PRUnichar *aDest, int32_t aOffset, int32_t aCount)
}
}
bool
void
nsTextFragment::Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateBidi)
{
// This is a common case because some callsites create a textnode
// with a value by creating the node and then calling AppendData.
if (mState.mLength == 0) {
return SetTo(aBuffer, aLength, aUpdateBidi);
SetTo(aBuffer, aLength, aUpdateBidi);
return;
}
// Should we optimize for aData.Length() == 0?
if (mState.mIs2b) {
// Already a 2-byte string so the result will be too
PRUnichar* buff = (PRUnichar*)moz_realloc(m2b, (mState.mLength + aLength) * sizeof(PRUnichar));
PRUnichar* buff = (PRUnichar*)nsMemory::Realloc(m2b, (mState.mLength + aLength) * sizeof(PRUnichar));
if (!buff) {
return false;
return;
}
memcpy(buff + mState.mLength, aBuffer, aLength * sizeof(PRUnichar));
@ -339,7 +327,7 @@ nsTextFragment::Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateB
UpdateBidiFlag(aBuffer, aLength);
}
return true;
return;
}
// Current string is a 1-byte string, check if the new data fits in one byte too.
@ -348,10 +336,10 @@ nsTextFragment::Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateB
if (first16bit != -1) { // aBuffer contains no non-8bit character
// The old data was 1-byte, but the new is not so we have to expand it
// all to 2-byte
PRUnichar* buff = (PRUnichar*)moz_malloc((mState.mLength + aLength) *
PRUnichar* buff = (PRUnichar*)nsMemory::Alloc((mState.mLength + aLength) *
sizeof(PRUnichar));
if (!buff) {
return false;
return;
}
// Copy data into buff
@ -363,7 +351,7 @@ nsTextFragment::Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateB
mState.mIs2b = true;
if (mState.mInHeap) {
moz_free(m2b);
nsMemory::Free(m2b);
}
m2b = buff;
@ -373,22 +361,22 @@ nsTextFragment::Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateB
UpdateBidiFlag(aBuffer + first16bit, aLength - first16bit);
}
return true;
return;
}
// The new and the old data is all 1-byte
char* buff;
if (mState.mInHeap) {
buff = (char*)moz_realloc(const_cast<char*>(m1b),
buff = (char*)nsMemory::Realloc(const_cast<char*>(m1b),
(mState.mLength + aLength) * sizeof(char));
if (!buff) {
return false;
return;
}
}
else {
buff = (char*)moz_malloc((mState.mLength + aLength) * sizeof(char));
buff = (char*)nsMemory::Alloc((mState.mLength + aLength) * sizeof(char));
if (!buff) {
return false;
return;
}
memcpy(buff, m1b, mState.mLength);
@ -402,7 +390,6 @@ nsTextFragment::Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateB
m1b = buff;
mState.mLength += aLength;
return true;
}
/* virtual */ size_t

View File

@ -53,7 +53,7 @@ public:
/**
* Change the contents of this fragment to be a copy of the
* the argument fragment, or to "" if unable to allocate enough memory.
* the argument fragment.
*/
nsTextFragment& operator=(const nsTextFragment& aOther);
@ -112,14 +112,14 @@ public:
* buffer. If aUpdateBidi is true, contents of the fragment will be scanned,
* and mState.mIsBidi will be turned on if it includes any Bidi characters.
*/
bool SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBidi);
void SetTo(const PRUnichar* aBuffer, int32_t aLength, bool aUpdateBidi);
/**
* Append aData to the end of this fragment. If aUpdateBidi is true, contents
* of the fragment will be scanned, and mState.mIsBidi will be turned on if
* it includes any Bidi characters.
*/
bool Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateBidi);
void Append(const PRUnichar* aBuffer, uint32_t aLength, bool aUpdateBidi);
/**
* Append the contents of this string fragment to aString

View File

@ -520,11 +520,7 @@ nsHtml5TreeOpExecutor::RunFlushLoop()
}
NS_ASSERTION(mFlushState == eInDocUpdate,
"Tried to perform tree op outside update batch.");
nsresult rv = iter->Perform(this, &scriptElement);
if (NS_FAILED(rv)) {
MarkAsBroken(rv);
break;
}
iter->Perform(this, &scriptElement);
// Be sure not to check the deadline if the last op was just performed.
if (MOZ_UNLIKELY(iter == last)) {
@ -626,11 +622,7 @@ nsHtml5TreeOpExecutor::FlushDocumentWrite()
}
NS_ASSERTION(mFlushState == eInDocUpdate,
"Tried to perform tree op outside update batch.");
nsresult rv = iter->Perform(this, &scriptElement);
if (NS_FAILED(rv)) {
MarkAsBroken(rv);
break;
}
iter->Perform(this, &scriptElement);
}
mOpQueue.Clear();