forked from mirrors/gecko-dev
Bug 1895572 - Throw correct exception when resolving namespaces for XPath. r=dom-core,mccr8,farre
Differential Revision: https://phabricator.services.mozilla.com/D209728
This commit is contained in:
parent
4ca30b8884
commit
249ac98ffe
10 changed files with 32 additions and 83 deletions
|
|
@ -43,7 +43,7 @@ class XPathEvaluatorParseContext : public txIParseContext {
|
||||||
|
|
||||||
nsresult getError() { return mLastError; }
|
nsresult getError() { return mLastError; }
|
||||||
|
|
||||||
nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) override;
|
int32_t resolveNamespacePrefix(nsAtom* aPrefix) override;
|
||||||
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
||||||
FunctionCall** aFunction) override;
|
FunctionCall** aFunction) override;
|
||||||
bool caseInsensitiveNameTests() override;
|
bool caseInsensitiveNameTests() override;
|
||||||
|
|
@ -129,12 +129,9 @@ already_AddRefed<XPathResult> XPathEvaluator::Evaluate(
|
||||||
* XPathNSResolver
|
* XPathNSResolver
|
||||||
*/
|
*/
|
||||||
|
|
||||||
nsresult XPathEvaluatorParseContext::resolveNamespacePrefix(nsAtom* aPrefix,
|
int32_t XPathEvaluatorParseContext::resolveNamespacePrefix(nsAtom* aPrefix) {
|
||||||
int32_t& aID) {
|
|
||||||
aID = kNameSpaceID_Unknown;
|
|
||||||
|
|
||||||
if (!mResolver && !mResolverNode) {
|
if (!mResolver && !mResolverNode) {
|
||||||
return NS_ERROR_DOM_NAMESPACE_ERR;
|
return kNameSpaceID_Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString prefix;
|
nsAutoString prefix;
|
||||||
|
|
@ -147,7 +144,8 @@ nsresult XPathEvaluatorParseContext::resolveNamespacePrefix(nsAtom* aPrefix,
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
mResolver->LookupNamespaceURI(prefix, ns, rv);
|
mResolver->LookupNamespaceURI(prefix, ns, rv);
|
||||||
if (rv.Failed()) {
|
if (rv.Failed()) {
|
||||||
return rv.StealNSResult();
|
rv.SuppressException();
|
||||||
|
return kNameSpaceID_Unknown;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (aPrefix == nsGkAtoms::xml) {
|
if (aPrefix == nsGkAtoms::xml) {
|
||||||
|
|
@ -158,17 +156,19 @@ nsresult XPathEvaluatorParseContext::resolveNamespacePrefix(nsAtom* aPrefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DOMStringIsNull(ns)) {
|
if (DOMStringIsNull(ns)) {
|
||||||
return NS_ERROR_DOM_NAMESPACE_ERR;
|
return kNameSpaceID_Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ns.IsEmpty()) {
|
if (ns.IsEmpty()) {
|
||||||
aID = kNameSpaceID_None;
|
return kNameSpaceID_None;
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the namespaceID for the URI
|
// get the namespaceID for the URI
|
||||||
return nsNameSpaceManager::GetInstance()->RegisterNameSpace(ns, aID);
|
int32_t id;
|
||||||
|
return NS_SUCCEEDED(
|
||||||
|
nsNameSpaceManager::GetInstance()->RegisterNameSpace(ns, id))
|
||||||
|
? id
|
||||||
|
: kNameSpaceID_Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult XPathEvaluatorParseContext::resolveFunctionCall(nsAtom* aName,
|
nsresult XPathEvaluatorParseContext::resolveFunctionCall(nsAtom* aName,
|
||||||
|
|
|
||||||
|
|
@ -823,33 +823,25 @@ nsresult txExprParser::resolveQName(const nsAString& aQName, nsAtom** aPrefix,
|
||||||
txIParseContext* aContext,
|
txIParseContext* aContext,
|
||||||
nsAtom** aLocalName, int32_t& aNamespace,
|
nsAtom** aLocalName, int32_t& aNamespace,
|
||||||
bool aIsNameTest) {
|
bool aIsNameTest) {
|
||||||
aNamespace = kNameSpaceID_None;
|
|
||||||
int32_t idx = aQName.FindChar(':');
|
int32_t idx = aQName.FindChar(':');
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
*aPrefix = NS_Atomize(StringHead(aQName, (uint32_t)idx)).take();
|
*aPrefix = NS_AtomizeMainThread(StringHead(aQName, (uint32_t)idx)).take();
|
||||||
if (!*aPrefix) {
|
*aLocalName = NS_AtomizeMainThread(Substring(aQName, (uint32_t)idx + 1,
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
aQName.Length() - (idx + 1)))
|
||||||
}
|
|
||||||
*aLocalName = NS_Atomize(Substring(aQName, (uint32_t)idx + 1,
|
|
||||||
aQName.Length() - (idx + 1)))
|
|
||||||
.take();
|
.take();
|
||||||
if (!*aLocalName) {
|
aNamespace = aContext->resolveNamespacePrefix(*aPrefix);
|
||||||
NS_RELEASE(*aPrefix);
|
return aNamespace != kNameSpaceID_Unknown ? NS_OK
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
: NS_ERROR_DOM_NAMESPACE_ERR;
|
||||||
}
|
|
||||||
return aContext->resolveNamespacePrefix(*aPrefix, aNamespace);
|
|
||||||
}
|
}
|
||||||
|
aNamespace = kNameSpaceID_None;
|
||||||
// the lexer dealt with idx == 0
|
// the lexer dealt with idx == 0
|
||||||
*aPrefix = 0;
|
*aPrefix = 0;
|
||||||
if (aIsNameTest && aContext->caseInsensitiveNameTests()) {
|
if (aIsNameTest && aContext->caseInsensitiveNameTests()) {
|
||||||
nsAutoString lcname;
|
nsAutoString lcname;
|
||||||
nsContentUtils::ASCIIToLower(aQName, lcname);
|
nsContentUtils::ASCIIToLower(aQName, lcname);
|
||||||
*aLocalName = NS_Atomize(lcname).take();
|
*aLocalName = NS_AtomizeMainThread(lcname).take();
|
||||||
} else {
|
} else {
|
||||||
*aLocalName = NS_Atomize(aQName).take();
|
*aLocalName = NS_AtomizeMainThread(aQName).take();
|
||||||
}
|
|
||||||
if (!*aLocalName) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class txIParseContext {
|
||||||
/*
|
/*
|
||||||
* Return a namespaceID for a given prefix.
|
* Return a namespaceID for a given prefix.
|
||||||
*/
|
*/
|
||||||
virtual nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) = 0;
|
virtual int32_t resolveNamespacePrefix(nsAtom* aPrefix) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a FunctionCall, needed for extension function calls and
|
* Create a FunctionCall, needed for extension function calls and
|
||||||
|
|
|
||||||
|
|
@ -330,9 +330,8 @@ class txXSLTParamContext : public txIParseContext, public txIEvalContext {
|
||||||
: mResolver(aResolver), mContext(aContext), mRecycler(aRecycler) {}
|
: mResolver(aResolver), mContext(aContext), mRecycler(aRecycler) {}
|
||||||
|
|
||||||
// txIParseContext
|
// txIParseContext
|
||||||
nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) override {
|
int32_t resolveNamespacePrefix(nsAtom* aPrefix) override {
|
||||||
aID = mResolver->lookupNamespace(aPrefix);
|
return mResolver->lookupNamespace(aPrefix);
|
||||||
return aID == kNameSpaceID_Unknown ? NS_ERROR_DOM_NAMESPACE_ERR : NS_OK;
|
|
||||||
}
|
}
|
||||||
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
||||||
FunctionCall** aFunction) override {
|
FunctionCall** aFunction) override {
|
||||||
|
|
|
||||||
|
|
@ -689,12 +689,10 @@ void txStylesheetCompilerState::addVariable(const txExpandedName& aName) {
|
||||||
mInScopeVariables.AppendElement(aName);
|
mInScopeVariables.AppendElement(aName);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult txStylesheetCompilerState::resolveNamespacePrefix(nsAtom* aPrefix,
|
int32_t txStylesheetCompilerState::resolveNamespacePrefix(nsAtom* aPrefix) {
|
||||||
int32_t& aID) {
|
|
||||||
NS_ASSERTION(aPrefix && aPrefix != nsGkAtoms::_empty,
|
NS_ASSERTION(aPrefix && aPrefix != nsGkAtoms::_empty,
|
||||||
"caller should handle default namespace ''");
|
"caller should handle default namespace ''");
|
||||||
aID = mElementContext->mMappings->lookupNamespace(aPrefix);
|
return mElementContext->mMappings->lookupNamespace(aPrefix);
|
||||||
return (aID != kNameSpaceID_Unknown) ? NS_OK : NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ class txStylesheetCompilerState : public txIParseContext {
|
||||||
void addVariable(const txExpandedName& aName);
|
void addVariable(const txExpandedName& aName);
|
||||||
|
|
||||||
// txIParseContext
|
// txIParseContext
|
||||||
nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) override;
|
int32_t resolveNamespacePrefix(nsAtom* aPrefix) override;
|
||||||
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
||||||
FunctionCall** aFunction) override;
|
FunctionCall** aFunction) override;
|
||||||
bool caseInsensitiveNameTests() override;
|
bool caseInsensitiveNameTests() override;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
[resolver-callback-interface-cross-realm.tentative.html]
|
|
||||||
expected:
|
|
||||||
if (os == "android") and fission: [OK, TIMEOUT]
|
|
||||||
[XPathNSResolver is cross-realm plain object without 'lookupNamespaceURI' property]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XPathNSResolver is cross-realm plain object with non-callable 'lookupNamespaceURI' property]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XPathNSResolver is cross-realm non-callable revoked Proxy]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XPathNSResolver is cross-realm callable revoked Proxy]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XPathNSResolver is cross-realm plain object with revoked Proxy as 'lookupNamespaceURI' property]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
[resolver-callback-interface.html]
|
|
||||||
expected:
|
|
||||||
if (os == "android") and fission: [OK, TIMEOUT]
|
|
||||||
[object resolver: abrupt completion from Get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[object resolver: 'lookupNamespaceURI' is falsy and not callable]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[object resolver: 'lookupNamespaceURI' is thruthy and not callable]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[callable resolver: abrupt completion from Call]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
[resolver-non-string-result.html]
|
|
||||||
expected:
|
|
||||||
if (os == "android") and fission: [OK, TIMEOUT]
|
|
||||||
[symbol]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[object coercion (abrupt completion)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
@ -1317,14 +1317,13 @@ class FormDataParseContext : public txIParseContext {
|
||||||
explicit FormDataParseContext(bool aCaseInsensitive)
|
explicit FormDataParseContext(bool aCaseInsensitive)
|
||||||
: mIsCaseInsensitive(aCaseInsensitive) {}
|
: mIsCaseInsensitive(aCaseInsensitive) {}
|
||||||
|
|
||||||
nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) override {
|
int32_t resolveNamespacePrefix(nsAtom* aPrefix) override {
|
||||||
if (aPrefix == nsGkAtoms::xul) {
|
if (aPrefix == nsGkAtoms::xul) {
|
||||||
aID = kNameSpaceID_XUL;
|
return kNameSpaceID_XUL;
|
||||||
} else {
|
|
||||||
MOZ_ASSERT(nsDependentAtomString(aPrefix).EqualsLiteral("xhtml"));
|
|
||||||
aID = kNameSpaceID_XHTML;
|
|
||||||
}
|
}
|
||||||
return NS_OK;
|
|
||||||
|
MOZ_ASSERT(nsDependentAtomString(aPrefix).EqualsLiteral("xhtml"));
|
||||||
|
return kNameSpaceID_XHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue