Bug 757771 part 1 - Make NS_NewContentIterator and friends infallible; r=bz

This commit is contained in:
Aryeh Gregor 2012-06-04 20:42:00 +03:00
Родитель 9be1268e1c
Коммит 29b2ea5b20
8 изменённых файлов: 46 добавлений и 71 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#define __nsIContentIterator_h___
#include "nsISupports.h"
#include "nsCOMPtr.h"
class nsINode;
class nsIDOMRange;
@ -63,5 +64,8 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(nsIContentIterator, NS_ICONTENTITERATOR_IID)
#endif // __nsIContentIterator_h___
already_AddRefed<nsIContentIterator> NS_NewContentIterator();
already_AddRefed<nsIContentIterator> NS_NewPreContentIterator();
already_AddRefed<nsIContentIterator> NS_NewContentSubtreeIterator();
#endif // __nsIContentIterator_h___

Просмотреть файл

@ -177,29 +177,19 @@ private:
* repository cruft
******************************************************/
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult)
already_AddRefed<nsIContentIterator>
NS_NewContentIterator()
{
nsContentIterator * iter = new nsContentIterator(false);
if (!iter) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aInstancePtrResult = iter);
return NS_OK;
nsCOMPtr<nsIContentIterator> iter = new nsContentIterator(false);
return iter.forget();
}
nsresult NS_NewPreContentIterator(nsIContentIterator** aInstancePtrResult)
already_AddRefed<nsIContentIterator>
NS_NewPreContentIterator()
{
nsContentIterator * iter = new nsContentIterator(true);
if (!iter) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aInstancePtrResult = iter);
return NS_OK;
nsCOMPtr<nsIContentIterator> iter = new nsContentIterator(true);
return iter.forget();
}
@ -1184,8 +1174,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsContentSubtreeIterator, nsCont
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRange)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult);
@ -1193,16 +1181,11 @@ nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult);
* repository cruft
******************************************************/
nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult)
already_AddRefed<nsIContentIterator>
NS_NewContentSubtreeIterator()
{
nsContentIterator * iter = new nsContentSubtreeIterator();
if (!iter) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aInstancePtrResult = iter);
return NS_OK;
nsCOMPtr<nsIContentIterator> iter = new nsContentSubtreeIterator();
return iter.forget();
}

Просмотреть файл

@ -29,8 +29,6 @@
#ifdef DEBUG_CONTENT_LIST
#include "nsIContentIterator.h"
nsresult
NS_NewPreContentIterator(nsIContentIterator** aInstancePtrResult);
#define ASSERT_IN_SYNC AssertInSync()
#else
#define ASSERT_IN_SYNC PR_BEGIN_MACRO PR_END_MACRO
@ -1016,7 +1014,7 @@ nsContentList::AssertInSync()
nsCOMPtr<nsIContentIterator> iter;
if (mDeep) {
NS_NewPreContentIterator(getter_AddRefs(iter));
iter = NS_NewPreContentIterator();
iter->Init(root);
iter->First();
}

Просмотреть файл

@ -136,8 +136,6 @@ PRInt32 nsIContent::sTabFocusModel = eTabFocus_any;
bool nsIContent::sTabFocusModelAppliesToXUL = false;
PRUint32 nsMutationGuard::sMutationCount = 0;
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
//----------------------------------------------------------------------
nsINode::nsSlots::~nsSlots()

Просмотреть файл

@ -33,9 +33,6 @@
using namespace mozilla;
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult);
/******************************************************
* stack based utilty class for managing monitor
******************************************************/
@ -1170,8 +1167,7 @@ RangeSubtreeIterator::Init(nsIDOMRange *aRange)
// Now create a Content Subtree Iterator to be used
// for the subtrees between the end points!
res = NS_NewContentSubtreeIterator(getter_AddRefs(mIter));
if (NS_FAILED(res)) return res;
mIter = NS_NewContentSubtreeIterator();
res = mIter->Init(aRange);
if (NS_FAILED(res)) return res;
@ -2244,10 +2240,8 @@ nsRange::ToString(nsAString& aReturn)
revisit - there are potential optimizations here and also tradeoffs.
*/
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
rv = iter->Init(this);
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
nsresult rv = iter->Init(this);
NS_ENSURE_SUCCESS(rv, rv);
nsString tempString;

Просмотреть файл

