mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-22 18:32:00 +00:00
1. add asserting code to check null ptr
This commit is contained in:
parent
80a50d6b37
commit
6df0b49bc8
editor
@ -74,31 +74,44 @@ NS_IMETHODIMP IMECommitTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransactio
|
||||
printf("Merge IME Commit");
|
||||
#endif
|
||||
|
||||
NS_ASSERTION(aDidMerge, "null ptr- aDidMerge");
|
||||
NS_ASSERTION(aTransaction, "null ptr- aTransaction");
|
||||
if((nsnull == aDidMerge) || (nsnull == aTransaction))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_OK;
|
||||
NS_ASSERTION(aOutputStream, "null ptr- aOutputStream");
|
||||
if(nsnull == aOutputStream)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "null ptr- aString");
|
||||
if(nsnull == aString) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
} else {
|
||||
*aString="Remove IMECommit: ";
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMECommitTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "null ptr- aString");
|
||||
if(nsnull == aString) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
} else {
|
||||
*aString="Insert IMECommit: ";
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* ============= nsISupports implementation ====================== */
|
||||
|
@ -61,6 +61,10 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement,
|
||||
const nsString &aStringToInsert,
|
||||
nsWeakPtr aPresShellWeak)
|
||||
{
|
||||
NS_ASSERTION(aElement, "illegal value- null ptr- aElement");
|
||||
NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList");
|
||||
if((nsnull == aElement) || (nsnull == aTextRangeList))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
mElement = do_QueryInterface(aElement);
|
||||
mOffset = aOffset;
|
||||
mReplaceLength = aReplaceLength;
|
||||
@ -125,6 +129,11 @@ NS_IMETHODIMP IMETextTxn::Undo(void)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
NS_ASSERTION(aDidMerge, "illegal vaule- null ptr- aDidMerge");
|
||||
NS_ASSERTION(aTransaction, "illegal vaule- null ptr- aTransaction");
|
||||
if((nsnull == aDidMerge) || (nsnull == aTransaction))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result;
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Merge IME Text element = %p\n", mElement.get());
|
||||
@ -190,11 +199,18 @@ NS_IMETHODIMP IMETextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
NS_ASSERTION(aOutputStream, "illegal value- null ptr- aOutputStream");
|
||||
if(nsnull == aOutputStream)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "illegal value- null ptr- aString");
|
||||
if(nsnull == aString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Text: ";
|
||||
@ -205,6 +221,10 @@ NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "illegal value- null ptr- aString");
|
||||
if(nsnull == aString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Text: ";
|
||||
@ -233,6 +253,9 @@ IMETextTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aTextRangeList)
|
||||
{
|
||||
NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
|
||||
if(nsnull == aTextRangeList)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
aResult = mStringToInsert;
|
||||
*aTextRangeList = mRangeList;
|
||||
return NS_OK;
|
||||
|
@ -1363,6 +1363,7 @@ nsEditor::BeginComposition(nsTextEventReply* aReply)
|
||||
if ((NS_SUCCEEDED(result)) && (node))
|
||||
{
|
||||
nodeAsText = do_QueryInterface(node);
|
||||
NS_ASSERTION(nodeAsText, "cannot get Text Node");
|
||||
range->GetStartOffset(&offset);
|
||||
if (!nodeAsText) {
|
||||
result = NS_ERROR_EDITOR_NO_TEXTNODE;
|
||||
@ -1402,8 +1403,12 @@ nsEditor::EndComposition(void)
|
||||
result = TransactionFactory::GetNewTransaction(IMECommitTxn::GetCID(), (EditTxn**)&commitTxn);
|
||||
if (NS_SUCCEEDED(result) && commitTxn!=nsnull)
|
||||
{
|
||||
commitTxn->Init();
|
||||
result = Do(commitTxn);
|
||||
result = commitTxn->Init();
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "commitTxt->Init failed");
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
result = Do(commitTxn);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "nsEditor::Do failed");
|
||||
}
|
||||
}
|
||||
|
||||
/* reset the data we need to construct a transaction */
|
||||
@ -1417,6 +1422,11 @@ nsEditor::EndComposition(void)
|
||||
NS_IMETHODIMP
|
||||
nsEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply)
|
||||
{
|
||||
NS_ASSERTION(aTextRangeList, "null ptr- aTextRangeList");
|
||||
NS_ASSERTION(aReply, "null ptr- aReply");
|
||||
if((nsnull == aTextRangeList) || (nsnull == aReply))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsICaret> caretP;
|
||||
nsresult result = SetInputMethodText(aCompositionString,aTextRangeList);
|
||||
mIMEBufferLength = aCompositionString.Length();
|
||||
@ -1424,9 +1434,12 @@ nsEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivateTex
|
||||
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
if (!ps) return NS_ERROR_NOT_INITIALIZED;
|
||||
ps->GetCaret(getter_AddRefs(caretP));
|
||||
caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
|
||||
|
||||
result = ps->GetCaret(getter_AddRefs(caretP));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get caret");
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
result = caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get window relative coordinates");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -4285,14 +4298,27 @@ nsEditor::CreateTxnForIMEText(const nsString & aStringToInsert,
|
||||
nsIPrivateTextRangeList* aTextRangeList,
|
||||
IMETextTxn ** aTxn)
|
||||
{
|
||||
NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
|
||||
NS_ASSERTION(aTxn, "illegal value- null ptr- aTxn");
|
||||
if((nsnull == aTextRangeList) || (nsnull == aTxn))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result;
|
||||
|
||||
if (mIMETextNode==nsnull)
|
||||
BeginComposition(nsnull);
|
||||
result = BeginComposition(nsnull);
|
||||
NS_ASSERTION( NS_SUCCEEDED(result), "BeginComposition failed");
|
||||
if(NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn);
|
||||
NS_ASSERTION( NS_SUCCEEDED(result), "TransactionFactory::GetNewTransaction failed");
|
||||
if(NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
if (nsnull!=*aTxn) {
|
||||
result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,aTextRangeList,aStringToInsert,mPresShellWeak);
|
||||
NS_ASSERTION( NS_SUCCEEDED(result), "nsIMETextTxn::Init failed");
|
||||
}
|
||||
else {
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -61,6 +61,10 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement,
|
||||
const nsString &aStringToInsert,
|
||||
nsWeakPtr aPresShellWeak)
|
||||
{
|
||||
NS_ASSERTION(aElement, "illegal value- null ptr- aElement");
|
||||
NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList");
|
||||
if((nsnull == aElement) || (nsnull == aTextRangeList))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
mElement = do_QueryInterface(aElement);
|
||||
mOffset = aOffset;
|
||||
mReplaceLength = aReplaceLength;
|
||||
@ -125,6 +129,11 @@ NS_IMETHODIMP IMETextTxn::Undo(void)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
NS_ASSERTION(aDidMerge, "illegal vaule- null ptr- aDidMerge");
|
||||
NS_ASSERTION(aTransaction, "illegal vaule- null ptr- aTransaction");
|
||||
if((nsnull == aDidMerge) || (nsnull == aTransaction))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result;
|
||||
#ifdef DEBUG_TAGUE
|
||||
printf("Merge IME Text element = %p\n", mElement.get());
|
||||
@ -190,11 +199,18 @@ NS_IMETHODIMP IMETextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
NS_ASSERTION(aOutputStream, "illegal value- null ptr- aOutputStream");
|
||||
if(nsnull == aOutputStream)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "illegal value- null ptr- aString");
|
||||
if(nsnull == aString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Remove Text: ";
|
||||
@ -205,6 +221,10 @@ NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "illegal value- null ptr- aString");
|
||||
if(nsnull == aString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (nsnull!=aString)
|
||||
{
|
||||
*aString="Insert Text: ";
|
||||
@ -233,6 +253,9 @@ IMETextTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
|
||||
NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aTextRangeList)
|
||||
{
|
||||
NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
|
||||
if(nsnull == aTextRangeList)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
aResult = mStringToInsert;
|
||||
*aTextRangeList = mRangeList;
|
||||
return NS_OK;
|
||||
|
@ -1363,6 +1363,7 @@ nsEditor::BeginComposition(nsTextEventReply* aReply)
|
||||
if ((NS_SUCCEEDED(result)) && (node))
|
||||
{
|
||||
nodeAsText = do_QueryInterface(node);
|
||||
NS_ASSERTION(nodeAsText, "cannot get Text Node");
|
||||
range->GetStartOffset(&offset);
|
||||
if (!nodeAsText) {
|
||||
result = NS_ERROR_EDITOR_NO_TEXTNODE;
|
||||
@ -1402,8 +1403,12 @@ nsEditor::EndComposition(void)
|
||||
result = TransactionFactory::GetNewTransaction(IMECommitTxn::GetCID(), (EditTxn**)&commitTxn);
|
||||
if (NS_SUCCEEDED(result) && commitTxn!=nsnull)
|
||||
{
|
||||
commitTxn->Init();
|
||||
result = Do(commitTxn);
|
||||
result = commitTxn->Init();
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "commitTxt->Init failed");
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
result = Do(commitTxn);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "nsEditor::Do failed");
|
||||
}
|
||||
}
|
||||
|
||||
/* reset the data we need to construct a transaction */
|
||||
@ -1417,6 +1422,11 @@ nsEditor::EndComposition(void)
|
||||
NS_IMETHODIMP
|
||||
nsEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply)
|
||||
{
|
||||
NS_ASSERTION(aTextRangeList, "null ptr- aTextRangeList");
|
||||
NS_ASSERTION(aReply, "null ptr- aReply");
|
||||
if((nsnull == aTextRangeList) || (nsnull == aReply))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsICaret> caretP;
|
||||
nsresult result = SetInputMethodText(aCompositionString,aTextRangeList);
|
||||
mIMEBufferLength = aCompositionString.Length();
|
||||
@ -1424,9 +1434,12 @@ nsEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivateTex
|
||||
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
if (!ps) return NS_ERROR_NOT_INITIALIZED;
|
||||
ps->GetCaret(getter_AddRefs(caretP));
|
||||
caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
|
||||
|
||||
result = ps->GetCaret(getter_AddRefs(caretP));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get caret");
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
result = caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get window relative coordinates");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -4285,14 +4298,27 @@ nsEditor::CreateTxnForIMEText(const nsString & aStringToInsert,
|
||||
nsIPrivateTextRangeList* aTextRangeList,
|
||||
IMETextTxn ** aTxn)
|
||||
{
|
||||
NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
|
||||
NS_ASSERTION(aTxn, "illegal value- null ptr- aTxn");
|
||||
if((nsnull == aTextRangeList) || (nsnull == aTxn))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult result;
|
||||
|
||||
if (mIMETextNode==nsnull)
|
||||
BeginComposition(nsnull);
|
||||
result = BeginComposition(nsnull);
|
||||
NS_ASSERTION( NS_SUCCEEDED(result), "BeginComposition failed");
|
||||
if(NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn);
|
||||
NS_ASSERTION( NS_SUCCEEDED(result), "TransactionFactory::GetNewTransaction failed");
|
||||
if(NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
if (nsnull!=*aTxn) {
|
||||
result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,aTextRangeList,aStringToInsert,mPresShellWeak);
|
||||
NS_ASSERTION( NS_SUCCEEDED(result), "nsIMETextTxn::Init failed");
|
||||
}
|
||||
else {
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
Loading…
x
Reference in New Issue
Block a user