Bug 1614174. Stop using NS_ERROR_DOM_TYPE_ERR in XPath. r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D62157

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2020-02-10 21:43:35 +00:00
Родитель c41ef3c07e
Коммит eb4285b299
3 изменённых файлов: 23 добавлений и 21 удалений

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

@ -164,7 +164,10 @@ already_AddRefed<XPathResult> XPathExpression::EvaluateWithContext(
xpathResult = new XPathResult(&aContextNode);
}
aRv = xpathResult->SetExprResult(exprResult, resultType, &aContextNode);
xpathResult->SetExprResult(exprResult, resultType, &aContextNode, aRv);
if (aRv.Failed()) {
return nullptr;
}
return xpathResult.forget();
}

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

@ -79,7 +79,7 @@ void XPathResult::RemoveObserver() {
nsINode* XPathResult::IterateNext(ErrorResult& aRv) {
if (!isIterator()) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not an iterator");
return nullptr;
}
@ -88,7 +88,7 @@ nsINode* XPathResult::IterateNext(ErrorResult& aRv) {
}
if (mInvalidIteratorState) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
aRv.ThrowInvalidStateError("The document has been mutated since the result was returned");
return nullptr;
}
@ -126,9 +126,9 @@ void XPathResult::ContentRemoved(nsIContent* aChild,
Invalidate(aChild->GetParent());
}
nsresult XPathResult::SetExprResult(txAExprResult* aExprResult,
uint16_t aResultType,
nsINode* aContextNode) {
void XPathResult::SetExprResult(txAExprResult* aExprResult,
uint16_t aResultType, nsINode* aContextNode,
ErrorResult& aRv) {
MOZ_ASSERT(aExprResult);
if ((isSnapshot(aResultType) || isIterator(aResultType) ||
@ -137,7 +137,8 @@ nsresult XPathResult::SetExprResult(txAExprResult* aExprResult,
// The DOM spec doesn't really say what should happen when reusing an
// XPathResult and an error is thrown. Let's not touch the XPathResult
// in that case.
return NS_ERROR_DOM_TYPE_ERR;
aRv.ThrowTypeError(u"Result type mismatch");
return;
}
mResultType = aResultType;
@ -184,7 +185,7 @@ nsresult XPathResult::SetExprResult(txAExprResult* aExprResult,
}
if (!isIterator()) {
return NS_OK;
return;
}
mCurrentPos = 0;
@ -199,8 +200,6 @@ nsresult XPathResult::SetExprResult(txAExprResult* aExprResult,
mDocument->AddMutationObserver(this);
}
}
return NS_OK;
}
void XPathResult::Invalidate(const nsIContent* aChangeRoot) {

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

@ -31,9 +31,9 @@ class txAExprResult;
class nsIXPathResult : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID)
virtual nsresult SetExprResult(txAExprResult* aExprResult,
uint16_t aResultType,
nsINode* aContextNode) = 0;
virtual void SetExprResult(txAExprResult* aExprResult, uint16_t aResultType,
nsINode* aContextNode,
mozilla::ErrorResult& aRv) = 0;
virtual nsresult GetExprResult(txAExprResult** aExprResult) = 0;
virtual nsresult Clone(nsIXPathResult** aResult) = 0;
};
@ -83,7 +83,7 @@ class XPathResult final : public nsIXPathResult,
uint16_t ResultType() const { return mResultType; }
double GetNumberValue(ErrorResult& aRv) const {
if (mResultType != NUMBER_TYPE) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not a number");
return 0;
}
@ -91,7 +91,7 @@ class XPathResult final : public nsIXPathResult,
}
void GetStringValue(nsAString& aStringValue, ErrorResult& aRv) const {
if (mResultType != STRING_TYPE) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not a string");
return;
}
@ -99,7 +99,7 @@ class XPathResult final : public nsIXPathResult,
}
bool GetBooleanValue(ErrorResult& aRv) const {
if (mResultType != BOOLEAN_TYPE) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not a boolean");
return false;
}
@ -107,7 +107,7 @@ class XPathResult final : public nsIXPathResult,
}
nsINode* GetSingleNodeValue(ErrorResult& aRv) const {
if (!isNode()) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not a node");
return nullptr;
}
@ -118,7 +118,7 @@ class XPathResult final : public nsIXPathResult,
}
uint32_t GetSnapshotLength(ErrorResult& aRv) const {
if (!isSnapshot()) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not a snapshot");
return 0;
}
@ -127,7 +127,7 @@ class XPathResult final : public nsIXPathResult,
nsINode* IterateNext(ErrorResult& aRv);
nsINode* SnapshotItem(uint32_t aIndex, ErrorResult& aRv) const {
if (!isSnapshot()) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
aRv.ThrowTypeError(u"Result is not a snapshot");
return nullptr;
}
@ -142,8 +142,8 @@ class XPathResult final : public nsIXPathResult,
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
nsresult SetExprResult(txAExprResult* aExprResult, uint16_t aResultType,
nsINode* aContextNode) override;
void SetExprResult(txAExprResult* aExprResult, uint16_t aResultType,
nsINode* aContextNode, ErrorResult& aRv) override;
nsresult GetExprResult(txAExprResult** aExprResult) override;
nsresult Clone(nsIXPathResult** aResult) override;
void RemoveObserver();