--- a/build/gecko_templates.mozbuild
+++ b/build/gecko_templates.mozbuild
@@ -73,16 +73,21 @@ def GeckoBinary(linkage='dependent', msv
if CONFIG['MOZ_LINKER']:
OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
elif mozglue == 'library':
if not CONFIG['MOZ_GLUE_IN_PROGRAM']:
USE_LIBS += ['mozglue']
else:
error('`mozglue` must be "program" or "library"')
+ if not CONFIG['JS_STANDALONE']:
+ USE_LIBS += [
+ 'fallible',
+ ]
+
@template
def GeckoProgram(name, linkage='standalone', **kwargs):
'''Template for program executables related to Gecko.
`name` identifies the executable base name.
See the documentation for `GeckoBinary` for other possible arguments,
--- a/dom/base/DOMParser.cpp
+++ b/dom/base/DOMParser.cpp
@@ -104,17 +104,17 @@ DOMParser::ParseFromString(const nsAStri
NS_ENSURE_SUCCESS(rv, rv);
domDocument.forget(aResult);
return rv;
}
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;
}
// The new stream holds a reference to the buffer
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewByteInputStream(getter_AddRefs(stream),
utf8str.get(), utf8str.Length(),
NS_ASSIGNMENT_DEPEND);
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -2197,17 +2197,17 @@ public:
u->mTextFragment = aTextFragment;
u->mType = Unit::eTextFragmentWithEncode;
u->mLength = aLen;
mLength += aLen;
}
bool ToString(nsAString& aOut)
{
- if (!aOut.SetCapacity(mLength, fallible_t())) {
+ if (!aOut.SetCapacity(mLength, fallible)) {
return false;
}
for (StringBuilder* current = this; current; current = current->mNext) {
uint32_t len = current->mUnits.Length();
for (uint32_t i = 0; i < len; ++i) {
Unit& u = current->mUnits[i];
switch (u.mType) {
--- a/dom/base/URLSearchParams.cpp
+++ b/dom/base/URLSearchParams.cpp
@@ -185,17 +185,17 @@ URLSearchParams::ConvertString(const nsA
int32_t outputLength = 0;
nsresult rv = mDecoder->GetMaxLength(aInput.BeginReading(), inputLength,
&outputLength);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
- if (!aOutput.SetLength(outputLength, fallible_t())) {
+ if (!aOutput.SetLength(outputLength, fallible)) {
return;
}
int32_t newOutputLength = outputLength;
rv = mDecoder->Convert(aInput.BeginReading(), &inputLength,
aOutput.BeginWriting(), &newOutputLength);
if (NS_FAILED(rv)) {
aOutput.Truncate();
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -727,17 +727,17 @@ nsContentUtils::Atob(const nsAString& aA
if (!Is8bit(aAsciiBase64String)) {
aBinaryData.Truncate();
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
}
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) {
if (!nsContentUtils::IsHTMLWhitespace(*start)) {
trimmedString.Append(*start);
}
start++;
}
@@ -4420,58 +4420,58 @@ nsContentUtils::SetNodeTextContent(nsICo
nsresult rv = aContent->AppendChildTo(textContent, true);
mb.NodesAdded();
return rv;
}
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;
}
}
}
return true;
}
/* static */
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;
}
}
}
}
return true;
@@ -6237,17 +6237,17 @@ void nsContentUtils::RemoveNewlines(nsSt
// strip CR/LF and null
static const char badChars[] = {'\r', '\n', 0};
aString.StripChars(badChars);
}
void
nsContentUtils::PlatformToDOMLineBreaks(nsString &aString)
{
- if (!PlatformToDOMLineBreaks(aString, mozilla::fallible_t())) {
+ if (!PlatformToDOMLineBreaks(aString, fallible)) {
aString.AllocFailed(aString.Length());
}
}
bool
nsContentUtils::PlatformToDOMLineBreaks(nsString& aString, const fallible_t& aFallible)
{
if (aString.FindChar(char16_t('\r')) != -1) {
@@ -6957,17 +6957,17 @@ nsContentUtils::DOMWindowDumpEnabled()
return true;
#endif
}
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
nsContentUtils::DestroyMatchString(void* aData)
{
if (aData) {
nsString* matchString = static_cast<nsString*>(aData);
delete matchString;
--- a/dom/base/nsDOMFileReader.cpp
+++ b/dom/base/nsDOMFileReader.cpp
@@ -343,17 +343,17 @@ nsDOMFileReader::DoReadData(nsIAsyncInpu
if (mDataFormat == FILE_AS_BINARY) {
//Continuously update our binary string as data comes in
uint32_t oldLen = mResult.Length();
NS_ASSERTION(mResult.Length() == mDataLen,
"unexpected mResult length");
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;
aStream->ReadSegments(ReadFuncBinaryString, buf + oldLen, aCount,
&bytesRead);
NS_ASSERTION(bytesRead == aCount, "failed to read data");
}
else {
@@ -517,17 +517,17 @@ nsDOMFileReader::GetAsDataURL(nsIDOMBlob
aResult.AppendLiteral("application/octet-stream");
}
aResult.AppendLiteral(";base64,");
nsCString encodedData;
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;
}
return NS_OK;
}
/* virtual */ JSObject*
nsDOMFileReader::WrapObject(JSContext* aCx)
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -567,17 +567,17 @@ ConvertAndWrite(const nsAString& aString
if (!charLength) {
// Nothing to write. Besides, a length 0 string has an immutable buffer, so
// attempts to null-terminate it will crash.
return NS_OK;
}
nsAutoCString charXferString;
- if (!charXferString.SetLength(charLength, fallible_t()))
+ if (!charXferString.SetLength(charLength, fallible))
return NS_ERROR_OUT_OF_MEMORY;
char* charXferBuf = charXferString.BeginWriting();
nsresult convert_rv = NS_OK;
do {
unicodeLength = startLength;
charLength = startCharLength;
--- a/dom/base/nsGenericDOMDataNode.cpp
+++ b/dom/base/nsGenericDOMDataNode.cpp
@@ -1069,19 +1069,20 @@ nsGenericDOMDataNode::HasTextForTranslat
void
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
{
mText.AppendTo(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>
nsGenericDOMDataNode::GetCurrentValueAtom()
{
nsAutoString val;
GetData(val);
return NS_NewAtom(val);
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -2768,17 +2768,16 @@ nsJSArgArray::nsJSArgArray(JSContext *aC
nsresult *prv) :
mContext(aContext),
mArgv(nullptr),
mArgc(argc)
{
// 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;
return;
}
}
// Callers are allowed to pass in a null argv even for argc > 0. They can
--- a/dom/base/nsJSUtils.h
+++ b/dom/base/nsJSUtils.h
@@ -156,17 +156,17 @@ public:
template<typename T>
inline bool
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;
}
return js::CopyStringChars(cx, dest.BeginWriting(), s, len);
}
inline void
AssignJSFlatString(nsAString &dest, JSFlatString *s)
--- a/dom/base/nsScriptNameSpaceManager.cpp
+++ b/dom/base/nsScriptNameSpaceManager.cpp
@@ -323,23 +323,23 @@ nsScriptNameSpaceManager::Init()
GlobalNameHashMatchEntry,
PL_DHashMoveEntryStub,
GlobalNameHashClearEntry,
GlobalNameHashInitEntry
};
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);
return NS_ERROR_OUT_OF_MEMORY;
}
RegisterWeakMemoryReporter(this);
--- a/dom/base/nsTextFragment.h
+++ b/dom/base/nsTextFragment.h
@@ -120,71 +120,71 @@ public:
* it includes any Bidi characters.
*/
bool Append(const char16_t* aBuffer, uint32_t aLength, bool aUpdateBidi);
/**
* 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());
}
}
/**
* Append the contents of this string fragment to aString
* @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);
}
}
/**
* Append a substring of the contents of this string fragment to aString.
* @param aOffset where to start the substring in this text fragment
* @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);
}
}
/**
* Append a substring of the contents of this string fragment to aString.
* @param aString the string in which to append
* @param aOffset where to start the substring in this text fragment
* @param aLength the length of the substring
* @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);
}
}
/**
* Make a copy of the fragments contents starting at offset for
* count characters. The offset and count will be adjusted to
* lie within the fragments data. The fragments data is converted if
* necessary.
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -665,17 +665,17 @@ nsXMLHttpRequest::AppendToResponseText(c
{
NS_ENSURE_STATE(mDecoder);
int32_t destBufferLen;
nsresult rv = mDecoder->GetMaxLength(aSrcBuffer, aSrcBufferLen,
&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;
}
char16_t* destBuffer = mResponseText.BeginWriting() + mResponseText.Length();
int32_t totalChars = mResponseText.Length();
// This code here is basically a copy of a similar thing in
--- a/dom/bindings/MozMap.h
+++ b/dom/bindings/MozMap.h
@@ -97,19 +97,17 @@ public:
void EnumerateValues(Enumerator aEnumerator, void *aClosure)
{
ValueEnumClosure args = { aEnumerator, aClosure };
this->EnumerateEntries(ValueEnumerator, &args);
}
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;
}
return &ent->mData;
}
private:
static PLDHashOperator
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -1055,17 +1055,16 @@ WebGLContext::GetImageBuffer(uint8_t** o
MOZ_ASSERT(mOptions.premultipliedAlpha || !premult, "We must get unpremult when we ask for it!");
RefPtr<DataSourceSurface> dataSurface = snapshot->GetDataSurface();
DataSourceSurface::MappedSurface map;
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();
return;
}
memcpy(imageBuffer, map.mData, mWidth * mHeight * 4);
dataSurface->Unmap();
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -576,17 +576,17 @@ WebGLContext::DoFakeVertexAttrib0(GLuint
mFakeVertexAttrib0BufferObjectVector[2] = mVertexAttrib0Vector[2];
mFakeVertexAttrib0BufferObjectVector[3] = mVertexAttrib0Vector[3];
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mFakeVertexAttrib0BufferObject);
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;
}
for(size_t i = 0; i < vertexCount; ++i) {
array[4 * i + 0] = mVertexAttrib0Vector[0];
array[4 * i + 1] = mVertexAttrib0Vector[1];
array[4 * i + 2] = mVertexAttrib0Vector[2];
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -43,17 +43,16 @@
#include "nsCocoaFeatures.h"
#endif
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/BindingUtils.h"
#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;
using namespace mozilla::gfx;
using namespace mozilla::gl;
static const WebGLRectangleObject*
CurValidFBRectObject(const WebGLContext* webgl,
@@ -2081,17 +2080,17 @@ WebGLContext::ReadPixels(GLint x, GLint
// no need to check again for integer overflow here, since we already know the sizes aren't greater than before
uint32_t subrect_plainRowSize = subrect_width * bytesPerPixel;
// There are checks above to ensure that this doesn't overflow.
uint32_t subrect_alignedRowSize =
RoundedToNextMultipleOf(subrect_plainRowSize, mPixelStorePackAlignment).value();
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");
gl->fReadPixels(subrect_x, subrect_y, subrect_width, subrect_height,
format, type, subrect_data.get());
// notice that this for loop terminates because we already checked that subrect_height is at most height
for (GLint y_inside_subrect = 0; y_inside_subrect < subrect_height; ++y_inside_subrect) {
@@ -3198,17 +3197,17 @@ WebGLContext::TexImage2D_base(TexImageTa
!mPixelStoreFlipY)
{
// no conversion, no flipping, so we avoid copying anything and just pass the source pointer
pixels = data;
}
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.");
return;
}
if (!ConvertImage(width, height, srcStride, dstStride,
static_cast<uint8_t*>(data), convertedData,
actualSrcFormat, srcPremultiplied,
@@ -3399,17 +3398,17 @@ WebGLContext::TexSubImage2D_base(TexImag
// no conversion, no flipping, so we avoid copying anything and just pass the source pointer
bool noConversion = (actualSrcFormat == dstFormat &&
srcPremultiplied == mPixelStorePremultiplyAlpha &&
srcStride == dstStride &&
!mPixelStoreFlipY);
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.");
return;
}
if (!ConvertImage(width, height, srcStride, dstStride,
static_cast<const uint8_t*>(data), convertedData,
actualSrcFormat, srcPremultiplied,
--- a/dom/encoding/TextDecoder.cpp
+++ b/dom/encoding/TextDecoder.cpp
@@ -58,17 +58,16 @@ TextDecoder::Decode(const char* aInput,
int32_t outLen;
nsresult rv = mDecoder->GetMaxLength(aInput, aLength, &outLen);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
// 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);
return;
}
int32_t length = aLength;
rv = mDecoder->Convert(aInput, &length, buf, &outLen);
--- a/dom/encoding/TextEncoder.cpp
+++ b/dom/encoding/TextEncoder.cpp
@@ -48,17 +48,16 @@ TextEncoder::Encode(JSContext* aCx,
const char16_t* data = PromiseFlatString(aString).get();
nsresult rv = mEncoder->GetMaxLength(data, srcLen, &maxLen);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
// 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);
return;
}
int32_t dstLen = maxLen;
rv = mEncoder->Convert(data, &srcLen, buf, &dstLen);
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -465,17 +465,17 @@ ExtractFromUSVString(const nsString& aSt
int32_t destBufferLen;
nsresult rv = encoder->GetMaxLength(aStr.get(), aStr.Length(), &destBufferLen);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCString encoded;
- if (!encoded.SetCapacity(destBufferLen, fallible_t())) {
+ if (!encoded.SetCapacity(destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
char* destBuffer = encoded.BeginWriting();
int32_t srcLen = (int32_t) aStr.Length();
int32_t outLen = destBufferLen;
rv = encoder->Convert(aStr.get(), &srcLen, destBuffer, &outLen);
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -578,17 +578,17 @@ public:
{
int32_t destBufferLen;
nsresult rv =
mDecoder->GetMaxLength(aSrcBuffer, aSrcBufferLen, &destBufferLen);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible_t())) {
+ if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
char16_t* destBuffer = mDecoded.BeginWriting() + mDecoded.Length();
int32_t totalChars = mDecoded.Length();
int32_t srcLen = (int32_t) aSrcBufferLen;
int32_t outLen = destBufferLen;
--- a/dom/filehandle/MemoryStreams.cpp
+++ b/dom/filehandle/MemoryStreams.cpp
@@ -21,17 +21,17 @@ MemoryOutputStream::Create(uint64_t aSiz
{
NS_ASSERTION(aSize, "Passed zero size!");
NS_ENSURE_TRUE(aSize <= UINT32_MAX, nullptr);
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();
}
NS_IMPL_ISUPPORTS(MemoryOutputStream, nsIOutputStream)
NS_IMETHODIMP
--- a/dom/html/HTMLFrameSetElement.cpp
+++ b/dom/html/HTMLFrameSetElement.cpp
@@ -227,17 +227,16 @@ HTMLFrameSetElement::ParseRowCol(const n
"Too many frameset specs allowed to allocate");
int32_t commaX = spec.FindChar(sComma);
int32_t count = 1;
while (commaX != kNotFound && count < NS_MAX_FRAMESET_SPEC_COUNT) {
count++;
commaX = spec.FindChar(sComma, commaX + 1);
}
- static const fallible_t fallible = fallible_t();
nsFramesetSpec* specs = new (fallible) nsFramesetSpec[count];
if (!specs) {
*aSpecs = nullptr;
aNumSpecs = 0;
return NS_ERROR_OUT_OF_MEMORY;
}
// Pre-grab the compat mode; we may need it later in the loop.
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -1868,18 +1868,16 @@ nsTextEditorState::GetValue(nsAString& a
}
}
}
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
// lead to crashes (or worse) because we'd be initializing the editor
// before InsertText returns. This script blocker makes sure that
// PrepareEditor cannot be called prematurely.
nsAutoScriptBlocker scriptBlocker;
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -141,18 +141,16 @@ static_assert(kMinorSchemaVersion <= 0xF
const int32_t kSQLiteSchemaVersion =
int32_t((kMajorSchemaVersion << 4) + kMinorSchemaVersion);
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";
const char kFileManagerDirectoryNameSuffix[] = ".files";
const char kPrefIndexedDBEnabled[] = "dom.indexedDB.enabled";
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -459,17 +459,17 @@ StructuredCloneReadString(JSStructuredCl
{
uint32_t length;
if (!JS_ReadBytes(aReader, &length, sizeof(uint32_t))) {
NS_WARNING("Failed to read length!");
return false;
}
length = NativeEndian::swapFromLittleEndian(length);
- if (!aString.SetLength(length, fallible_t())) {
+ if (!aString.SetLength(length, fallible)) {
NS_WARNING("Out of memory?");
return false;
}
char* buffer = aString.BeginWriting();
if (!JS_ReadBytes(aReader, buffer, length)) {
NS_WARNING("Failed to read type!");
return false;
--- a/dom/media/fmp4/MP4Stream.h
+++ b/dom/media/fmp4/MP4Stream.h
@@ -6,17 +6,16 @@
#ifndef MP4_STREAM_H_
#define MP4_STREAM_H_
#include "mp4_demuxer/mp4_demuxer.h"
#include "MediaResource.h"
-#include "mozilla/fallible.h"
#include "mozilla/Maybe.h"
#include "mozilla/Monitor.h"
namespace mozilla {
class Monitor;
class MP4Stream : public mp4_demuxer::Stream {
@@ -72,17 +71,17 @@ private:
struct CacheBlock {
CacheBlock(int64_t aOffset, size_t aCount)
: mOffset(aOffset), mCount(aCount), mBuffer(nullptr) {}
int64_t mOffset;
size_t mCount;
bool Init()
{
- mBuffer = new ((fallible_t())) char[mCount];
+ mBuffer = new (fallible) char[mCount];
return !!mBuffer;
}
char* Buffer()
{
MOZ_ASSERT(mBuffer.get());
return mBuffer.get();
}
--- a/dom/media/webaudio/AudioDestinationNode.cpp
+++ b/dom/media/webaudio/AudioDestinationNode.cpp
@@ -57,19 +57,18 @@ public:
*aOutput = aInput;
// The output buffer is allocated lazily, on the rendering thread.
if (!mBufferAllocated) {
// These allocations might fail if content provides a huge number of
// channels or size, but it's OK since we'll deal with the failure
// gracefully.
if (mInputChannels.SetLength(mNumberOfChannels)) {
- static const fallible_t fallible = fallible_t();
for (uint32_t i = 0; i < mNumberOfChannels; ++i) {
- mInputChannels[i] = new(fallible) float[mLength];
+ mInputChannels[i] = new (fallible) float[mLength];
if (!mInputChannels[i]) {
mInputChannels.Clear();
break;
}
}
}
mBufferAllocated = true;
--- a/dom/media/webaudio/MediaBufferDecoder.cpp
+++ b/dom/media/webaudio/MediaBufferDecoder.cpp
@@ -328,23 +328,22 @@ MediaDecodeTask::FinishDecode()
SPEEX_RESAMPLER_QUALITY_DEFAULT, nullptr);
speex_resampler_skip_zeros(resampler);
resampledFrames += speex_resampler_get_output_latency(resampler);
}
// Allocate the channel buffers. Note that if we end up resampling, we may
// write fewer bytes than mResampledFrames to the output buffer, in which
// case mWriteIndex will tell us how many valid samples we have.
- static const fallible_t fallible = fallible_t();
bool memoryAllocationSuccess = true;
if (!mDecodeJob.mChannelBuffers.SetLength(channelCount)) {
memoryAllocationSuccess = false;
} else {
for (uint32_t i = 0; i < channelCount; ++i) {
- mDecodeJob.mChannelBuffers[i] = new(fallible) float[resampledFrames];
+ mDecodeJob.mChannelBuffers[i] = new (fallible) float[resampledFrames];
if (!mDecodeJob.mChannelBuffers[i]) {
memoryAllocationSuccess = false;
break;
}
}
}
if (!memoryAllocationSuccess) {
ReportFailureOnMainThread(WebAudioDecodeJob::UnknownError);
--- a/dom/plugins/base/nsPluginTags.cpp
+++ b/dom/plugins/base/nsPluginTags.cpp
@@ -254,17 +254,17 @@ static nsresult ConvertToUTF8(nsIUnicode
nsAFlatCString& aString)
{
int32_t numberOfBytes = aString.Length();
int32_t outUnicodeLen;
nsAutoString buffer;
nsresult rv = aUnicodeDecoder->GetMaxLength(aString.get(), numberOfBytes,
&outUnicodeLen);
NS_ENSURE_SUCCESS(rv, rv);
- if (!buffer.SetLength(outUnicodeLen, fallible_t()))
+ if (!buffer.SetLength(outUnicodeLen, fallible))
return NS_ERROR_OUT_OF_MEMORY;
rv = aUnicodeDecoder->Convert(aString.get(), &numberOfBytes,
buffer.BeginWriting(), &outUnicodeLen);
NS_ENSURE_SUCCESS(rv, rv);
buffer.SetLength(outUnicodeLen);
CopyUTF16toUTF8(buffer, aString);
return NS_OK;
--- a/dom/storage/DOMStorage.cpp
+++ b/dom/storage/DOMStorage.cpp
@@ -112,17 +112,17 @@ DOMStorage::SetItem(const nsAString& aKe
Telemetry::Accumulate(GetType() == LocalStorage
? Telemetry::LOCALDOMSTORAGE_KEY_SIZE_BYTES
: Telemetry::SESSIONDOMSTORAGE_KEY_SIZE_BYTES, aKey.Length());
Telemetry::Accumulate(GetType() == LocalStorage
? Telemetry::LOCALDOMSTORAGE_VALUE_SIZE_BYTES
: Telemetry::SESSIONDOMSTORAGE_VALUE_SIZE_BYTES, aData.Length());
nsString data;
- bool ok = data.Assign(aData, fallible_t());
+ bool ok = data.Assign(aData, fallible);
if (!ok) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
nsString old;
aRv = mCache->SetItem(this, aKey, data, old);
if (aRv.Failed()) {
--- a/dom/svg/SVGContentUtils.h
+++ b/dom/svg/SVGContentUtils.h
@@ -5,17 +5,16 @@
#ifndef MOZILLA_SVGCONTENTUTILS_H
#define MOZILLA_SVGCONTENTUTILS_H
// include math.h to pick up definition of M_ maths defines e.g. M_PI
#define _USE_MATH_DEFINES
#include <math.h>
-#include "mozilla/fallible.h"
#include "mozilla/gfx/2D.h" // for StrokeOptions
#include "mozilla/gfx/Matrix.h"
#include "mozilla/RangedPtr.h"
#include "nsError.h"
#include "nsStringFwd.h"
#include "gfx2DGlue.h"
class gfxTextContextPaint;
@@ -106,18 +105,17 @@ public:
* returned to the caller as a non-const pointer (so that the caller can
* initialize the values in the buffer, since mDashPattern is const).
*/
Float* InitDashPattern(size_t aDashCount) {
if (aDashCount <= MOZ_ARRAY_LENGTH(mSmallArray)) {
mDashPattern = mSmallArray;
return mSmallArray;
}
- static const mozilla::fallible_t fallible = mozilla::fallible_t();
- Float* nonConstArray = new (fallible) Float[aDashCount];
+ Float* nonConstArray = new (mozilla::fallible) Float[aDashCount];
mDashPattern = nonConstArray;
return nonConstArray;
}
void DiscardDashPattern() {
if (mDashPattern && mDashPattern != mSmallArray) {
delete [] mDashPattern;
}
mDashLength = 0;
--- a/dom/svg/SVGFEConvolveMatrixElement.cpp
+++ b/dom/svg/SVGFEConvolveMatrixElement.cpp
@@ -197,17 +197,16 @@ SVGFEConvolveMatrixElement::GetPrimitive
return failureDescription;
} else {
targetY = orderY / 2;
}
if (orderX > NS_SVG_OFFSCREEN_MAX_DIMENSION ||
orderY > NS_SVG_OFFSCREEN_MAX_DIMENSION)
return failureDescription;
- const fallible_t fallible = fallible_t();
nsAutoArrayPtr<float> kernel(new (fallible) float[orderX * orderY]);
if (!kernel)
return failureDescription;
for (uint32_t i = 0; i < kmLength; i++) {
kernel[kmLength - 1 - i] = kernelMatrix[i];
}
float divisor;
--- a/dom/xslt/base/txDouble.cpp
+++ b/dom/xslt/base/txDouble.cpp
@@ -174,17 +174,17 @@ void txDouble::toString(double aValue, n
else {
// trailing zeros, total length given by intDigits
length = intDigits;
}
if (aValue < 0)
++length;
// grow the string
uint32_t oldlength = aDest.Length();
- if (!aDest.SetLength(oldlength + length, mozilla::fallible_t()))
+ if (!aDest.SetLength(oldlength + length, mozilla::fallible))
return; // out of memory
nsAString::iterator dest;
aDest.BeginWriting(dest).advance(int32_t(oldlength));
if (aValue < 0) {
*dest = '-'; ++dest;
}
int i;
// leading zeros
--- a/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp
+++ b/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp
@@ -509,17 +509,17 @@ txXPathNodeUtils::appendNodeValue(const
return;
}
if (aNode.isDocument() ||
aNode.mNode->IsElement() ||
aNode.mNode->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT)) {
nsContentUtils::AppendNodeTextContent(aNode.mNode, true, aResult,
- mozilla::fallible_t());
+ mozilla::fallible);
return;
}
aNode.Content()->AppendTextTo(aResult);
}
/* static */
--- a/editor/libeditor/nsTextEditRules.cpp
+++ b/editor/libeditor/nsTextEditRules.cpp
@@ -1193,17 +1193,17 @@ nsTextEditRules::TruncateInsertionIfNeed
const nsAString *aInString,
nsAString *aOutString,
int32_t aMaxLength,
bool *aTruncated)
{
if (!aSelection || !aInString || !aOutString) {return NS_ERROR_NULL_POINTER;}
nsresult res = NS_OK;
- if (!aOutString->Assign(*aInString, mozilla::fallible_t())) {
+ if (!aOutString->Assign(*aInString, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (aTruncated) {
*aTruncated = false;
}
NS_ENSURE_STATE(mEditor);
if ((-1 != aMaxLength) && IsPlaintextEditor() && !mEditor->IsIMEComposing() )
--- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
@@ -571,17 +571,17 @@ mozInlineSpellWordUtil::BuildSoftText()
}
if (firstOffsetInNode < lastOffsetInNode) {
int32_t len = lastOffsetInNode - firstOffsetInNode;
mSoftTextDOMMapping.AppendElement(
DOMTextMapping(NodeOffset(node, firstOffsetInNode), mSoftText.Length(), len));
bool ok = textFragment->AppendTo(mSoftText, firstOffsetInNode, len,
- mozilla::fallible_t());
+ mozilla::fallible);
if (!ok) {
// probably out of memory, remove from mSoftTextDOMMapping
mSoftTextDOMMapping.RemoveElementAt(mSoftTextDOMMapping.Length() - 1);
exit = true;
}
}
firstOffsetInNode = 0;
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -669,18 +669,17 @@ MemoryTextureClient::ToSurfaceDescriptor
GetFormat());
return true;
}
bool
MemoryTextureClient::Allocate(uint32_t aSize)
{
MOZ_ASSERT(!mBuffer);
- static const fallible_t fallible = fallible_t();
- mBuffer = new(fallible) uint8_t[aSize];
+ mBuffer = new (fallible) uint8_t[aSize];
if (!mBuffer) {
NS_WARNING("Failed to allocate buffer");
return false;
}
GfxMemoryImageReporter::DidAlloc(mBuffer);
mBufSize = aSize;
return true;
}
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -1091,17 +1091,16 @@ gfxFT2FontList::AppendFacesFromOmnijarEn
}
nsZipItem *item = aArchive->GetItem(aEntryName.get());
NS_ASSERTION(item, "failed to find zip entry");
uint32_t bufSize = item->RealSize();
// We use fallible allocation here; if there's not enough RAM, we'll simply
// ignore the bundled fonts and fall back to the device's installed fonts.
- static const fallible_t fallible = fallible_t();
nsAutoArrayPtr<uint8_t> buf(new (fallible) uint8_t[bufSize]);
if (!buf) {
return;
}
nsZipCursor cursor(item, aArchive, buf, bufSize);
uint8_t* data = cursor.Copy(&bufSize);
NS_ASSERTION(data && bufSize == item->RealSize(),
--- a/image/decoders/icon/win/nsIconChannel.cpp
+++ b/image/decoders/icon/win/nsIconChannel.cpp
@@ -485,17 +485,17 @@ GetColorTableSize(BITMAPINFOHEADER* aHea
// Given a header and a size, creates a freshly allocated BITMAPINFO structure.
// It is the caller's responsibility to null-check and delete the structure.
static BITMAPINFO*
CreateBitmapInfo(BITMAPINFOHEADER* aHeader, size_t aColorTableSize)
{
BITMAPINFO* bmi = (BITMAPINFO*) ::operator new(sizeof(BITMAPINFOHEADER) +
aColorTableSize,
- mozilla::fallible_t());
+ mozilla::fallible);
if (bmi) {
memcpy(bmi, aHeader, sizeof(BITMAPINFOHEADER));
memset(bmi->bmiColors, 0, aColorTableSize);
}
return bmi;
}
nsresult
--- a/image/encoders/bmp/nsBMPEncoder.cpp
+++ b/image/encoders/bmp/nsBMPEncoder.cpp
@@ -180,17 +180,16 @@ nsBMPEncoder::AddImageFrame(const uint8_
// validate input format
if (aInputFormat != INPUT_FORMAT_RGB &&
aInputFormat != INPUT_FORMAT_RGBA &&
aInputFormat != INPUT_FORMAT_HOSTARGB) {
return NS_ERROR_INVALID_ARG;
}
- static fallible_t fallible = fallible_t();
nsAutoArrayPtr<uint8_t> row(new (fallible)
uint8_t[mBMPInfoHeader.width *
BytesPerPixel(mBMPInfoHeader.bpp)]);
if (!row) {
return NS_ERROR_OUT_OF_MEMORY;
}
// write each row: if we add more input formats, we may want to
--- a/image/src/SourceBuffer.h
+++ b/image/src/SourceBuffer.h
@@ -267,17 +267,16 @@ private:
class Chunk
{
public:
explicit Chunk(size_t aCapacity)
: mCapacity(aCapacity)
, mLength(0)
{
MOZ_ASSERT(aCapacity > 0, "Creating zero-capacity chunk");
- static const fallible_t fallible = fallible_t();
mData = new (fallible) char[mCapacity];
}
~Chunk() { delete[] mData; }
Chunk(Chunk&& aOther)
: mCapacity(aOther.mCapacity)
, mLength(aOther.mLength)
--- a/intl/uconv/nsScriptableUConv.cpp
+++ b/intl/uconv/nsScriptableUConv.cpp
@@ -60,17 +60,17 @@ NS_IMETHODIMP
nsScriptableUnicodeConverter::ConvertFromUnicode(const nsAString& aSrc,
nsACString& _retval)
{
int32_t len;
char* str;
nsresult rv = ConvertFromUnicodeWithLength(aSrc, &len, &str);
if (NS_SUCCEEDED(rv)) {
// No Adopt on nsACString :(
- if (!_retval.Assign(str, len, mozilla::fallible_t())) {
+ if (!_retval.Assign(str, len, mozilla::fallible)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
moz_free(str);
}
return rv;
}
nsresult
@@ -109,17 +109,17 @@ nsScriptableUnicodeConverter::Finish(nsA
_retval.Truncate();
return NS_OK;
}
int32_t len;
char* str;
nsresult rv = FinishWithLength(&str, &len);
if (NS_SUCCEEDED(rv)) {
// No Adopt on nsACString :(
- if (!_retval.Assign(str, len, mozilla::fallible_t())) {
+ if (!_retval.Assign(str, len, mozilla::fallible)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
moz_free(str);
}
return rv;
}
/* AString ConvertToUnicode (in ACString src); */
@@ -155,17 +155,17 @@ nsScriptableUnicodeConverter::ConvertFro
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;
rv = mDecoder->Convert(reinterpret_cast<const char*>(aData),
&inLength, buf, &outLength);
if (NS_SUCCEEDED(rv))
{
buf[outLength] = 0;
- if (!_retval.Assign(buf, outLength, mozilla::fallible_t())) {
+ if (!_retval.Assign(buf, outLength, mozilla::fallible)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
moz_free(buf);
return rv;
}
return NS_ERROR_FAILURE;
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -2215,17 +2215,17 @@ void nsBidiPresUtils::CopyLogicalToVisua
nsAString& aDest,
nsBidiLevel aBaseDirection,
bool aOverride)
{
aDest.SetLength(0);
uint32_t srcLength = aSource.Length();
if (srcLength == 0)
return;
- if (!aDest.SetLength(srcLength, fallible_t())) {
+ if (!aDest.SetLength(srcLength, fallible)) {
return;
}
nsAString::const_iterator fromBegin, fromEnd;
nsAString::iterator toBegin;
aSource.BeginReading(fromBegin);
aSource.EndReading(fromEnd);
aDest.BeginWriting(toBegin);
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1004,17 +1004,16 @@ void MediaPipelineTransmit::PipelineList
if (!enabled_ || chunk.mFrame.GetForceBlack()) {
gfx::IntSize size = img->GetSize();
uint32_t yPlaneLen = YSIZE(size.width, size.height);
uint32_t cbcrPlaneLen = 2 * CRSIZE(size.width, size.height);
uint32_t length = yPlaneLen + cbcrPlaneLen;
// Send a black image.
nsAutoArrayPtr<uint8_t> pixelData;
- static const fallible_t fallible = fallible_t();
pixelData = new (fallible) uint8_t[length];
if (pixelData) {
// YCrCb black = 0x10 0x80 0x80
memset(pixelData, 0x10, yPlaneLen);
// Fill Cb/Cr planes
memset(pixelData + yPlaneLen, 0x80, cbcrPlaneLen);
MOZ_MTLOG(ML_DEBUG, "Sending a black video frame");
new file mode 100644
--- /dev/null
+++ b/memory/fallible/fallible.cpp
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "fallible.h"
+
+namespace mozilla {
+
+const fallible_t fallible = {};
+
+}
rename from memory/mozalloc/fallible.h
rename to memory/fallible/fallible.h
--- a/memory/mozalloc/fallible.h
+++ b/memory/fallible/fallible.h
@@ -1,14 +1,67 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_fallible_h
#define mozilla_fallible_h
+#if defined(__cplusplus)
+
+/* Explicit fallible allocation
+ *
+ * Memory allocation (normally) defaults to abort in case of failed
+ * allocation. That is, it never returns NULL, and crashes instead.
+ *
+ * Code can explicitely request for fallible memory allocation thanks
+ * to the declarations below.
+ *
+ * The typical use of the mozilla::fallible const is with placement new,
+ * like the following:
+ *
+ * foo = new (mozilla::fallible) Foo();
+ *
+ * The following forms, or derivatives, are also possible but deprecated:
+ *
+ * foo = new ((mozilla::fallible_t())) Foo();
+ *
+ * const mozilla::fallible_t fallible = mozilla::fallible_t();
+ * bar = new (f) Bar();
+ *
+ * It is also possible to declare method overloads with fallible allocation
+ * alternatives, like so:
+ *
+ * class Foo {
+ * public:
+ * void Method(void *);
+ * void Method(void *, const mozilla::fallible_t&);
+ * };
+ *
+ * Foo foo;
+ * foo.Method(nullptr, mozilla::fallible);
+ *
+ * If that last method call is in a method that itself takes a const
+ * fallible_t& argument, it is recommended to propagate that argument
+ * instead of using mozilla::fallible:
+ *
+ * void Func(Foo &foo, const mozilla::fallible_t& aFallible) {
+ * foo.Method(nullptr, aFallible);
+ * }
+ *
+ */
namespace mozilla {
struct fallible_t { };
+/* This symbol is kept unexported, such that in corner cases where the
+ * compiler can't remove its use (essentially, cross compilation-unit
+ * calls), the smallest machine code is used.
+ * Depending how the linker packs symbols, it will consume between 1 and
+ * 8 bytes of read-only data in each executable or shared library, but
+ * only in those where it's actually not optimized out by the compiler.
+ */
+extern const fallible_t fallible;
+
} // namespace mozilla
+#endif
#endif // mozilla_fallible_h
new file mode 100644
--- /dev/null
+++ b/memory/fallible/moz.build
@@ -0,0 +1,30 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+EXPORTS.mozilla += [
+ 'fallible.h',
+]
+
+Library('fallible')
+
+SOURCES += [
+ 'fallible.cpp',
+]
+
+if CONFIG['_MSC_VER']:
+ # MSVC normally adds linker directives relative to the CRT in a .drectve
+ # section in .obj files. Then, when linking objects, it adds those
+ # directives as if they were given as command line arguments. This can
+ # lead to trying to include link CRTs because different objects are
+ # compiled with different CRT options (i.e. -MT vs. -MD), and failing.
+ # The only source in this directory doesn't expose anything that depends
+ # on a CRT, so it doesn't need to be bound to a specific one.
+ # Adding the -Zl option makes MSVC not store linker directives in the
+ # object. This allows to link fallible.obj to binaries independently of
+ # the CRT they use.
+ CXXFLAGS += [
+ '-Zl',
+ ]
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/moz.build
@@ -1,17 +1,16 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
NO_VISIBILITY_FLAGS = True
EXPORTS.mozilla += [
- 'fallible.h',
'mozalloc.h',
'mozalloc_abort.h',
'mozalloc_oom.h',
]
if CONFIG['MOZ_MSVC_STL_WRAP__RAISE'] or CONFIG['MOZ_MSVC_STL_WRAP__Throw']:
build_msvc_wrappers = 1
else:
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -1152,17 +1152,17 @@ nsZipItemPtr_base::nsZipItemPtr_base(nsZ
nsZipItem* item = aZip->GetItem(aEntryName);
if (!item)
return;
uint32_t size = 0;
if (item->Compression() == DEFLATED) {
size = item->RealSize();
- mAutoBuf = new ((fallible_t())) uint8_t[size];
+ mAutoBuf = new (fallible) uint8_t[size];
if (!mAutoBuf) {
return;
}
}
nsZipCursor cursor(item, aZip, mAutoBuf, size, doCRC);
mReturnBuf = cursor.Read(&mReadlen);
if (!mReturnBuf) {
--- a/modules/libpref/nsPrefBranch.cpp
+++ b/modules/libpref/nsPrefBranch.cpp
@@ -325,17 +325,17 @@ NS_IMETHODIMP nsPrefBranch::GetComplexVa
if (aType.Equals(NS_GET_IID(nsISupportsString))) {
nsCOMPtr<nsISupportsString> theString(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
// Debugging to see why we end up with very long strings here with
// some addons, see bug 836263.
nsAutoString wdata;
- if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible_t())) {
+ if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible)) {
#ifdef MOZ_CRASHREPORTER
nsCOMPtr<nsICrashReporter> cr =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (cr) {
cr->AnnotateCrashReport(NS_LITERAL_CSTRING("bug836263-size"),
nsPrintfCString("%x", utf8String.Length()));
cr->RegisterAppMemory(uint64_t(utf8String.BeginReading()),
std::min(0x1000U, utf8String.Length()));
--- a/modules/libpref/prefapi.cpp
+++ b/modules/libpref/prefapi.cpp
@@ -142,17 +142,17 @@ enum {
static nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, uint32_t flags);
#define PREF_HASHTABLE_INITIAL_LENGTH 1024
nsresult PREF_Init()
{
if (!gHashTable.IsInitialized()) {
if (!PL_DHashTableInit(&gHashTable, &pref_HashTableOps,
- sizeof(PrefHashEntry), fallible_t(),
+ sizeof(PrefHashEntry), fallible,
PREF_HASHTABLE_INITIAL_LENGTH)) {
return NS_ERROR_OUT_OF_MEMORY;
}
PL_INIT_ARENA_POOL(&gPrefNameArena, "PrefNameArena",
PREFNAME_ARENA_SIZE);
}
return NS_OK;
--- a/moz.build
+++ b/moz.build
@@ -38,16 +38,17 @@ if not CONFIG['LIBXUL_SDK']:
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
DIRS += ['other-licenses/android']
if CONFIG['MOZ_MEMORY']:
DIRS += ['memory']
DIRS += [
'mozglue',
+ 'memory/fallible',
'memory/mozalloc',
'memory/volatile',
]
if not CONFIG['JS_STANDALONE']:
DIRS += ['xpcom/xpidl']
if CONFIG['COMPILE_ENVIRONMENT'] and not CONFIG['LIBXUL_SDK']:
--- a/netwerk/base/nsBufferedStreams.cpp
+++ b/netwerk/base/nsBufferedStreams.cpp
@@ -66,18 +66,17 @@ nsBufferedStream::Init(nsISupports* stre
{
NS_ASSERTION(stream, "need to supply a stream");
NS_ASSERTION(mStream == nullptr, "already inited");
mStream = stream;
NS_IF_ADDREF(mStream);
mBufferSize = bufferSize;
mBufferStartOffset = 0;
mCursor = 0;
- const mozilla::fallible_t fallible = mozilla::fallible_t();
- mBuffer = new (fallible) char[bufferSize];
+ mBuffer = new (mozilla::fallible) char[bufferSize];
if (mBuffer == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
nsresult
nsBufferedStream::Close()
{
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -1541,17 +1541,17 @@ NS_ReadInputStreamToBuffer(nsIInputStrea
// external code can't see fallible_t
#ifdef MOZILLA_INTERNAL_API
inline nsresult
NS_ReadInputStreamToString(nsIInputStream *aInputStream,
nsACString &aDest,
uint32_t aCount)
{
- if (!aDest.SetLength(aCount, mozilla::fallible_t()))
+ if (!aDest.SetLength(aCount, mozilla::fallible))
return NS_ERROR_OUT_OF_MEMORY;
void* dest = aDest.BeginWriting();
return NS_ReadInputStreamToBuffer(aInputStream, &dest, aCount);
}
#endif
inline nsresult
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -583,17 +583,17 @@ nsStandardURL::BuildNormalizedSpec(const
else
approxLen += mHost.mLen;
}
//
// generate the normalized URL string
//
// approxLen should be correct or 1 high
- if (!mSpec.SetLength(approxLen+1, mozilla::fallible_t())) // buf needs a trailing '\0' below
+ if (!mSpec.SetLength(approxLen+1, mozilla::fallible)) // buf needs a trailing '\0' below
return NS_ERROR_OUT_OF_MEMORY;
char *buf;
mSpec.BeginWriting(buf);
uint32_t i = 0;
if (mScheme.mLen > 0) {
i = AppendSegmentToBuf(buf, i, spec, mScheme);
net_ToLowerCase(buf + mScheme.mPos, mScheme.mLen);
--- a/netwerk/base/nsUnicharStreamLoader.cpp
+++ b/netwerk/base/nsUnicharStreamLoader.cpp
@@ -21,17 +21,17 @@ using mozilla::dom::EncodingUtils;
NS_IMETHODIMP
nsUnicharStreamLoader::Init(nsIUnicharStreamLoaderObserver *aObserver)
{
NS_ENSURE_ARG_POINTER(aObserver);
mObserver = aObserver;
- if (!mRawData.SetCapacity(SNIFFING_BUFFER_SIZE, fallible_t()))
+ if (!mRawData.SetCapacity(SNIFFING_BUFFER_SIZE, fallible))
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
nsresult
nsUnicharStreamLoader::Create(nsISupports *aOuter,
REFNSIID aIID,
@@ -209,17 +209,17 @@ nsUnicharStreamLoader::WriteSegmentFun(n
nsUnicharStreamLoader* self = static_cast<nsUnicharStreamLoader*>(aClosure);
uint32_t haveRead = self->mBuffer.Length();
int32_t srcLen = aCount;
int32_t dstLen;
self->mDecoder->GetMaxLength(aSegment, srcLen, &dstLen);
uint32_t capacity = haveRead + dstLen;
- if (!self->mBuffer.SetCapacity(capacity, fallible_t())) {
+ if (!self->mBuffer.SetCapacity(capacity, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
DebugOnly<nsresult> rv =
self->mDecoder->Convert(aSegment,
&srcLen,
self->mBuffer.BeginWriting() + haveRead,
&dstLen);
--- a/netwerk/cache/nsCacheEntry.cpp
+++ b/netwerk/cache/nsCacheEntry.cpp
@@ -400,17 +400,17 @@ nsCacheEntryHashTable::~nsCacheEntryHash
nsresult
nsCacheEntryHashTable::Init()
{
nsresult rv = NS_OK;
initialized = PL_DHashTableInit(&table, &ops,
sizeof(nsCacheEntryHashTableEntry),
- fallible_t(), 256);
+ fallible, 256);
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
return rv;
}
void
nsCacheEntryHashTable::Shutdown()
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -961,17 +961,17 @@ nsOfflineCacheDevice::UpdateEntry(nsCach
NS_ENSURE_SUCCESS(rv, rv);
rv = entry->SetMetaDataElement("security-info", info.get());
NS_ENSURE_SUCCESS(rv, rv);
}
nsCString metaDataBuf;
uint32_t mdSize = entry->MetaDataSize();
- if (!metaDataBuf.SetLength(mdSize, fallible_t()))
+ if (!metaDataBuf.SetLength(mdSize, fallible))
return NS_ERROR_OUT_OF_MEMORY;
char *md = metaDataBuf.BeginWriting();
entry->FlattenMetaData(md, mdSize);
nsOfflineCacheRecord rec;
rec.metaData = (const uint8_t *) md;
rec.metaDataLen = mdSize;
rec.dataSize = entry->DataSize();
--- a/netwerk/protocol/http/nsHttp.cpp
+++ b/netwerk/protocol/http/nsHttp.cpp
@@ -101,17 +101,17 @@ nsHttp::CreateAtomTable()
if (!sLock) {
sLock = new Mutex("nsHttp.sLock");
}
// The initial length for this table is a value greater than the number of
// known atoms (NUM_HTTP_ATOMS) because we expect to encounter a few random
// headers right off the bat.
if (!PL_DHashTableInit(&sAtomTable, &ops, sizeof(PLDHashEntryStub),
- fallible_t(), NUM_HTTP_ATOMS + 10)) {
+ fallible, NUM_HTTP_ATOMS + 10)) {
return NS_ERROR_OUT_OF_MEMORY;
}
// fill the table with our known atoms
const char *const atoms[] = {
#define HTTP_ATOM(_name, _value) nsHttp::_name._val,
#include "nsHttpAtomList.h"
#undef HTTP_ATOM
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -1604,17 +1604,17 @@ WebSocketChannel::ProcessInput(uint8_t *
if (NS_FAILED(rv)) {
return rv;
}
LOG(("WebSocketChannel:: message successfully inflated "
"[origLength=%d, newLength=%d]\n", payloadLength,
utf8Data.Length()));
} else {
if (!utf8Data.Assign((const char *)payload, payloadLength,
- mozilla::fallible_t())) {
+ mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Section 8.1 says to fail connection if invalid utf-8 in text message
if (!IsUTF8(utf8Data, false)) {
LOG(("WebSocketChannel:: text frame invalid utf-8\n"));
return NS_ERROR_CANNOT_CONVERT_DATA;
@@ -1714,17 +1714,17 @@ WebSocketChannel::ProcessInput(uint8_t *
if (NS_FAILED(rv)) {
return rv;
}
LOG(("WebSocketChannel:: message successfully inflated "
"[origLength=%d, newLength=%d]\n", payloadLength,
binaryData.Length()));
} else {
if (!binaryData.Assign((const char *)payload, payloadLength,
- mozilla::fallible_t())) {
+ mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
mTargetThread->Dispatch(
new CallOnMessageAvailable(this, binaryData, binaryData.Length()),
NS_DISPATCH_NORMAL);
// To add the header to 'Networking Dashboard' log
--- a/netwerk/streamconv/converters/nsDirIndexParser.cpp
+++ b/netwerk/streamconv/converters/nsDirIndexParser.cpp
@@ -328,17 +328,17 @@ nsDirIndexParser::OnDataAvailable(nsIReq
uint32_t aCount) {
if (aCount < 1)
return NS_OK;
int32_t len = mBuf.Length();
// Ensure that our mBuf has capacity to hold the data we're about to
// read.
- if (!mBuf.SetLength(len + aCount, fallible_t()))
+ if (!mBuf.SetLength(len + aCount, fallible))
return NS_ERROR_OUT_OF_MEMORY;
// Now read the data into our buffer.
nsresult rv;
uint32_t count;
rv = aStream->Read(mBuf.BeginWriting() + len, aCount, &count);
if (NS_FAILED(rv)) return rv;
--- a/parser/html/nsHtml5OwningUTF16Buffer.cpp
+++ b/parser/html/nsHtml5OwningUTF16Buffer.cpp
@@ -34,23 +34,22 @@ nsHtml5OwningUTF16Buffer::~nsHtml5Owning
tail.swap(tmp);
}
}
// static
already_AddRefed<nsHtml5OwningUTF16Buffer>
nsHtml5OwningUTF16Buffer::FalliblyCreate(int32_t aLength)
{
- const mozilla::fallible_t fallible = mozilla::fallible_t();
- char16_t* newBuf = new (fallible) char16_t[aLength];
+ char16_t* newBuf = new (mozilla::fallible) char16_t[aLength];
if (!newBuf) {
return nullptr;
}
nsRefPtr<nsHtml5OwningUTF16Buffer> newObj =
- new (fallible) nsHtml5OwningUTF16Buffer(newBuf);
+ new (mozilla::fallible) nsHtml5OwningUTF16Buffer(newBuf);
if (!newObj) {
delete[] newBuf;
return nullptr;
}
return newObj.forget();
}
void
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -766,18 +766,17 @@ nsHtml5StreamParser::SniffStreamBytes(co
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
}
}
if (!mSniffingBuffer) {
- const mozilla::fallible_t fallible = mozilla::fallible_t();
- mSniffingBuffer = new (fallible)
+ mSniffingBuffer = new (mozilla::fallible)
uint8_t[NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE];
if (!mSniffingBuffer) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
memcpy(mSniffingBuffer + mSniffingLength, aFromSegment, aCount);
mSniffingLength += aCount;
*aWriteCount = aCount;
@@ -1141,18 +1140,17 @@ nsHtml5StreamParser::OnDataAvailable(nsI
if (NS_FAILED(rv = mExecutor->IsBroken())) {
return rv;
}
NS_ASSERTION(mRequest == aRequest, "Got data on wrong stream.");
uint32_t totalRead;
// Main thread to parser thread dispatch requires copying to buffer first.
if (NS_IsMainThread()) {
- const mozilla::fallible_t fallible = mozilla::fallible_t();
- nsAutoArrayPtr<uint8_t> data(new (fallible) uint8_t[aLength]);
+ nsAutoArrayPtr<uint8_t> data(new (mozilla::fallible) uint8_t[aLength]);
if (!data) {
return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
}
rv = aInStream->Read(reinterpret_cast<char*>(data.get()),
aLength, &totalRead);
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(totalRead <= aLength, "Read more bytes than were available?");
--- a/parser/htmlparser/nsHTMLEntities.cpp
+++ b/parser/htmlparser/nsHTMLEntities.cpp
@@ -80,22 +80,22 @@ static const EntityNode gEntityArray[] =
#define NS_HTML_ENTITY_COUNT ((int32_t)ArrayLength(gEntityArray))
nsresult
nsHTMLEntities::AddRefTable(void)
{
if (!gTableRefCnt) {
if (!PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
sizeof(EntityNodeEntry),
- fallible_t(), NS_HTML_ENTITY_COUNT)) {
+ fallible, NS_HTML_ENTITY_COUNT)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
sizeof(EntityNodeEntry),
- fallible_t(), NS_HTML_ENTITY_COUNT)) {
+ fallible, NS_HTML_ENTITY_COUNT)) {
PL_DHashTableFinish(&gEntityToUnicode);
return NS_ERROR_OUT_OF_MEMORY;
}
for (const EntityNode *node = gEntityArray,
*node_end = ArrayEnd(gEntityArray);
node < node_end; ++node) {
// add to Entity->Unicode table
--- a/parser/htmlparser/nsScannerString.cpp
+++ b/parser/htmlparser/nsScannerString.cpp
@@ -467,17 +467,17 @@ copy_multifragment_string( nsScannerIter
}
void
CopyUnicodeTo( const nsScannerIterator& aSrcStart,
const nsScannerIterator& aSrcEnd,
nsAString& aDest )
{
nsAString::iterator writer;
- if (!aDest.SetLength(Distance(aSrcStart, aSrcEnd), mozilla::fallible_t())) {
+ if (!aDest.SetLength(Distance(aSrcStart, aSrcEnd), mozilla::fallible)) {
aDest.Truncate();
return; // out of memory
}
aDest.BeginWriting(writer);
nsScannerIterator fromBegin(aSrcStart);
copy_multifragment_string(fromBegin, aSrcEnd, writer);
}
@@ -500,17 +500,17 @@ AppendUnicodeTo( const nsScannerIterator
void
AppendUnicodeTo( const nsScannerIterator& aSrcStart,
const nsScannerIterator& aSrcEnd,
nsAString& aDest )
{
nsAString::iterator writer;
uint32_t oldLength = aDest.Length();
- if (!aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd), mozilla::fallible_t()))
+ if (!aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd), mozilla::fallible))
return; // out of memory
aDest.BeginWriting(writer).advance(oldLength);
nsScannerIterator fromBegin(aSrcStart);
copy_multifragment_string(fromBegin, aSrcEnd, writer);
}
bool
--- a/security/manager/ssl/src/nsCertTree.cpp
+++ b/security/manager/ssl/src/nsCertTree.cpp
@@ -177,17 +177,17 @@ void nsCertTree::ClearCompareHash()
PL_DHashTableFinish(&mCompareCache);
}
}
nsresult nsCertTree::InitCompareHash()
{
ClearCompareHash();
if (!PL_DHashTableInit(&mCompareCache, &gMapOps,
- sizeof(CompareCacheHashEntryPtr), fallible_t(), 64)) {
+ sizeof(CompareCacheHashEntryPtr), fallible, 64)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
nsCertTree::~nsCertTree()
{
ClearCompareHash();
--- a/services/crypto/component/nsSyncJPAKE.cpp
+++ b/services/crypto/component/nsSyncJPAKE.cpp
@@ -11,17 +11,17 @@
#include <secmodt.h>
#include <secport.h>
#include <secerr.h>
#include <nsDebug.h>
#include <nsError.h>
#include <base64.h>
#include <nsString.h>
-using mozilla::fallible_t;
+using mozilla::fallible;
static bool
hex_from_2char(const unsigned char *c2, unsigned char *byteval)
{
int i;
unsigned char offset;
*byteval = 0;
for (i=0; i<2; i++) {
@@ -68,17 +68,17 @@ fromHexString(const nsACString & str, un
}
return NS_OK;
}
static bool
toHexString(const unsigned char * str, unsigned len, nsACString & out)
{
static const char digits[] = "0123456789ABCDEF";
- if (!out.SetCapacity(2 * len, fallible_t()))
+ if (!out.SetCapacity(2 * len, fallible))
return false;
out.SetLength(0);
for (unsigned i = 0; i < len; ++i) {
out.Append(digits[str[i] >> 4]);
out.Append(digits[str[i] & 0x0f]);
}
return true;
}
@@ -296,17 +296,17 @@ NS_IMETHODIMP nsSyncJPAKE::Round2(const
static nsresult
setBase64(const unsigned char * data, unsigned len, nsACString & out)
{
nsresult rv = NS_OK;
const char * base64 = BTOA_DataToAscii(data, len);
if (base64 != nullptr) {
size_t len = PORT_Strlen(base64);
- if (out.SetCapacity(len, fallible_t())) {
+ if (out.SetCapacity(len, fallible)) {
out.SetLength(0);
out.Append(base64, len);
PORT_Free((void*) base64);
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
--- a/toolkit/components/downloads/SQLFunctions.cpp
+++ b/toolkit/components/downloads/SQLFunctions.cpp
@@ -56,17 +56,17 @@ Base64urlEncode(const uint8_t* aBytes,
uint32_t aNumBytes,
nsCString& _result)
{
// SetLength does not set aside space for null termination. PL_Base64Encode
// will not null terminate, however, nsCStrings must be null terminated. As a
// result, we set the capacity to be one greater than what we need, and the
// length to our desired length.
uint32_t length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math.
- NS_ENSURE_TRUE(_result.SetCapacity(length + 1, mozilla::fallible_t()),
+ NS_ENSURE_TRUE(_result.SetCapacity(length + 1, mozilla::fallible),
NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes,
_result.BeginWriting());
// base64url encoding is defined in RFC 4648. It replaces the last two
// alphabet characters of base64 encoding with '-' and '_' respectively.
_result.ReplaceChar('+', '-');
--- a/toolkit/components/places/Helpers.cpp
+++ b/toolkit/components/places/Helpers.cpp
@@ -207,17 +207,17 @@ Base64urlEncode(const uint8_t* aBytes,
uint32_t aNumBytes,
nsCString& _result)
{
// SetLength does not set aside space for null termination. PL_Base64Encode
// will not null terminate, however, nsCStrings must be null terminated. As a
// result, we set the capacity to be one greater than what we need, and the
// length to our desired length.
uint32_t length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math.
- NS_ENSURE_TRUE(_result.SetCapacity(length + 1, fallible_t()),
+ NS_ENSURE_TRUE(_result.SetCapacity(length + 1, fallible),
NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes,
_result.BeginWriting());
// base64url encoding is defined in RFC 4648. It replaces the last two
// alphabet characters of base64 encoding with '-' and '_' respectively.
_result.ReplaceChar('+', '-');
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -1788,17 +1788,17 @@ TelemetryImpl::NewKeyedHistogram(const n
nsresult rv = CheckHistogramArguments(histogramType, min, max, bucketCount, optArgCount == 3);
if (NS_FAILED(rv)) {
return rv;
}
KeyedHistogram* keyed = new KeyedHistogram(name, expiration, histogramType,
min, max, bucketCount);
- if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible_t()))) {
+ if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible))) {
delete keyed;
return NS_ERROR_OUT_OF_MEMORY;
}
return WrapAndReturnKeyedHistogram(keyed, cx, ret);
}
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -1684,17 +1684,17 @@ nsIMM32Handler::GetCompositionString(con
nsAString& aCompositionString) const
{
aCompositionString.Truncate();
// Retrieve the size of the required output buffer.
long lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex, nullptr, 0);
if (lRtn < 0 ||
!aCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1,
- mozilla::fallible_t())) {
+ mozilla::fallible)) {
PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
("IMM32: GetCompositionString, FAILED by OOM\n"));
return; // Error or out of memory.
}
// Actually retrieve the composition string information.
lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex,
(LPVOID)aCompositionString.BeginWriting(),
@@ -1751,17 +1751,17 @@ bool
nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage,
nsACString& aANSIStr)
{
int len = ::WideCharToMultiByte(aCodePage, 0,
(LPCWSTR)aStr.get(), aStr.Length(),
nullptr, 0, nullptr, nullptr);
NS_ENSURE_TRUE(len >= 0, false);
- if (!aANSIStr.SetLength(len, mozilla::fallible_t())) {
+ if (!aANSIStr.SetLength(len, mozilla::fallible)) {
PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
("IMM32: ConvertToANSIString, FAILED by OOM\n"));
return false;
}
::WideCharToMultiByte(aCodePage, 0, (LPCWSTR)aStr.get(), aStr.Length(),
(LPSTR)aANSIStr.BeginWriting(), len, nullptr, nullptr);
return true;
}
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1352,17 +1352,17 @@ private:
void DoWalk(nsDeque& aQueue);
void CheckedPush(nsDeque& aQueue, PtrInfo* aPi)
{
if (!aPi) {
MOZ_CRASH();
}
- if (!aQueue.Push(aPi, fallible_t())) {
+ if (!aQueue.Push(aPi, fallible)) {
mVisitor.Failed();
}
}
public:
void Walk(PtrInfo* aPi);
void WalkFromRoots(CCGraph& aGraph);
// copy-constructing the visitor should be cheap, and less
--- a/xpcom/ds/nsStaticNameTable.cpp
+++ b/xpcom/ds/nsStaticNameTable.cpp
@@ -134,17 +134,17 @@ nsStaticCaseInsensitiveNameTable::Init(c
mNameArray = (nsDependentCString*)
nsMemory::Alloc(aLength * sizeof(nsDependentCString));
if (!mNameArray) {
return false;
}
if (!PL_DHashTableInit(&mNameTable, &nametable_CaseInsensitiveHashTableOps,
- sizeof(NameTableEntry), fallible_t(),
+ sizeof(NameTableEntry), fallible,
aLength)) {
return false;
}
for (int32_t index = 0; index < aLength; ++index) {
const char* raw = aNames[index];
#ifdef DEBUG
{
--- a/xpcom/ds/nsSupportsPrimitives.cpp
+++ b/xpcom/ds/nsSupportsPrimitives.cpp
@@ -2,18 +2,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsSupportsPrimitives.h"
#include "nsMemory.h"
#include "prprf.h"
-using mozilla::fallible_t;
-
/***************************************************************************/
NS_IMPL_ISUPPORTS(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
nsSupportsIDImpl::nsSupportsIDImpl()
: mData(nullptr)
{
}
@@ -102,17 +100,17 @@ nsSupportsCStringImpl::ToString(char** a
}
return NS_OK;
}
NS_IMETHODIMP
nsSupportsCStringImpl::SetData(const nsACString& aData)
{
- bool ok = mData.Assign(aData, fallible_t());
+ bool ok = mData.Assign(aData, mozilla::fallible);
if (!ok) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
/*****************************************************************************
* nsSupportsStringImpl
@@ -147,17 +145,17 @@ nsSupportsStringImpl::ToString(char16_t*
}
return NS_OK;
}
NS_IMETHODIMP
nsSupportsStringImpl::SetData(const nsAString& aData)
{
- bool ok = mData.Assign(aData, fallible_t());
+ bool ok = mData.Assign(aData, mozilla::fallible);
if (!ok) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
/***************************************************************************/
--- a/xpcom/glue/moz.build
+++ b/xpcom/glue/moz.build
@@ -109,8 +109,13 @@ if CONFIG['_MSC_VER']:
LOCAL_INCLUDES += [
'../build',
]
if CONFIG['ENABLE_TESTS']:
DIRS += ['tests/gtest']
FAIL_ON_WARNINGS = True
+
+# Include fallible for third party code using the xpcom glue
+USE_LIBS += [
+ 'fallible',
+]
--- a/xpcom/glue/nomozalloc/moz.build
+++ b/xpcom/glue/nomozalloc/moz.build
@@ -37,8 +37,13 @@ LOCAL_INCLUDES += [
# avoids "msvcrp" and assembly dependencies from creeping into the directives
# for this library on Windows.
USE_STATIC_LIBS = True
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
+
+# Include fallible for third party code using the xpcom glue
+USE_LIBS += [
+ 'fallible',
+]
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -118,17 +118,17 @@ public:
/**
* put a new value for the associated key
* @param aKey the key to put
* @param aData the new data
* @return always true, unless memory allocation failed
*/
void Put(KeyType aKey, const UserDataType& aData)
{
- if (!Put(aKey, aData, fallible_t())) {
+ if (!Put(aKey, aData, mozilla::fallible)) {
NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
}
}
NS_WARN_UNUSED_RESULT bool Put(KeyType aKey, const UserDataType& aData,
const fallible_t&)
{
EntryType* ent = this->PutEntry(aKey);
--- a/xpcom/glue/nsDeque.h
+++ b/xpcom/glue/nsDeque.h
@@ -79,31 +79,31 @@ public:
/**
* Appends new member at the end of the deque.
*
* @param item to store in deque
*/
void Push(void* aItem)
{
- if (!Push(aItem, fallible_t())) {
+ if (!Push(aItem, mozilla::fallible)) {
NS_ABORT_OOM(mSize * sizeof(void*));
}
}
NS_WARN_UNUSED_RESULT bool Push(void* aItem, const fallible_t&);
/**
* Inserts new member at the front of the deque.
*
* @param item to store in deque
*/
void PushFront(void* aItem)
{
- if (!PushFront(aItem, fallible_t())) {
+ if (!PushFront(aItem, mozilla::fallible)) {
NS_ABORT_OOM(mSize * sizeof(void*));
}
}
NS_WARN_UNUSED_RESULT bool PushFront(void* aItem, const fallible_t&);
/**
* Remove and return the last item in the container.
--- a/xpcom/glue/nsRefPtrHashtable.h
+++ b/xpcom/glue/nsRefPtrHashtable.h
@@ -142,17 +142,17 @@ nsRefPtrHashtable<KeyClass, RefPtr>::Get
return nullptr;
}
template<class KeyClass, class RefPtr>
void
nsRefPtrHashtable<KeyClass, RefPtr>::Put(KeyType aKey,
already_AddRefed<RefPtr> aData)
{
- if (!Put(aKey, mozilla::Move(aData), mozilla::fallible_t())) {
+ if (!Put(aKey, mozilla::Move(aData), mozilla::fallible)) {
NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
}
}
template<class KeyClass, class RefPtr>
bool
nsRefPtrHashtable<KeyClass, RefPtr>::Put(KeyType aKey,
already_AddRefed<RefPtr> aData,
--- a/xpcom/glue/nsTHashtable.h
+++ b/xpcom/glue/nsTHashtable.h
@@ -144,17 +144,17 @@ public:
/**
* Get the entry associated with a key, or create a new entry,
* @param aKey the key to retrieve
* @return pointer to the entry class retreived; nullptr only if memory
can't be allocated
*/
EntryType* PutEntry(KeyType aKey)
{
- EntryType* e = PutEntry(aKey, fallible_t());
+ EntryType* e = PutEntry(aKey, mozilla::fallible);
if (!e) {
NS_ABORT_OOM(mTable.EntrySize() * mTable.EntryCount());
}
return e;
}
EntryType* PutEntry(KeyType aKey, const fallible_t&) NS_WARN_UNUSED_RESULT {
NS_ASSERTION(mTable.IsInitialized(),
--- a/xpcom/glue/pldhash.cpp
+++ b/xpcom/glue/pldhash.cpp
@@ -171,17 +171,17 @@ PLDHashTable*
PL_NewDHashTable(const PLDHashTableOps* aOps, uint32_t aEntrySize,
uint32_t aLength)
{
PLDHashTable* table = (PLDHashTable*)malloc(sizeof(*table));
if (!table) {
return nullptr;
}
- if (!PL_DHashTableInit(table, aOps, aEntrySize, fallible_t(), aLength)) {
+ if (!PL_DHashTableInit(table, aOps, aEntrySize, fallible, aLength)) {
free(table);
return nullptr;
}
return table;
}
void
PL_DHashTableDestroy(PLDHashTable* aTable)
@@ -271,17 +271,17 @@ PL_DHashTableInit(PLDHashTable* aTable,
{
return aTable->Init(aOps, aEntrySize, aFallible, aLength);
}
void
PL_DHashTableInit(PLDHashTable* aTable, const PLDHashTableOps* aOps,
uint32_t aEntrySize, uint32_t aLength)
{
- if (!PL_DHashTableInit(aTable, aOps, aEntrySize, fallible_t(), aLength)) {
+ if (!PL_DHashTableInit(aTable, aOps, aEntrySize, fallible, aLength)) {
if (aLength > PL_DHASH_MAX_INITIAL_LENGTH) {
MOZ_CRASH(); // the asked-for length was too big
}
uint32_t capacity = MinCapacity(aLength), nbytes;
if (!SizeOfEntryStore(capacity, aEntrySize, &nbytes)) {
MOZ_CRASH(); // the required mEntryStore size was too big
}
NS_ABORT_OOM(nbytes); // allocation failed
--- a/xpcom/glue/standalone/moz.build
+++ b/xpcom/glue/standalone/moz.build
@@ -39,8 +39,13 @@ DEFINES['XPCOM_GLUE'] = True
LOCAL_INCLUDES += [
'../../build',
]
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
+
+# Include fallible for third party code using the xpcom glue
+USE_LIBS += [
+ 'fallible',
+]
--- a/xpcom/glue/standalone/staticruntime/moz.build
+++ b/xpcom/glue/standalone/staticruntime/moz.build
@@ -34,8 +34,13 @@ LOCAL_INCLUDES += [
# Statically link to the CRT on Windows
USE_STATIC_LIBS = True
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
+
+# Include fallible for third party code using the xpcom glue
+USE_LIBS += [
+ 'fallible',
+]
--- a/xpcom/glue/staticruntime/moz.build
+++ b/xpcom/glue/staticruntime/moz.build
@@ -32,8 +32,13 @@ LOCAL_INCLUDES += [
# Statically link to the CRT on Windows
USE_STATIC_LIBS = True
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
+
+# Include fallible for third party code using the xpcom glue
+USE_LIBS += [
+ 'fallible',
+]
--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -262,17 +262,17 @@ Base64Encode(const nsACString& aBinaryDa
return NS_OK;
}
uint32_t stringLen = ((aBinaryData.Length() + 2) / 3) * 4;
char* buffer;
// Add one byte for null termination.
- if (aString.SetCapacity(stringLen + 1, fallible_t()) &&
+ if (aString.SetCapacity(stringLen + 1, fallible) &&
(buffer = aString.BeginWriting()) &&
PL_Base64Encode(aBinaryData.BeginReading(), aBinaryData.Length(), buffer)) {
// PL_Base64Encode doesn't null terminate the buffer for us when we pass
// the buffer in. Do that manually.
buffer[stringLen] = '\0';
aString.SetLength(stringLen);
return NS_OK;
@@ -312,17 +312,17 @@ Base64Decode(const nsACString& aString,
return NS_OK;
}
uint32_t binaryDataLen = ((aString.Length() * 3) / 4);
char* buffer;
// Add one byte for null termination.
- if (aBinaryData.SetCapacity(binaryDataLen + 1, fallible_t()) &&
+ if (aBinaryData.SetCapacity(binaryDataLen + 1, fallible) &&
(buffer = aBinaryData.BeginWriting()) &&
PL_Base64Decode(aString.BeginReading(), aString.Length(), buffer)) {
// PL_Base64Decode doesn't null terminate the buffer for us when we pass
// the buffer in. Do that manually, taking into account the number of '='
// characters we were passed.
if (!aString.IsEmpty() && aString[aString.Length() - 1] == '=') {
if (aString.Length() > 1 && aString[aString.Length() - 2] == '=') {
binaryDataLen -= 2;
--- a/xpcom/io/SnappyCompressOutputStream.cpp
+++ b/xpcom/io/SnappyCompressOutputStream.cpp
@@ -102,17 +102,17 @@ SnappyCompressOutputStream::WriteSegment
{
*aBytesWrittenOut = 0;
if (!mBaseStream) {
return NS_BASE_STREAM_CLOSED;
}
if (!mBuffer) {
- mBuffer.reset(new ((fallible_t())) char[mBlockSize]);
+ mBuffer.reset(new (fallible) char[mBlockSize]);
if (NS_WARN_IF(!mBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
while (aCount > 0) {
// Determine how much space is left in our flat, uncompressed buffer.
MOZ_ASSERT(mNextByte <= mBlockSize);
@@ -169,17 +169,17 @@ SnappyCompressOutputStream::FlushToBaseS
{
MOZ_ASSERT(mBaseStream);
// Lazily create the compressed buffer on our first flush. This
// allows us to report OOM during stream operation. This buffer
// will then get re-used until the stream is closed.
if (!mCompressedBuffer) {
mCompressedBufferLength = MaxCompressedBufferLength(mBlockSize);
- mCompressedBuffer.reset(new ((fallible_t())) char[mCompressedBufferLength]);
+ mCompressedBuffer.reset(new (fallible) char[mCompressedBufferLength]);
if (NS_WARN_IF(!mCompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
// The first chunk must be a StreamIdentifier chunk. Write it out
// if we have not done so already.
nsresult rv = MaybeFlushStreamIdentifier();
--- a/xpcom/io/SnappyUncompressInputStream.cpp
+++ b/xpcom/io/SnappyUncompressInputStream.cpp
@@ -183,24 +183,24 @@ SnappyUncompressInputStream::ParseNextCh
nsresult rv;
*aBytesReadOut = 0;
// Lazily create our two buffers so we can report OOM during stream
// operation. These allocations only happens once. The buffers are reused
// until the stream is closed.
if (!mUncompressedBuffer) {
- mUncompressedBuffer.reset(new ((fallible_t())) char[snappy::kBlockSize]);
+ mUncompressedBuffer.reset(new (fallible) char[snappy::kBlockSize]);
if (NS_WARN_IF(!mUncompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
if (!mCompressedBuffer) {
- mCompressedBuffer.reset(new ((fallible_t())) char[kCompressedBufferLength]);
+ mCompressedBuffer.reset(new (fallible) char[kCompressedBufferLength]);
if (NS_WARN_IF(!mCompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
// We have no decompressed data and we also have not seen the start of stream
// yet. Read and validate the StreamIdentifier chunk. Also read the next
// header to determine the size of the first real data chunk.
--- a/xpcom/io/nsBinaryStream.cpp
+++ b/xpcom/io/nsBinaryStream.cpp
@@ -760,17 +760,17 @@ nsBinaryInputStream::ReadString(nsAStrin
}
if (length == 0) {
aString.Truncate();
return NS_OK;
}
// pre-allocate output buffer, and get direct access to buffer...
- if (!aString.SetLength(length, mozilla::fallible_t())) {
+ if (!aString.SetLength(length, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsAString::iterator start;
aString.BeginWriting(start);
WriteStringClosure closure;
closure.mWriteCursor = start.get();
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -3649,17 +3649,17 @@ nsDriveEnumerator::~nsDriveEnumerator()
nsresult
nsDriveEnumerator::Init()
{
/* If the length passed to GetLogicalDriveStrings is smaller
* than the length of the string it would return, it returns
* the length required for the string. */
DWORD length = GetLogicalDriveStringsW(0, 0);
/* The string is null terminated */
- if (!mDrives.SetLength(length + 1, fallible_t())) {
+ if (!mDrives.SetLength(length + 1, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!GetLogicalDriveStringsW(length, wwc(mDrives.BeginWriting()))) {
return NS_ERROR_FAILURE;
}
mDrives.BeginReading(mStartOfCurrentDrive);
mDrives.EndReading(mEndOfDrivesString);
return NS_OK;
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -809,17 +809,17 @@ NS_CopyNativeToUnicode(const nsACString&
//
// OPTIMIZATION: preallocate space for largest possible result; convert
// directly into the result buffer to avoid intermediate buffer copy.
//
// this will generally result in a larger allocation, but that seems
// better than an extra buffer copy.
//
- if (!aOutput.SetLength(inputLen, fallible_t())) {
+ if (!aOutput.SetLength(inputLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsAString::iterator out_iter;
aOutput.BeginWriting(out_iter);
char16_t* result = out_iter.get();
uint32_t resultLeft = inputLen;
@@ -920,17 +920,17 @@ NS_CopyNativeToUnicode(const nsACString&
// determine length of result
uint32_t resultLen = 0;
int n = ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, nullptr, 0);
if (n > 0) {
resultLen += n;
}
// allocate sufficient space
- if (!aOutput.SetLength(resultLen, fallible_t())) {
+ if (!aOutput.SetLength(resultLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (resultLen > 0) {
nsAString::iterator out_iter;
aOutput.BeginWriting(out_iter);
char16_t* result = out_iter.get();
@@ -954,17 +954,17 @@ NS_CopyUnicodeToNative(const nsAString&
int n = ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, nullptr, 0,
nullptr, nullptr);
if (n > 0) {
resultLen += n;
}
// allocate sufficient space
- if (!aOutput.SetLength(resultLen, fallible_t())) {
+ if (!aOutput.SetLength(resultLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (resultLen > 0) {
nsACString::iterator out_iter;
aOutput.BeginWriting(out_iter);
// default "defaultChar" is '?', which is an illegal character on windows
// file system. That will cause file uncreatable. Change it to '_'
--- a/xpcom/string/nsAString.h
+++ b/xpcom/string/nsAString.h
@@ -9,18 +9,16 @@
#define nsAString_h___
#include "nsStringFwd.h"
#include "nsStringIterator.h"
#include <string.h>
#include <stdarg.h>
-#include "mozilla/fallible.h"
-
#define kNotFound -1
// declare nsAString
#include "string-template-def-unichar.h"
#include "nsTSubstring.h"
#include "string-template-undef.h"
// declare nsACString
--- a/xpcom/string/nsReadableUtils.cpp
+++ b/xpcom/string/nsReadableUtils.cpp
@@ -41,29 +41,29 @@ CopyASCIItoUTF16(const char* aSource, ns
if (aSource) {
AppendASCIItoUTF16(nsDependentCString(aSource), aDest);
}
}
void
CopyUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
{
- if (!CopyUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
+ if (!CopyUTF16toUTF8(aSource, aDest, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we report the length of aSource as UTF-16 instead of UTF-8.
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
CopyUTF16toUTF8(const nsAString& aSource, nsACString& aDest,
- const mozilla::fallible_t&)
+ const mozilla::fallible_t& aFallible)
{
aDest.Truncate();
- if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
+ if (!AppendUTF16toUTF8(aSource, aDest, aFallible)) {
return false;
}
return true;
}
void
CopyUTF8toUTF16(const nsACString& aSource, nsAString& aDest)
{
@@ -103,28 +103,28 @@ LossyAppendUTF16toASCII(const nsAString&
copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
converter);
}
void
AppendASCIItoUTF16(const nsACString& aSource, nsAString& aDest)
{
- if (!AppendASCIItoUTF16(aSource, aDest, mozilla::fallible_t())) {
+ if (!AppendASCIItoUTF16(aSource, aDest, mozilla::fallible)) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
AppendASCIItoUTF16(const nsACString& aSource, nsAString& aDest,
- const mozilla::fallible_t&)
+ const mozilla::fallible_t& aFallible)
{
uint32_t old_dest_length = aDest.Length();
if (!aDest.SetLength(old_dest_length + aSource.Length(),
- mozilla::fallible_t())) {
+ aFallible)) {
return false;
}
nsACString::const_iterator fromBegin, fromEnd;
nsAString::iterator dest;
aDest.BeginWriting(dest);
@@ -152,39 +152,39 @@ AppendASCIItoUTF16(const char* aSource,
if (aSource) {
AppendASCIItoUTF16(nsDependentCString(aSource), aDest);
}
}
void
AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
{
- if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
+ if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we report the length of aSource as UTF-16 instead of UTF-8.
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest,
- const mozilla::fallible_t&)
+ const mozilla::fallible_t& aFallible)
{
nsAString::const_iterator source_start, source_end;
CalculateUTF8Size calculator;
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), calculator);
uint32_t count = calculator.Size();
if (count) {
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
- if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
+ if (!aDest.SetLength(old_dest_length + count, aFallible)) {
return false;
}
// All ready? Time to convert
ConvertUTF16toUTF8 converter(aDest.BeginWriting() + old_dest_length);
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), converter);
@@ -195,38 +195,38 @@ AppendUTF16toUTF8(const nsAString& aSour
}
return true;
}
void
AppendUTF8toUTF16(const nsACString& aSource, nsAString& aDest)
{
- if (!AppendUTF8toUTF16(aSource, aDest, mozilla::fallible_t())) {
+ if (!AppendUTF8toUTF16(aSource, aDest, mozilla::fallible)) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
AppendUTF8toUTF16(const nsACString& aSource, nsAString& aDest,
- const mozilla::fallible_t&)
+ const mozilla::fallible_t& aFallible)
{
nsACString::const_iterator source_start, source_end;
CalculateUTF8Length calculator;
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), calculator);
uint32_t count = calculator.Length();
// Avoid making the string mutable if we're appending an empty string
if (count) {
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
- if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
+ if (!aDest.SetLength(old_dest_length + count, aFallible)) {
return false;
}
// All ready? Time to convert
ConvertUTF8toUTF16 converter(aDest.BeginWriting() + old_dest_length);
copy_string(aSource.BeginReading(source_start),
aSource.EndReading(source_end), converter);
--- a/xpcom/string/nsTStringObsolete.cpp
+++ b/xpcom/string/nsTStringObsolete.cpp
@@ -459,28 +459,28 @@ nsTString_CharT::ReplaceSubstring(const
{
ReplaceSubstring(nsTDependentString_CharT(aTarget),
nsTDependentString_CharT(aNewValue));
}
bool
nsTString_CharT::ReplaceSubstring(const char_type* aTarget,
const char_type* aNewValue,
- const fallible_t& fallible)
+ const fallible_t& aFallible)
{
return ReplaceSubstring(nsTDependentString_CharT(aTarget),
nsTDependentString_CharT(aNewValue),
- fallible);
+ aFallible);
}
void
nsTString_CharT::ReplaceSubstring(const self_type& aTarget,
const self_type& aNewValue)
{
- if (!ReplaceSubstring(aTarget, aNewValue, fallible_t())) {
+ if (!ReplaceSubstring(aTarget, aNewValue, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we could have been replacing multiple copies of aTarget.
AllocFailed(mLength + (aNewValue.Length() - aTarget.Length()));
}
}
bool
nsTString_CharT::ReplaceSubstring(const self_type& aTarget,
--- a/xpcom/string/nsTSubstring.cpp
+++ b/xpcom/string/nsTSubstring.cpp
@@ -248,17 +248,17 @@ nsTSubstring_CharT::EnsureMutable(size_t
}
if ((mFlags & F_SHARED) &&
!nsStringBuffer::FromData(mData)->IsReadonly()) {
return true;
}
aNewLen = mLength;
}
- return SetLength(aNewLen, fallible_t());
+ return SetLength(aNewLen, mozilla::fallible);
}
// ---------------------------------------------------------------------------
// This version of Assign is optimized for single-character assignment.
void
nsTSubstring_CharT::Assign(char_type aChar)
{
@@ -278,72 +278,72 @@ nsTSubstring_CharT::Assign(char_type aCh
*mData = aChar;
return true;
}
void
nsTSubstring_CharT::Assign(const char_type* aData)
{
- if (!Assign(aData, size_type(-1), fallible_t())) {
+ if (!Assign(aData, size_type(-1), mozilla::fallible)) {
AllocFailed(char_traits::length(aData));
}
}
void
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength)
{
- if (!Assign(aData, aLength, fallible_t())) {
+ if (!Assign(aData, aLength, mozilla::fallible)) {
AllocFailed(aLength == size_type(-1) ? char_traits::length(aData)
: aLength);
}
}
bool
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength,
- const fallible_t&)
+ const fallible_t& aFallible)
{
if (!aData || aLength == 0) {
Truncate();
return true;
}
if (aLength == size_type(-1)) {
aLength = char_traits::length(aData);
}
if (IsDependentOn(aData, aData + aLength)) {
- return Assign(string_type(aData, aLength), fallible_t());
+ return Assign(string_type(aData, aLength), aFallible);
}
if (!ReplacePrep(0, mLength, aLength)) {
return false;
}
char_traits::copy(mData, aData, aLength);
return true;
}
void
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength)
{
- if (!AssignASCII(aData, aLength, fallible_t())) {
+ if (!AssignASCII(aData, aLength, mozilla::fallible)) {
AllocFailed(aLength);
}
}
bool
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength,
- const fallible_t&)
+ const fallible_t& aFallible)
{
// A Unicode string can't depend on an ASCII string buffer,
// so this dependence check only applies to CStrings.
#ifdef CharT_is_char
if (IsDependentOn(aData, aData + aLength)) {
- return Assign(string_type(aData, aLength), fallible_t());
+ return Assign(string_type(aData, aLength), aFallible);
}
#endif
if (!ReplacePrep(0, mLength, aLength)) {
return false;
}
char_traits::copyASCII(mData, aData, aLength);
@@ -357,23 +357,23 @@ nsTSubstring_CharT::AssignLiteral(const
mData = const_cast<char_type*>(aData);
mLength = aLength;
SetDataFlags(F_TERMINATED | F_LITERAL);
}
void
nsTSubstring_CharT::Assign(const self_type& aStr)
{
- if (!Assign(aStr, fallible_t())) {
+ if (!Assign(aStr, mozilla::fallible)) {
AllocFailed(aStr.Length());
}
}
bool
-nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t&)
+nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t& aFallible)
{
// |aStr| could be sharable. We need to check its flags to know how to
// deal with it.
if (&aStr == this) {
return true;
}
@@ -401,34 +401,34 @@ nsTSubstring_CharT::Assign(const self_ty
} else if (aStr.mFlags & F_LITERAL) {
NS_ABORT_IF_FALSE(aStr.mFlags & F_TERMINATED, "Unterminated literal");
AssignLiteral(aStr.mData, aStr.mLength);
return true;
}
// else, treat this like an ordinary assignment.
- return Assign(aStr.Data(), aStr.Length(), fallible_t());
+ return Assign(aStr.Data(), aStr.Length(), aFallible);
}
void
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple)
{
- if (!Assign(aTuple, fallible_t())) {
+ if (!Assign(aTuple, mozilla::fallible)) {
AllocFailed(aTuple.Length());
}
}
bool
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple,
- const fallible_t&)
+ const fallible_t& aFallible)
{
if (aTuple.IsDependentOn(mData, mData + mLength)) {
// take advantage of sharing here...
- return Assign(string_type(aTuple), fallible_t());
+ return Assign(string_type(aTuple), aFallible);
}
size_type length = aTuple.Length();
// don't use ReplacePrep here because it changes the length
char_type* oldData;
uint32_t oldFlags;
if (!MutatePrep(length, &oldData, &oldFlags)) {
@@ -481,17 +481,17 @@ nsTSubstring_CharT::Replace(index_type a
if (ReplacePrep(aCutStart, aCutLength, 1)) {
mData[aCutStart] = aChar;
}
}
bool
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
char_type aChar,
- const mozilla::fallible_t&)
+ const fallible_t&)
{
aCutStart = XPCOM_MIN(aCutStart, Length());
if (!ReplacePrep(aCutStart, aCutLength, 1)) {
return false;
}
mData[aCutStart] = aChar;
@@ -499,37 +499,37 @@ nsTSubstring_CharT::Replace(index_type a
return true;
}
void
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData, size_type aLength)
{
if (!Replace(aCutStart, aCutLength, aData, aLength,
- mozilla::fallible_t())) {
+ mozilla::fallible)) {
AllocFailed(Length() - aCutLength + 1);
}
}
bool
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData, size_type aLength,
- const mozilla::fallible_t&)
+ const fallible_t& aFallible)
{
// unfortunately, some callers pass null :-(
if (!aData) {
aLength = 0;
} else {
if (aLength == size_type(-1)) {
aLength = char_traits::length(aData);
}
if (IsDependentOn(aData, aData + aLength)) {
nsTAutoString_CharT temp(aData, aLength);
- return Replace(aCutStart, aCutLength, temp, mozilla::fallible_t());
+ return Replace(aCutStart, aCutLength, temp, aFallible);
}
}
aCutStart = XPCOM_MIN(aCutStart, Length());
bool ok = ReplacePrep(aCutStart, aCutLength, aLength);
if (!ok) {
return false;
@@ -597,17 +597,17 @@ nsTSubstring_CharT::ReplaceLiteral(index
} else if (ReplacePrep(aCutStart, aCutLength, aLength) && aLength > 0) {
char_traits::copy(mData + aCutStart, aData, aLength);
}
}
void
nsTSubstring_CharT::SetCapacity(size_type aCapacity)
{
- if (!SetCapacity(aCapacity, fallible_t())) {
+ if (!SetCapacity(aCapacity, mozilla::fallible)) {
AllocFailed(aCapacity);
}
}
bool
nsTSubstring_CharT::SetCapacity(size_type aCapacity, const fallible_t&)
{
// capacity does not include room for the terminating null char
@@ -654,19 +654,19 @@ nsTSubstring_CharT::SetCapacity(size_typ
void
nsTSubstring_CharT::SetLength(size_type aLength)
{
SetCapacity(aLength);
mLength = aLength;
}
bool
-nsTSubstring_CharT::SetLength(size_type aLength, const fallible_t&)
+nsTSubstring_CharT::SetLength(size_type aLength, const fallible_t& aFallible)
{
- if (!SetCapacity(aLength, fallible_t())) {
+ if (!SetCapacity(aLength, aFallible)) {
return false;
}
mLength = aLength;
return true;
}
void
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -171,29 +171,29 @@ public:
return EnsureMutable() ? (mData + mLength) : char_iterator(0);
}
char_iterator& BeginWriting(char_iterator& aIter)
{
return aIter = BeginWriting();
}
- char_iterator& BeginWriting(char_iterator& aIter, const fallible_t&)
+ char_iterator& BeginWriting(char_iterator& aIter, const fallible_t& aFallible)
{
- return aIter = BeginWriting(fallible_t());
+ return aIter = BeginWriting(aFallible);
}
char_iterator& EndWriting(char_iterator& aIter)
{
return aIter = EndWriting();
}
- char_iterator& EndWriting(char_iterator& aIter, const fallible_t&)
+ char_iterator& EndWriting(char_iterator& aIter, const fallible_t& aFallible)
{
- return aIter = EndWriting(fallible_t());
+ return aIter = EndWriting(aFallible);
}
/**
* deprecated writing iterators
*/
iterator& BeginWriting(iterator& aIter)
{
@@ -375,48 +375,50 @@ public:
const fallible_t&);
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
void Assign(char16ptr_t aData)
{
Assign(static_cast<const char16_t*>(aData));
}
- NS_WARN_UNUSED_RESULT bool Assign(char16ptr_t aData, const fallible_t&)
+ NS_WARN_UNUSED_RESULT bool Assign(char16ptr_t aData,
+ const fallible_t& aFallible)
{
- return Assign(static_cast<const char16_t*>(aData), fallible_t());
+ return Assign(static_cast<const char16_t*>(aData), aFallible);
}
void Assign(char16ptr_t aData, size_type aLength)
{
Assign(static_cast<const char16_t*>(aData), aLength);
}
NS_WARN_UNUSED_RESULT bool Assign(char16ptr_t aData, size_type aLength,
- const fallible_t&)
+ const fallible_t& aFallible)
{
- return Assign(static_cast<const char16_t*>(aData), aLength, fallible_t());
+ return Assign(static_cast<const char16_t*>(aData), aLength,
+ aFallible);
}
#endif
void NS_FASTCALL AssignASCII(const char* aData, size_type aLength);
NS_WARN_UNUSED_RESULT bool NS_FASTCALL AssignASCII(const char* aData,
size_type aLength,
const fallible_t&);
void NS_FASTCALL AssignASCII(const char* aData)
{
AssignASCII(aData, mozilla::AssertedCast<size_type, size_t>(strlen(aData)));
}
NS_WARN_UNUSED_RESULT bool NS_FASTCALL AssignASCII(const char* aData,
- const fallible_t&)
+ const fallible_t& aFallible)
{
return AssignASCII(aData,
mozilla::AssertedCast<size_type, size_t>(strlen(aData)),
- fallible_t());
+ aFallible);
}
// AssignLiteral must ONLY be applied to an actual literal string, or
// a char array *constant* declared without an explicit size.
// Do not attempt to use it with a regular char* pointer, or with a
// non-constant char array variable. Use AssignASCII for those.
// There are not fallible version of these methods because they only really
// apply to small allocations that we wouldn't want to check anyway.
@@ -468,37 +470,37 @@ public:
* buffer manipulation
*/
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
char_type aChar);
NS_WARN_UNUSED_RESULT bool NS_FASTCALL Replace(index_type aCutStart,
size_type aCutLength,
char_type aChar,
- const mozilla::fallible_t&);
+ const fallible_t&);
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData,
size_type aLength = size_type(-1));
NS_WARN_UNUSED_RESULT bool NS_FASTCALL Replace(index_type aCutStart,
size_type aCutLength,
const char_type* aData,
size_type aLength,
- const mozilla::fallible_t&);
+ const fallible_t&);
void Replace(index_type aCutStart, size_type aCutLength,
const self_type& aStr)
{
Replace(aCutStart, aCutLength, aStr.Data(), aStr.Length());
}
NS_WARN_UNUSED_RESULT bool Replace(index_type aCutStart,
size_type aCutLength,
const self_type& aStr,
- const mozilla::fallible_t&)
+ const fallible_t& aFallible)
{
return Replace(aCutStart, aCutLength, aStr.Data(), aStr.Length(),
- mozilla::fallible_t());
+ aFallible);
}
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
const substring_tuple_type& aTuple);
void NS_FASTCALL ReplaceASCII(index_type aCutStart, size_type aCutLength,
const char* aData,
size_type aLength = size_type(-1));
@@ -512,28 +514,28 @@ public:
ReplaceLiteral(aCutStart, aCutLength, aStr, N - 1);
}
void Append(char_type aChar)
{
Replace(mLength, 0, aChar);
}
NS_WARN_UNUSED_RESULT bool Append(char_type aChar,
- const mozilla::fallible_t&)
+ const fallible_t& aFallible)
{
- return Replace(mLength, 0, aChar, mozilla::fallible_t());
+ return Replace(mLength, 0, aChar, aFallible);
}
void Append(const char_type* aData, size_type aLength = size_type(-1))
{
Replace(mLength, 0, aData, aLength);
}
NS_WARN_UNUSED_RESULT bool Append(const char_type* aData, size_type aLength,
- const mozilla::fallible_t&)
+ const fallible_t& aFallible)
{
- return Replace(mLength, 0, aData, aLength, mozilla::fallible_t());
+ return Replace(mLength, 0, aData, aLength, aFallible);
}
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
void Append(char16ptr_t aData, size_type aLength = size_type(-1))
{
Append(static_cast<const char16_t*>(aData), aLength);
}
#endif
@@ -761,20 +763,21 @@ public:
}
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
size_type GetMutableData(wchar_t** aData, size_type aNewLen = size_type(-1))
{
return GetMutableData(reinterpret_cast<char16_t**>(aData), aNewLen);
}
- size_type GetMutableData(wchar_t** aData, size_type aNewLen, const fallible_t&)
+ size_type GetMutableData(wchar_t** aData, size_type aNewLen,
+ const fallible_t& aFallible)
{
return GetMutableData(reinterpret_cast<char16_t**>(aData), aNewLen,
- fallible_t());
+ aFallible);
}
#endif
/**
* string data is never null, but can be marked void. if true, the
* string will be truncated. @see nsTSubstring::IsVoid
*/
--- a/xpcom/tests/TestPLDHash.cpp
+++ b/xpcom/tests/TestPLDHash.cpp
@@ -22,17 +22,17 @@ static bool test_pldhash_Init_capacity_o
if (t.IsInitialized()) {
return false;
}
// Try the largest allowed capacity. With PL_DHASH_MAX_CAPACITY==1<<26, this
// will allocate 0.5GB of entry store on 32-bit platforms and 1GB on 64-bit
// platforms.
if (!PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(PLDHashEntryStub),
- mozilla::fallible_t(), PL_DHASH_MAX_INITIAL_LENGTH)) {
+ mozilla::fallible, PL_DHASH_MAX_INITIAL_LENGTH)) {
return false;
}
// Check that Init() sets |ops|.
if (!t.IsInitialized()) {
return false;
}
@@ -52,17 +52,17 @@ static bool test_pldhash_Init_capacity_t
// Check that the constructor nulls |ops|.
if (t.IsInitialized()) {
return false;
}
// Try the smallest too-large capacity.
if (PL_DHashTableInit(&t, PL_DHashGetStubOps(),
sizeof(PLDHashEntryStub),
- mozilla::fallible_t(),
+ mozilla::fallible,
PL_DHASH_MAX_INITIAL_LENGTH + 1)) {
return false; // it succeeded!?
}
// Don't call PL_DHashTableFinish() here; it's not safe after Init() failure.
// Check that |ops| is still null.
if (t.IsInitialized()) {
return false;
@@ -88,17 +88,17 @@ static bool test_pldhash_Init_overflow()
// test wouldn't be reliable.
struct OneKBEntry {
PLDHashEntryHdr hdr;
char buf[1024 - sizeof(PLDHashEntryHdr)];
};
if (PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(OneKBEntry),
- mozilla::fallible_t(), PL_DHASH_MAX_INITIAL_LENGTH)) {
+ mozilla::fallible, PL_DHASH_MAX_INITIAL_LENGTH)) {
return false; // it succeeded!?
}
// Don't call PL_DHashTableFinish() here; it's not safe after Init() failure.
// Check that |ops| is still null.
if (t.IsInitialized()) {
return false;
}
--- a/xpcom/tests/gtest/TestStrings.cpp
+++ b/xpcom/tests/gtest/TestStrings.cpp
@@ -6,22 +6,21 @@
#include <stdio.h>
#include <stdlib.h>
#include "nsString.h"
#include "nsStringBuffer.h"
#include "nsReadableUtils.h"
#include "nsCRTGlue.h"
#include "nsRefPtr.h"
#include "nsTArray.h"
-#include "mozilla/fallible.h"
#include "gtest/gtest.h"
namespace TestStrings {
-using mozilla::fallible_t;
+using mozilla::fallible;
void test_assign_helper(const nsACString& in, nsACString &_retval)
{
_retval = in;
}
TEST(Strings, assign)
{
@@ -846,85 +845,85 @@ TEST(String, strip_chars)
TEST(Strings, huge_capacity)
{
nsString a, b, c, d, e, f, g, h, i, j, k, l, m, n;
nsCString n1;
// Ignore the result if the address space is less than 64-bit because
// some of the allocations above will exhaust the address space.
if (sizeof(void*) >= 8) {
- EXPECT_TRUE(a.SetCapacity(1, fallible_t()));
- EXPECT_FALSE(a.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
- EXPECT_TRUE(a.SetCapacity(0, fallible_t())); // free the allocated memory
+ EXPECT_TRUE(a.SetCapacity(1, fallible));
+ EXPECT_FALSE(a.SetCapacity(nsString::size_type(-1)/2, fallible));
+ EXPECT_TRUE(a.SetCapacity(0, fallible)); // free the allocated memory
- EXPECT_TRUE(b.SetCapacity(1, fallible_t()));
- EXPECT_FALSE(b.SetCapacity(nsString::size_type(-1)/2 - 1, fallible_t()));
- EXPECT_TRUE(b.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(b.SetCapacity(1, fallible));
+ EXPECT_FALSE(b.SetCapacity(nsString::size_type(-1)/2 - 1, fallible));
+ EXPECT_TRUE(b.SetCapacity(0, fallible));
- EXPECT_TRUE(c.SetCapacity(1, fallible_t()));
- EXPECT_FALSE(c.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
- EXPECT_TRUE(c.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(c.SetCapacity(1, fallible));
+ EXPECT_FALSE(c.SetCapacity(nsString::size_type(-1)/2, fallible));
+ EXPECT_TRUE(c.SetCapacity(0, fallible));
- EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2 - 1, fallible_t()));
- EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
- EXPECT_TRUE(d.SetCapacity(0, fallible_t()));
+ EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2 - 1, fallible));
+ EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2, fallible));
+ EXPECT_TRUE(d.SetCapacity(0, fallible));
- EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4, fallible_t()));
- EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
- EXPECT_TRUE(e.SetCapacity(0, fallible_t()));
+ EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4, fallible));
+ EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
+ EXPECT_TRUE(e.SetCapacity(0, fallible));
- EXPECT_FALSE(f.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
- EXPECT_TRUE(f.SetCapacity(0, fallible_t()));
+ EXPECT_FALSE(f.SetCapacity(nsString::size_type(-1)/2, fallible));
+ EXPECT_TRUE(f.SetCapacity(0, fallible));
- EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1000, fallible_t()));
- EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1001, fallible_t()));
- EXPECT_TRUE(g.SetCapacity(0, fallible_t()));
+ EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1000, fallible));
+ EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1001, fallible));
+ EXPECT_TRUE(g.SetCapacity(0, fallible));
- EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/4+1, fallible_t()));
- EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
- EXPECT_TRUE(h.SetCapacity(0, fallible_t()));
+ EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/4+1, fallible));
+ EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/2, fallible));
+ EXPECT_TRUE(h.SetCapacity(0, fallible));
- EXPECT_TRUE(i.SetCapacity(1, fallible_t()));
- EXPECT_TRUE(i.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible_t()));
- EXPECT_FALSE(i.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
- EXPECT_TRUE(i.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(i.SetCapacity(1, fallible));
+ EXPECT_TRUE(i.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible));
+ EXPECT_FALSE(i.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
+ EXPECT_TRUE(i.SetCapacity(0, fallible));
- EXPECT_TRUE(j.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible_t()));
- EXPECT_FALSE(j.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
- EXPECT_TRUE(j.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(j.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible));
+ EXPECT_FALSE(j.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
+ EXPECT_TRUE(j.SetCapacity(0, fallible));
- EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/8 - 1000, fallible_t()));
- EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 1001, fallible_t()));
- EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 998, fallible_t()));
- EXPECT_FALSE(k.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
- EXPECT_TRUE(k.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/8 - 1000, fallible));
+ EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 1001, fallible));
+ EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 998, fallible));
+ EXPECT_FALSE(k.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
+ EXPECT_TRUE(k.SetCapacity(0, fallible));
- EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8, fallible_t()));
- EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 1, fallible_t()));
- EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 2, fallible_t()));
- EXPECT_TRUE(l.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8, fallible));
+ EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 1, fallible));
+ EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 2, fallible));
+ EXPECT_TRUE(l.SetCapacity(0, fallible));
- EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1000, fallible_t()));
- EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1001, fallible_t()));
- EXPECT_TRUE(m.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1000, fallible));
+ EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1001, fallible));
+ EXPECT_TRUE(m.SetCapacity(0, fallible));
- EXPECT_TRUE(n.SetCapacity(nsString::size_type(-1)/8+1, fallible_t()));
- EXPECT_FALSE(n.SetCapacity(nsString::size_type(-1)/4, fallible_t()));
- EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(n.SetCapacity(nsString::size_type(-1)/8+1, fallible));
+ EXPECT_FALSE(n.SetCapacity(nsString::size_type(-1)/4, fallible));
+ EXPECT_TRUE(n.SetCapacity(0, fallible));
- EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
- EXPECT_TRUE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 2, fallible_t()));
- EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
- EXPECT_FALSE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 1, fallible_t()));
- EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
- EXPECT_TRUE(n1.SetCapacity(0, fallible_t()));
- EXPECT_TRUE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 2, fallible_t()));
- EXPECT_TRUE(n1.SetCapacity(0, fallible_t()));
- EXPECT_FALSE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 1, fallible_t()));
- EXPECT_TRUE(n1.SetCapacity(0, fallible_t()));
+ EXPECT_TRUE(n.SetCapacity(0, fallible));
+ EXPECT_TRUE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 2, fallible));
+ EXPECT_TRUE(n.SetCapacity(0, fallible));
+ EXPECT_FALSE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 1, fallible));
+ EXPECT_TRUE(n.SetCapacity(0, fallible));
+ EXPECT_TRUE(n1.SetCapacity(0, fallible));
+ EXPECT_TRUE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 2, fallible));
+ EXPECT_TRUE(n1.SetCapacity(0, fallible));
+ EXPECT_FALSE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 1, fallible));
+ EXPECT_TRUE(n1.SetCapacity(0, fallible));
}
}
static void test_tofloat_helper(const nsString& aStr, float aExpected, bool aSuccess)
{
nsresult result;
EXPECT_EQ(aStr.ToFloat(&result), aExpected);
if (aSuccess) {