Skip to content

Commit

Permalink
Bug 1157898 part 4. Add ErrorResult::ErrorCodeIs() and use it in vari…
Browse files Browse the repository at this point in the history
…ous places to get rid of ErrorCode(). r=peterv
  • Loading branch information
bzbarsky committed Apr 27, 2015
1 parent 6a46477 commit 812e53e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dom/base/nsINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,7 @@ nsINode::ParseSelectorList(const nsAString& aSelectorString,
// We hit this for syntax errors, which are quite common, so don't
// use NS_ENSURE_SUCCESS. (For example, jQuery has an extended set
// of selectors, but it sees if we can parse them first.)
MOZ_ASSERT(aRv.ErrorCode() == NS_ERROR_DOM_SYNTAX_ERR,
MOZ_ASSERT(aRv.ErrorCodeIs(NS_ERROR_DOM_SYNTAX_ERR),
"Unexpected error, so cached version won't return it");
cache.CacheList(aSelectorString, nullptr);
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ nsRange::IsPointInRange(nsINode& aParent, uint32_t aOffset, ErrorResult& aRv)
{
uint16_t compareResult = ComparePoint(aParent, aOffset, aRv);
// If the node isn't in the range's document, it clearly isn't in the range.
if (aRv.ErrorCode() == NS_ERROR_DOM_WRONG_DOCUMENT_ERR) {
aRv = NS_OK;
if (aRv.ErrorCodeIs(NS_ERROR_DOM_WRONG_DOCUMENT_ERR)) {
aRv.SuppressException();
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsXMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,10 @@ nsXMLHttpRequest::GetResponseHeader(const nsACString& header,
}

aRv = httpChannel->GetResponseHeader(header, _retval);
if (aRv.ErrorCode() == NS_ERROR_NOT_AVAILABLE) {
if (aRv.ErrorCodeIs(NS_ERROR_NOT_AVAILABLE)) {
// Means no header
_retval.SetIsVoid(true);
aRv = NS_OK;
aRv.SuppressException();
}
}

Expand Down
6 changes: 5 additions & 1 deletion dom/bindings/ErrorResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ErrorResult {

// StealJSException steals the JS Exception from the object. This method must
// be called only if IsJSException() returns true. This method also resets the
// ErrorCode() to NS_OK.
// error code to NS_OK.
void StealJSException(JSContext* cx, JS::MutableHandle<JS::Value> value);

void MOZ_ALWAYS_INLINE MightThrowJSException()
Expand Down Expand Up @@ -164,6 +164,10 @@ class ErrorResult {
return mResult;
}

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

private:
friend struct IPC::ParamTraits<ErrorResult>;
void SerializeMessage(IPC::Message* aMsg) const;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webaudio/AudioProcessingEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AudioProcessingEvent::LazilyCreateBuffer(uint32_t aNumberOfChannels,
AudioBuffer::Create(mNode->Context(), aNumberOfChannels,
mNode->BufferSize(),
mNode->Context()->SampleRate(), cx, aRv);
MOZ_ASSERT(buffer || aRv.ErrorCode() == NS_ERROR_OUT_OF_MEMORY);
MOZ_ASSERT(buffer || aRv.ErrorCodeIs(NS_ERROR_OUT_OF_MEMORY));
return buffer.forget();
}

Expand Down
6 changes: 3 additions & 3 deletions dom/storage/DOMStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ DOMStorage::SetItem(const nsAString& aKey, const nsAString& aData,
return;
}

if (aRv.ErrorCode() != NS_SUCCESS_DOM_NO_OPERATION) {
if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
BroadcastChangeNotification(aKey, old, aData);
}
}
Expand All @@ -148,7 +148,7 @@ DOMStorage::RemoveItem(const nsAString& aKey, ErrorResult& aRv)
return;
}

if (aRv.ErrorCode() != NS_SUCCESS_DOM_NO_OPERATION) {
if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
BroadcastChangeNotification(aKey, old, NullString());
}
}
Expand All @@ -166,7 +166,7 @@ DOMStorage::Clear(ErrorResult& aRv)
return;
}

if (aRv.ErrorCode() != NS_SUCCESS_DOM_NO_OPERATION) {
if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
BroadcastChangeNotification(NullString(), NullString(), NullString());
}
}
Expand Down
3 changes: 2 additions & 1 deletion dom/xslt/xpath/XPathEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ XPathEvaluator::CreateExpression(const nsAString & aExpression,
aRv = txExprParser::createExpr(PromiseFlatString(aExpression), aContext,
getter_Transfers(expression));
if (aRv.Failed()) {
if (aRv.ErrorCode() != NS_ERROR_DOM_NAMESPACE_ERR) {
if (!aRv.ErrorCodeIs(NS_ERROR_DOM_NAMESPACE_ERR)) {
aRv.SuppressException();
aRv.Throw(NS_ERROR_DOM_INVALID_EXPRESSION_ERR);
}

Expand Down

0 comments on commit 812e53e

Please sign in to comment.