Skip to content

Commit

Permalink
Bug 1126593 - Add a global fallible instance, so that using fallible …
Browse files Browse the repository at this point in the history
…works directly, everywhere. r=njn
  • Loading branch information
glandium committed Feb 2, 2015
1 parent 0039cec commit 1ad017b
Show file tree
Hide file tree
Showing 97 changed files with 372 additions and 276 deletions.
5 changes: 5 additions & 0 deletions build/gecko_templates.mozbuild
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def GeckoBinary(linkage='dependent', msvcrt='dynamic', mozglue=None):
else:
error('`mozglue` must be "program" or "library"')

if not CONFIG['JS_STANDALONE']:
USE_LIBS += [
'fallible',
]


@template
def GeckoProgram(name, linkage='standalone', **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion dom/base/DOMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ DOMParser::ParseFromString(const nsAString& str,

nsAutoCString utf8str;
// Convert from UTF16 to UTF8 using fallible allocations
if (!AppendUTF16toUTF8(str, utf8str, mozilla::fallible_t())) {
if (!AppendUTF16toUTF8(str, utf8str, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/FragmentOrElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ class StringBuilder

bool ToString(nsAString& aOut)
{
if (!aOut.SetCapacity(mLength, fallible_t())) {
if (!aOut.SetCapacity(mLength, fallible)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/URLSearchParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ URLSearchParams::ConvertString(const nsACString& aInput, nsAString& aOutput)
return;
}

if (!aOutput.SetLength(outputLength, fallible_t())) {
if (!aOutput.SetLength(outputLength, fallible)) {
return;
}

Expand Down
20 changes: 10 additions & 10 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ nsContentUtils::Atob(const nsAString& aAsciiBase64String,
const char16_t* start = aAsciiBase64String.BeginReading();
const char16_t* end = aAsciiBase64String.EndReading();
nsString trimmedString;
if (!trimmedString.SetCapacity(aAsciiBase64String.Length(), fallible_t())) {
if (!trimmedString.SetCapacity(aAsciiBase64String.Length(), fallible)) {
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
}
while (start < end) {
Expand Down Expand Up @@ -4425,20 +4425,20 @@ nsContentUtils::SetNodeTextContent(nsIContent* aContent,

static bool
AppendNodeTextContentsRecurse(nsINode* aNode, nsAString& aResult,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
for (nsIContent* child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
if (child->IsElement()) {
bool ok = AppendNodeTextContentsRecurse(child, aResult,
mozilla::fallible_t());
aFallible);
if (!ok) {
return false;
}
}
else if (child->IsNodeOfType(nsINode::eTEXT)) {
bool ok = child->AppendTextTo(aResult, mozilla::fallible_t());
bool ok = child->AppendTextTo(aResult, aFallible);
if (!ok) {
return false;
}
Expand All @@ -4452,21 +4452,21 @@ AppendNodeTextContentsRecurse(nsINode* aNode, nsAString& aResult,
bool
nsContentUtils::AppendNodeTextContent(nsINode* aNode, bool aDeep,
nsAString& aResult,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
return static_cast<nsIContent*>(aNode)->AppendTextTo(aResult,
mozilla::fallible_t());
aFallible);
}
else if (aDeep) {
return AppendNodeTextContentsRecurse(aNode, aResult, mozilla::fallible_t());
return AppendNodeTextContentsRecurse(aNode, aResult, aFallible);
}
else {
for (nsIContent* child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
if (child->IsNodeOfType(nsINode::eTEXT)) {
bool ok = child->AppendTextTo(aResult, mozilla::fallible_t());
bool ok = child->AppendTextTo(aResult, fallible);
if (!ok) {
return false;
}
Expand Down Expand Up @@ -6242,7 +6242,7 @@ void nsContentUtils::RemoveNewlines(nsString &aString)
void
nsContentUtils::PlatformToDOMLineBreaks(nsString &aString)
{
if (!PlatformToDOMLineBreaks(aString, mozilla::fallible_t())) {
if (!PlatformToDOMLineBreaks(aString, fallible)) {
aString.AllocFailed(aString.Length());
}
}
Expand Down Expand Up @@ -6962,7 +6962,7 @@ bool
nsContentUtils::GetNodeTextContent(nsINode* aNode, bool aDeep, nsAString& aResult)
{
aResult.Truncate();
return AppendNodeTextContent(aNode, aDeep, aResult, mozilla::fallible_t());
return AppendNodeTextContent(aNode, aDeep, aResult, fallible);
}

void
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDOMFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
if (uint64_t(oldLen) + aCount > UINT32_MAX)
return NS_ERROR_OUT_OF_MEMORY;
char16_t *buf = nullptr;
mResult.GetMutableData(&buf, oldLen + aCount, fallible_t());
mResult.GetMutableData(&buf, oldLen + aCount, fallible);
NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);

uint32_t bytesRead = 0;
Expand Down Expand Up @@ -522,7 +522,7 @@ nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aFile,
rv = Base64Encode(Substring(aFileData, aDataLen), encodedData);
NS_ENSURE_SUCCESS(rv, rv);

if (!AppendASCIItoUTF16(encodedData, aResult, fallible_t())) {
if (!AppendASCIItoUTF16(encodedData, aResult, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsDocumentEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ ConvertAndWrite(const nsAString& aString,
}

nsAutoCString charXferString;
if (!charXferString.SetLength(charLength, fallible_t()))
if (!charXferString.SetLength(charLength, fallible))
return NS_ERROR_OUT_OF_MEMORY;

char* charXferBuf = charXferString.BeginWriting();
Expand Down
5 changes: 3 additions & 2 deletions dom/base/nsGenericDOMDataNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,10 @@ nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
}

bool
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult, const mozilla::fallible_t&)
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult,
const mozilla::fallible_t& aFallible)
{
return mText.AppendTo(aResult, mozilla::fallible_t());
return mText.AppendTo(aResult, aFallible);
}

already_AddRefed<nsIAtom>
Expand Down
1 change: 0 additions & 1 deletion dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,6 @@ nsJSArgArray::nsJSArgArray(JSContext *aContext, uint32_t argc, JS::Value *argv,
// copy the array - we don't know its lifetime, and ours is tied to xpcom
// refcounting.
if (argc) {
static const fallible_t fallible = fallible_t();
mArgv = new (fallible) JS::Heap<JS::Value>[argc];
if (!mArgv) {
*prv = NS_ERROR_OUT_OF_MEMORY;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsJSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ AssignJSString(JSContext *cx, T &dest, JSString *s)
size_t len = js::GetStringLength(s);
static_assert(js::MaxStringLength < (1 << 28),
"Shouldn't overflow here or in SetCapacity");
if (MOZ_UNLIKELY(!dest.SetLength(len, mozilla::fallible_t()))) {
if (MOZ_UNLIKELY(!dest.SetLength(len, mozilla::fallible))) {
JS_ReportOutOfMemory(cx);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsScriptNameSpaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ nsScriptNameSpaceManager::Init()

mIsInitialized = PL_DHashTableInit(&mGlobalNames, &hash_table_ops,
sizeof(GlobalNameMapEntry),
fallible_t(),
fallible,
GLOBALNAME_HASHTABLE_INITIAL_LENGTH);
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_OUT_OF_MEMORY);

mIsInitialized = PL_DHashTableInit(&mNavigatorNames, &hash_table_ops,
sizeof(GlobalNameMapEntry),
fallible_t(),
fallible,
GLOBALNAME_HASHTABLE_INITIAL_LENGTH);
if (!mIsInitialized) {
PL_DHashTableFinish(&mGlobalNames);
Expand Down
16 changes: 8 additions & 8 deletions dom/base/nsTextFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class nsTextFragment MOZ_FINAL {
* Append the contents of this string fragment to aString
*/
void AppendTo(nsAString& aString) const {
if (!AppendTo(aString, mozilla::fallible_t())) {
if (!AppendTo(aString, mozilla::fallible)) {
aString.AllocFailed(aString.Length() + GetLength());
}
}
Expand All @@ -135,17 +135,17 @@ class nsTextFragment MOZ_FINAL {
* @return false if an out of memory condition is detected, true otherwise
*/
bool AppendTo(nsAString& aString,
const mozilla::fallible_t&) const NS_WARN_UNUSED_RESULT {
const mozilla::fallible_t& aFallible) const NS_WARN_UNUSED_RESULT {
if (mState.mIs2b) {
bool ok = aString.Append(m2b, mState.mLength, mozilla::fallible_t());
bool ok = aString.Append(m2b, mState.mLength, aFallible);
if (!ok) {
return false;
}

return true;
} else {
return AppendASCIItoUTF16(Substring(m1b, mState.mLength), aString,
mozilla::fallible_t());
aFallible);
}
}

Expand All @@ -155,7 +155,7 @@ class nsTextFragment MOZ_FINAL {
* @param aLength the length of the substring
*/
void AppendTo(nsAString& aString, int32_t aOffset, int32_t aLength) const {
if (!AppendTo(aString, aOffset, aLength, mozilla::fallible_t())) {
if (!AppendTo(aString, aOffset, aLength, mozilla::fallible)) {
aString.AllocFailed(aString.Length() + aLength);
}
}
Expand All @@ -168,18 +168,18 @@ class nsTextFragment MOZ_FINAL {
* @return false if an out of memory condition is detected, true otherwise
*/
bool AppendTo(nsAString& aString, int32_t aOffset, int32_t aLength,
const mozilla::fallible_t&) const NS_WARN_UNUSED_RESULT
const mozilla::fallible_t& aFallible) const NS_WARN_UNUSED_RESULT
{
if (mState.mIs2b) {
bool ok = aString.Append(m2b + aOffset, aLength, mozilla::fallible_t());
bool ok = aString.Append(m2b + aOffset, aLength, aFallible);
if (!ok) {
return false;
}

return true;
} else {
return AppendASCIItoUTF16(Substring(m1b + aOffset, aLength), aString,
mozilla::fallible_t());
aFallible);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsXMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ nsXMLHttpRequest::AppendToResponseText(const char * aSrcBuffer,
&destBufferLen);
NS_ENSURE_SUCCESS(rv, rv);

if (!mResponseText.SetCapacity(mResponseText.Length() + destBufferLen, fallible_t())) {
if (!mResponseText.SetCapacity(mResponseText.Length() + destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

Expand Down
4 changes: 1 addition & 3 deletions dom/bindings/MozMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ class MozMap : protected nsTHashtable<binding_detail::MozMapEntry<DataType>>

DataType* AddEntry(const nsAString& aKey) NS_WARN_UNUSED_RESULT
{
// XXXbz can't just use fallible_t() because our superclass has a
// private typedef by that name.
EntryType* ent = this->PutEntry(aKey, mozilla::fallible_t());
EntryType* ent = this->PutEntry(aKey, fallible);
if (!ent) {
return nullptr;
}
Expand Down
1 change: 0 additions & 1 deletion dom/canvas/WebGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,6 @@ WebGLContext::GetImageBuffer(uint8_t** out_imageBuffer, int32_t* out_format)
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map))
return;

static const fallible_t fallible = fallible_t();
uint8_t* imageBuffer = new (fallible) uint8_t[mWidth * mHeight * 4];
if (!imageBuffer) {
dataSurface->Unmap();
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/WebGLContextDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ WebGLContext::DoFakeVertexAttrib0(GLuint vertexCount)
GetAndFlushUnderlyingGLErrors();

if (mFakeVertexAttrib0BufferStatus == WebGLVertexAttrib0Status::EmulatedInitializedArray) {
UniquePtr<GLfloat[]> array(new ((fallible_t())) GLfloat[4 * vertexCount]);
UniquePtr<GLfloat[]> array(new (fallible) GLfloat[4 * vertexCount]);
if (!array) {
ErrorOutOfMemory("Fake attrib0 array.");
return false;
Expand Down
7 changes: 3 additions & 4 deletions dom/canvas/WebGLContextGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/Endian.h"
#include "mozilla/fallible.h"

using namespace mozilla;
using namespace mozilla::dom;
Expand Down Expand Up @@ -2086,7 +2085,7 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
uint32_t subrect_byteLength = (subrect_height-1)*subrect_alignedRowSize + subrect_plainRowSize;

// create subrect buffer, call glReadPixels, copy pixels into destination buffer, delete subrect buffer
UniquePtr<GLubyte> subrect_data(new ((fallible_t())) GLubyte[subrect_byteLength]);
UniquePtr<GLubyte> subrect_data(new (fallible) GLubyte[subrect_byteLength]);
if (!subrect_data)
return ErrorOutOfMemory("readPixels: subrect_data");

Expand Down Expand Up @@ -3203,7 +3202,7 @@ WebGLContext::TexImage2D_base(TexImageTarget texImageTarget, GLint level,
else
{
size_t convertedDataSize = height * dstStride;
convertedData = new ((fallible_t())) uint8_t[convertedDataSize];
convertedData = new (fallible) uint8_t[convertedDataSize];
if (!convertedData) {
ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
" a buffer for doing format conversion.");
Expand Down Expand Up @@ -3404,7 +3403,7 @@ WebGLContext::TexSubImage2D_base(TexImageTarget texImageTarget, GLint level,

if (!noConversion) {
size_t convertedDataSize = height * dstStride;
convertedData = new ((fallible_t())) uint8_t[convertedDataSize];
convertedData = new (fallible) uint8_t[convertedDataSize];
if (!convertedData) {
ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
" a buffer for doing format conversion.");
Expand Down
1 change: 0 additions & 1 deletion dom/encoding/TextDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ TextDecoder::Decode(const char* aInput, const int32_t aLength,
}
// Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string.
static const fallible_t fallible = fallible_t();
nsAutoArrayPtr<char16_t> buf(new (fallible) char16_t[outLen + 1]);
if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
Expand Down
1 change: 0 additions & 1 deletion dom/encoding/TextEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ TextEncoder::Encode(JSContext* aCx,
}
// Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string.
static const fallible_t fallible = fallible_t();
nsAutoArrayPtr<char> buf(new (fallible) char[maxLen + 1]);
if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
Expand Down
4 changes: 2 additions & 2 deletions dom/fetch/Fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ ExtractFromUSVString(const nsString& aStr,
}

nsCString encoded;
if (!encoded.SetCapacity(destBufferLen, fallible_t())) {
if (!encoded.SetCapacity(destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

Expand Down Expand Up @@ -583,7 +583,7 @@ class StreamDecoder MOZ_FINAL
return rv;
}

if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible_t())) {
if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/filehandle/MemoryStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MemoryOutputStream::Create(uint64_t aSize)
nsRefPtr<MemoryOutputStream> stream = new MemoryOutputStream();

char* dummy;
uint32_t length = stream->mData.GetMutableData(&dummy, aSize, fallible_t());
uint32_t length = stream->mData.GetMutableData(&dummy, aSize, fallible);
NS_ENSURE_TRUE(length == aSize, nullptr);

return stream.forget();
Expand Down
1 change: 0 additions & 1 deletion dom/html/HTMLFrameSetElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ HTMLFrameSetElement::ParseRowCol(const nsAString & aValue,
commaX = spec.FindChar(sComma, commaX + 1);
}

static const fallible_t fallible = fallible_t();
nsFramesetSpec* specs = new (fallible) nsFramesetSpec[count];
if (!specs) {
*aSpecs = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions dom/html/nsTextEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,8 +1873,6 @@ bool
nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
bool aSetValueChanged)
{
mozilla::fallible_t fallible;

if (mEditor && mBoundFrame) {
// The InsertText call below might flush pending notifications, which
// could lead into a scheduled PrepareEditor to be called. That will
Expand Down
2 changes: 0 additions & 2 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ const int32_t kStorageProgressGranularity = 1000;

const char kSavepointClause[] = "SAVEPOINT sp;";

const fallible_t fallible = fallible_t();

const uint32_t kFileCopyBufferSize = 32768;

const char kJournalDirectoryName[] = "journals";
Expand Down
2 changes: 1 addition & 1 deletion dom/indexedDB/IDBObjectStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ StructuredCloneReadString(JSStructuredCloneReader* aReader,
}
length = NativeEndian::swapFromLittleEndian(length);

if (!aString.SetLength(length, fallible_t())) {
if (!aString.SetLength(length, fallible)) {
NS_WARNING("Out of memory?");
return false;
}
Expand Down
Loading

0 comments on commit 1ad017b

Please sign in to comment.