@ -27,8 +27,6 @@
#include "nsIMEStateManager.h"
#include "nsIObjectFrame.h"
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
/******************************************************************/
/* nsContentEventHandler */
/******************************************************************/
@ -278,10 +276,7 @@ static PRUint32 ConvertToXPOffset(nsIContent* aContent, PRUint32 aNativeOffset)
static nsresult GenerateFlatTextContent(nsRange* aRange,
nsAFlatString& aString)
{
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
iter->Init(aRange);
NS_ASSERTION(aString.IsEmpty(), "aString must be empty string");
@ -374,11 +369,8 @@ nsContentEventHandler::SetRangeFromFlatTextOffset(
PRUint32 aNativeLength,
bool aExpandToClusterBoundaries)
{
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
rv = iter->Init(mRootContent);
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
nsresult rv = iter->Init(mRootContent);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 nativeOffset = 0;
@ -579,11 +571,8 @@ nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent)
NS_ENSURE_SUCCESS(rv, rv);
// used to iterate over all contents and their frames
nsCOMPtr<nsIContentIterator> iter;
rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
iter->Init(range);
NS_ENSURE_SUCCESS(rv, rv);
// get the starting frame
PRInt32 offset = range->StartOffset();
@ -915,10 +904,7 @@ nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
NS_ASSERTION(startDOMNode, "startNode doesn't have nsIDOMNode");
prev->SetEnd(startDOMNode, aNodeOffset);
nsCOMPtr<nsIContentIterator> iter;
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
iter->Init(prev);
nsCOMPtr<nsINode> startNode = do_QueryInterface(startDOMNode);

Просмотреть файл

@ -36,8 +36,6 @@
#include "nsSMILTypes.h"
#include "nsIContentIterator.h"
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
using namespace mozilla;
using namespace mozilla::dom;

Просмотреть файл

@ -394,10 +394,7 @@ nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
nsresult NS_NewDomSelection(nsISelection** aResult);
nsresult NS_NewContentViewer(nsIContentViewer** aResult);
nsresult NS_NewContentIterator(nsIContentIterator** aResult);
nsresult NS_NewPreContentIterator(nsIContentIterator** aResult);
nsresult NS_NewGenRegularIterator(nsIContentIterator** aResult);
nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aResult);
nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult);
nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
nsresult NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult);
@ -427,6 +424,23 @@ ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
return rv; \
}
// As above, but expects
// already_AddRefed<nsIFoo> NS_NewFoo();
// instead of
// nsresult NS_NewFoo(nsIFoo**);
#define MAKE_CTOR2(ctor_, iface_, func_) \
static nsresult \
ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
{ \
*aResult = nsnull; \
if (aOuter) { \
return NS_ERROR_NO_AGGREGATION; \
} \
nsCOMPtr<iface_> inst = func_(); \
inst.forget(aResult); \
return NS_OK; \
}
#ifdef DEBUG
MAKE_CTOR(CreateNewFrameUtil, nsIFrameUtil, NS_NewFrameUtil)
MAKE_CTOR(CreateNewLayoutDebugger, nsILayoutDebugger, NS_NewLayoutDebugger)
@ -460,9 +474,9 @@ MAKE_CTOR(CreateXMLDocument, nsIDocument, NS_NewXML
MAKE_CTOR(CreateSVGDocument, nsIDocument, NS_NewSVGDocument)
MAKE_CTOR(CreateImageDocument, nsIDocument, NS_NewImageDocument)
MAKE_CTOR(CreateDOMSelection, nsISelection, NS_NewDomSelection)
MAKE_CTOR(CreateContentIterator, nsIContentIterator, NS_NewContentIterator)
MAKE_CTOR(CreatePreContentIterator, nsIContentIterator, NS_NewPreContentIterator)
MAKE_CTOR(CreateSubtreeIterator, nsIContentIterator, NS_NewContentSubtreeIterator)
MAKE_CTOR2(CreateContentIterator, nsIContentIterator, NS_NewContentIterator)
MAKE_CTOR2(CreatePreContentIterator, nsIContentIterator, NS_NewPreContentIterator)
MAKE_CTOR2(CreateSubtreeIterator, nsIContentIterator, NS_NewContentSubtreeIterator)
// CreateHTMLImgElement, see below
// CreateHTMLOptionElement, see below
// CreateHTMLAudioElement, see below