зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1303095 - XMLHttpRequestString should be fallible, r=mccr8
This commit is contained in:
Родитель
52624b56b2
Коммит
4f62933f76
|
@ -581,7 +581,10 @@ XMLHttpRequestMainThread::GetResponseText(nsAString& aResponseText,
|
|||
return;
|
||||
}
|
||||
|
||||
snapshot.GetAsString(aResponseText);
|
||||
if (!snapshot.GetAsString(aResponseText)) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -645,7 +648,9 @@ XMLHttpRequestMainThread::CreateResponseParsedJSON(JSContext* aCx)
|
|||
}
|
||||
|
||||
nsAutoString string;
|
||||
mResponseText.GetAsString(string);
|
||||
if (!mResponseText.GetAsString(string)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// The Unicode converter has already zapped the BOM if there was one
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
|
|
|
@ -47,11 +47,11 @@ public:
|
|||
mData.Append(aString);
|
||||
}
|
||||
|
||||
void
|
||||
MOZ_MUST_USE bool
|
||||
GetAsString(nsAString& aString)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
aString = mData;
|
||||
return aString.Assign(mData, mozilla::fallible);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -60,12 +60,12 @@ public:
|
|||
return mData.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
}
|
||||
|
||||
void
|
||||
MOZ_MUST_USE bool
|
||||
GetAsString(nsAString& aString, uint32_t aLength)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
MOZ_ASSERT(aLength <= mData.Length());
|
||||
aString.Assign(mData.BeginReading(), aLength);
|
||||
return aString.Assign(mData.BeginReading(), aLength, mozilla::fallible);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -120,7 +120,7 @@ XMLHttpRequestString::Append(const nsAString& aString)
|
|||
mBuffer->Append(aString);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
XMLHttpRequestString::GetAsString(nsAString& aString) const
|
||||
{
|
||||
return mBuffer->GetAsString(aString);
|
||||
|
@ -186,13 +186,12 @@ XMLHttpRequestStringSnapshot::Set(XMLHttpRequestStringBuffer* aBuffer,
|
|||
mVoid = false;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
XMLHttpRequestStringSnapshot::GetAsString(nsAString& aString) const
|
||||
{
|
||||
if (mBuffer) {
|
||||
MOZ_ASSERT(!mVoid);
|
||||
mBuffer->GetAsString(aString, mLength);
|
||||
return;
|
||||
return mBuffer->GetAsString(aString, mLength);
|
||||
}
|
||||
|
||||
aString.Truncate();
|
||||
|
@ -200,6 +199,8 @@ XMLHttpRequestStringSnapshot::GetAsString(nsAString& aString) const
|
|||
if (mVoid) {
|
||||
aString.SetIsVoid(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
// This method should be called only when the string is really needed because
|
||||
// it can cause the duplication of the strings in case the loading of the XHR
|
||||
// is not completed yet.
|
||||
void GetAsString(nsAString& aString) const;
|
||||
MOZ_MUST_USE bool GetAsString(nsAString& aString) const;
|
||||
|
||||
size_t SizeOfThis(MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
return !mLength;
|
||||
}
|
||||
|
||||
void GetAsString(nsAString& aString) const;
|
||||
MOZ_MUST_USE bool GetAsString(nsAString& aString) const;
|
||||
|
||||
private:
|
||||
XMLHttpRequestStringSnapshot(const XMLHttpRequestStringSnapshot&) = delete;
|
||||
|
|
|
@ -2425,9 +2425,10 @@ XMLHttpRequestWorker::GetResponseText(nsAString& aResponseText, ErrorResult& aRv
|
|||
return;
|
||||
}
|
||||
|
||||
nsAutoString foo;
|
||||
mStateData.mResponseText.GetAsString(foo);
|
||||
aResponseText.Assign(foo.BeginReading(), foo.Length());
|
||||
if (!mStateData.mResponseText.GetAsString(aResponseText)) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Загрузка…
Ссылка в новой задаче