Skip to content

Commit

Permalink
Bug 1157898 part 5. Eliminate the remaining non-ErrorResult consumers…
Browse files Browse the repository at this point in the history
… of ErrorResult::ErrorCode and make it protected. r=peterv
  • Loading branch information
bzbarsky committed Apr 27, 2015
1 parent 812e53e commit ee28d44
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,7 @@ NS_IMETHODIMP
nsGlobalWindow::GetWindow(nsIDOMWindow** aWindow)
{
ErrorResult rv;
FORWARD_TO_OUTER_OR_THROW(GetWindow, (aWindow), rv, rv.ErrorCode());
FORWARD_TO_OUTER_OR_THROW(GetWindow, (aWindow), rv, rv.StealNSResult());

nsCOMPtr<nsIDOMWindow> window = Window();
window.forget(aWindow);
Expand Down
8 changes: 8 additions & 0 deletions dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ ErrorResult::ReportNotEnoughArgsError(JSContext* cx,
ThrowErrorMessage(cx, dom::MSG_MISSING_ARGUMENTS, errorMessage.get());
}

void
ErrorResult::ReportGenericError(JSContext* cx)
{
MOZ_ASSERT(!IsErrorWithMessage());
MOZ_ASSERT(!IsJSException());
dom::Throw(cx, ErrorCode());
}

ErrorResult&
ErrorResult::operator=(ErrorResult&& aRHS)
{
Expand Down
3 changes: 2 additions & 1 deletion dom/bindings/BindingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ ThrowMethodFailedWithDetails(JSContext* cx, ErrorResult& rv,
rv.ReportNotEnoughArgsError(cx, ifaceName, memberName);
return false;
}
return Throw(cx, rv.ErrorCode());
rv.ReportGenericError(cx);
return false;
}

// Returns true if the JSClass is used for DOM objects.
Expand Down
22 changes: 16 additions & 6 deletions dom/bindings/ErrorResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class ErrorResult {
const char* memberName);
bool IsNotEnoughArgsError() const { return ErrorCode() == NS_ERROR_XPC_NOT_ENOUGH_ARGS; }

// Report a generic error. This should only be used if we're not
// some more specific exception type.
void ReportGenericError(JSContext* cx);

// Support for uncatchable exceptions.
void ThrowUncatchableException() {
Throw(NS_ERROR_UNCATCHABLE_EXCEPTION);
Expand Down Expand Up @@ -160,14 +164,20 @@ class ErrorResult {
return NS_FAILED(mResult);
}

nsresult ErrorCode() const {
return mResult;
}

bool ErrorCodeIs(nsresult rv) const {
return mResult == rv;
}

// For use in logging ONLY.
uint32_t ErrorCodeAsInt() const {
return static_cast<uint32_t>(ErrorCode());
}

protected:
nsresult ErrorCode() const {
return mResult;
}

private:
friend struct IPC::ParamTraits<ErrorResult>;
void SerializeMessage(IPC::Message* aMsg) const;
Expand Down Expand Up @@ -225,7 +235,7 @@ class ErrorResult {
if (res.Failed()) { \
nsCString msg; \
msg.AppendPrintf("ENSURE_SUCCESS(%s, %s) failed with " \
"result 0x%X", #res, #ret, res.ErrorCode()); \
"result 0x%X", #res, #ret, res.ErrorCodeAsInt()); \
NS_WARNING(msg.get()); \
return ret; \
} \
Expand All @@ -236,7 +246,7 @@ class ErrorResult {
if (res.Failed()) { \
nsCString msg; \
msg.AppendPrintf("ENSURE_SUCCESS_VOID(%s) failed with " \
"result 0x%X", #res, res.ErrorCode()); \
"result 0x%X", #res, res.ErrorCodeAsInt()); \
NS_WARNING(msg.get()); \
return; \
} \
Expand Down
2 changes: 1 addition & 1 deletion dom/events/EventListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ EventListenerManager::HandleEventSubType(Listener* aListener,
ErrorResult rv;
listenerHolder.GetWebIDLCallback()->
HandleEvent(aCurrentTarget, *(aDOMEvent->InternalDOMEvent()), rv);
result = rv.ErrorCode();
result = rv.StealNSResult();
} else {
result = listenerHolder.GetXPCOMCallback()->HandleEvent(aDOMEvent);
}
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLCanvasElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ HTMLCanvasElement::CopyInnerTo(Element* aDest)
ErrorResult err;
context2d->DrawImage(element,
0.0, 0.0, err);
rv = err.ErrorCode();
rv = err.StealNSResult();
}
}
return rv;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLOptionsCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ HTMLOptionsCollection::SetOption(uint32_t aIndex,
nsCOMPtr<nsINode> node = do_QueryInterface(aOption);
ErrorResult res;
parent->ReplaceChild(*node, *refChild, res);
rv = res.ErrorCode();
rv = res.StealNSResult();
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/storage/DOMStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DOMStorage final
{
RemoveItem(aKey, aRv);

aFound = (aRv.ErrorCode() != NS_SUCCESS_DOM_NO_OPERATION);
aFound = !aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION);
}

void Clear(ErrorResult& aRv);
Expand Down
7 changes: 4 additions & 3 deletions dom/workers/ScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,9 @@ class ScriptLoaderRunnable final : public WorkerFeature,
nsRefPtr<Promise> cachePromise =
mCacheCreator->Cache_()->Put(request, *response, error);
if (NS_WARN_IF(error.Failed())) {
channel->Cancel(error.ErrorCode());
return error.StealNSResult();
nsresult rv = error.StealNSResult();
channel->Cancel(rv);
return rv;
}

nsRefPtr<CachePromiseHandler> promiseHandler =
Expand Down Expand Up @@ -1322,7 +1323,7 @@ CacheScriptLoader::Load(Cache* aCache)
ErrorResult error;
nsRefPtr<Promise> promise = aCache->Match(request, params, error);
if (NS_WARN_IF(error.Failed())) {
Fail(error.ErrorCode());
Fail(error.StealNSResult());
return;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/workers/ServiceWorkerScriptCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ CompareCache::ManageCacheResult(JSContext* aCx, JS::Handle<JS::Value> aValue)
CacheQueryOptions params;
nsRefPtr<Promise> promise = cache->Match(request, params, error);
if (NS_WARN_IF(error.Failed())) {
mManager->CacheFinished(error.ErrorCode(), false);
mManager->CacheFinished(error.StealNSResult(), false);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/workers/ServiceWorkerWindowClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ServiceWorkerWindowClient::Focus(ErrorResult& aRv) const
promiseProxy);
aRv = NS_DispatchToMainThread(r);
if (NS_WARN_IF(aRv.Failed())) {
promise->MaybeReject(aRv.ErrorCode());
promise->MaybeReject(aRv);
}

return promise.forget();
Expand Down
3 changes: 1 addition & 2 deletions dom/xul/nsXULElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,7 @@ nsXULElement::GetControllers(ErrorResult& rv)
rv = NS_NewXULControllers(nullptr, NS_GET_IID(nsIControllers),
reinterpret_cast<void**>(&slots->mControllers));

NS_ASSERTION(NS_SUCCEEDED(rv.ErrorCode()),
"unable to create a controllers");
NS_ASSERTION(!rv.Failed(), "unable to create a controllers");
if (rv.Failed()) {
return nullptr;
}
Expand Down
6 changes: 5 additions & 1 deletion editor/libeditor/nsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,10 +1445,14 @@ nsEditor::SplitNode(nsIContent& aNode, int32_t aOffset, ErrorResult& aResult)

mRangeUpdater.SelAdjSplitNode(aNode, aOffset, newNode);

nsresult result = aResult.StealNSResult();
for (auto& listener : mActionListeners) {
listener->DidSplitNode(aNode.AsDOMNode(), aOffset, GetAsDOMNode(newNode),
aResult.ErrorCode());
result);
}
// Note: result might be a success code, so we can't use Throw() to
// set it on aResult.
aResult = result;

return newNode;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/libeditor/nsHTMLEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert)
if (err.Failed()) {
#ifdef DEBUG
printf("Couldn't create contextual fragment: error was %X\n",
static_cast<uint32_t>(err.ErrorCode()));
err.ErrorCodeAsInt());
#endif
return err.StealNSResult();
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/spellcheck/src/mozInlineSpellChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
aSpellCheckSelection->GetRangesForInterval(*beginNode, beginOffset,
*endNode, endOffset,
true, ranges, erv);
ENSURE_SUCCESS(erv, erv.ErrorCode());
ENSURE_SUCCESS(erv, erv.StealNSResult());
for (uint32_t i = 0; i < ranges.Length(); i++)
RemoveRange(aSpellCheckSelection, ranges[i]);
}
Expand Down
12 changes: 3 additions & 9 deletions media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,7 @@ class JSErrorResult : public ErrorResult
~JSErrorResult()
{
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
WouldReportJSException();
if (IsJSException()) {
MOZ_ASSERT(NS_IsMainThread());
AutoJSContext cx;
Optional<JS::Handle<JS::Value> > value(cx);
StealJSException(cx, &value.Value());
}
SuppressException();
#endif
}
};
Expand Down Expand Up @@ -237,7 +231,7 @@ class TracksAvailableCallback : public DOMMediaStream::OnTracksAvailableCallback
if (jrv.Failed()) {
CSFLogError(logTag, ": OnAddTrack(%u) failed! Error: %u",
static_cast<unsigned>(i),
static_cast<unsigned>(jrv.ErrorCode()));
jrv.ErrorCodeAsInt());
}
}

Expand All @@ -252,7 +246,7 @@ class TracksAvailableCallback : public DOMMediaStream::OnTracksAvailableCallback
mObserver->OnAddStream(*aStream, rv);
if (rv.Failed()) {
CSFLogError(logTag, ": OnAddStream() failed! Error: %u",
static_cast<unsigned>(rv.ErrorCode()));
rv.ErrorCodeAsInt());
}
}
}
Expand Down

0 comments on commit ee28d44

Please sign in to comment.