Skip to content

Commit 0425e42

Browse files
committed
Bug 1484496: Part 3 - Fix nsISimpleEnumerator implementations with broken contracts. r=froydnj
The nsISimpleEnumerator contract specifies that GetNext() returns NS_ERROR_FAILURE when iteration is complete. Several implementations, however, either return NS_OK and a null result, or return some other error code, when iteration is complete. Since my initial implementation of the JS iteration stubs rely on the contract-defined behavior of GetNext(), these need to be fixed before it can land. Differential Revision: https://phabricator.services.mozilla.com/D3726 --HG-- extra : rebase_source : aab0395df52e18ccff5b0a2489a983013bf484b1 extra : histedit_source : a5644f0a88799b4463af9dd01dfec33b373b1f58
1 parent 65c28aa commit 0425e42

File tree

7 files changed

+20
-9
lines changed

7 files changed

+20
-9
lines changed

toolkit/components/windowwatcher/nsWindowWatcher.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ nsWatcherWindowEnumerator::GetNext(nsISupports** aResult)
205205
if (mCurrentPosition) {
206206
CallQueryInterface(mCurrentPosition->mWindow, aResult);
207207
mCurrentPosition = FindNext();
208+
return NS_OK;
208209
}
209-
return NS_OK;
210+
return NS_ERROR_FAILURE;
210211
}
211212

212213
nsWatcherWindowEntry*

xpcom/ds/nsEnumeratorUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ EmptyEnumeratorImpl::HasMore(bool* aResult)
7373
NS_IMETHODIMP
7474
EmptyEnumeratorImpl::GetNext(nsISupports** aResult)
7575
{
76-
return NS_ERROR_UNEXPECTED;
76+
return NS_ERROR_FAILURE;
7777
}
7878

7979
NS_IMETHODIMP
@@ -144,7 +144,7 @@ nsSingletonEnumerator::GetNext(nsISupports** aResult)
144144
}
145145

146146
if (mConsumed) {
147-
return NS_ERROR_UNEXPECTED;
147+
return NS_ERROR_FAILURE;
148148
}
149149

150150
mConsumed = true;
@@ -246,7 +246,7 @@ nsUnionEnumerator::GetNext(nsISupports** aResult)
246246
}
247247

248248
if (mConsumed) {
249-
return NS_ERROR_UNEXPECTED;
249+
return NS_ERROR_FAILURE;
250250
}
251251

252252
if (!mAtSecond) {

xpcom/ds/nsObserverList.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ NS_IMETHODIMP
129129
nsObserverEnumerator::GetNext(nsISupports** aResult)
130130
{
131131
if (mIndex == mObservers.Count()) {
132-
NS_ERROR("Enumerating after HasMoreElements returned false.");
133-
return NS_ERROR_UNEXPECTED;
132+
return NS_ERROR_FAILURE;
134133
}
135134

136135
NS_ADDREF(*aResult = mObservers[mIndex]);

xpcom/ds/nsStringEnumerator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ nsStringEnumerator::HasMoreElements(bool* aResult)
117117
NS_IMETHODIMP
118118
nsStringEnumerator::GetNext(nsISupports** aResult)
119119
{
120+
if (mIndex >= mArray->Length()) {
121+
return NS_ERROR_FAILURE;
122+
}
123+
120124
if (mIsUnicode) {
121125
nsSupportsString* stringImpl = new nsSupportsString();
122126
if (!stringImpl) {

xpcom/io/nsLocalFileUnix.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ nsDirEnumeratorUnix::GetNext(nsISupports** aResult)
179179
if (NS_FAILED(rv)) {
180180
return rv;
181181
}
182+
if (!file) {
183+
return NS_ERROR_FAILURE;
184+
}
182185
file.forget(aResult);
183186
return NS_OK;
184187
}

xpcom/io/nsLocalFileWin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ class nsDirEnumerator final
769769
if (NS_FAILED(rv)) {
770770
return rv;
771771
}
772+
if (!hasMore) {
773+
return NS_ERROR_FAILURE;
774+
}
772775

773776
mNext.forget(aResult);
774777
return NS_OK;
@@ -3628,7 +3631,7 @@ nsDriveEnumerator::GetNext(nsISupports** aNext)
36283631
* character of the current drive. */
36293632
if (*mStartOfCurrentDrive == L'\0') {
36303633
*aNext = nullptr;
3631-
return NS_OK;
3634+
return NS_ERROR_FAILURE;
36323635
}
36333636

36343637
nsAString::const_iterator driveEnd = mStartOfCurrentDrive;

xpfe/appshell/nsAppShellWindowEnumerator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ NS_IMETHODIMP nsASDOMWindowEnumerator::GetNext(nsISupports **retval)
208208
if (domWindow)
209209
return CallQueryInterface(domWindow, retval);
210210
}
211-
return NS_OK;
211+
return NS_ERROR_FAILURE;
212212
}
213213

214214
//
@@ -235,8 +235,9 @@ NS_IMETHODIMP nsASXULWindowEnumerator::GetNext(nsISupports **retval)
235235
if (mCurrentPosition) {
236236
CallQueryInterface(mCurrentPosition->mWindow, retval);
237237
mCurrentPosition = FindNext();
238+
return NS_OK;
238239
}
239-
return NS_OK;
240+
return NS_ERROR_FAILURE;
240241
}
241242

242243
//

0 commit comments

Comments
 (0)