Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/xslt/xpath/txNameTest.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "txExpr.h"
7
#include "nsAtom.h"
8
#include "nsGkAtoms.h"
9
#include "txXPathTreeWalker.h"
10
#include "txIXPathContext.h"
11
12
txNameTest::txNameTest(nsAtom* aPrefix, nsAtom* aLocalName, int32_t aNSID,
13
                       uint16_t aNodeType)
14
    :mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID),
15
     mNodeType(aNodeType)
16
0
{
17
0
    if (aPrefix == nsGkAtoms::_empty)
18
0
        mPrefix = nullptr;
19
0
    NS_ASSERTION(aLocalName, "txNameTest without a local name?");
20
0
    NS_ASSERTION(aNodeType == txXPathNodeType::DOCUMENT_NODE ||
21
0
                 aNodeType == txXPathNodeType::ELEMENT_NODE ||
22
0
                 aNodeType == txXPathNodeType::ATTRIBUTE_NODE,
23
0
                 "Go fix txNameTest::matches");
24
0
}
25
26
nsresult
27
txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext,
28
                    bool& aMatched)
29
0
{
30
0
    if ((mNodeType == txXPathNodeType::ELEMENT_NODE &&
31
0
         !txXPathNodeUtils::isElement(aNode)) ||
32
0
        (mNodeType == txXPathNodeType::ATTRIBUTE_NODE &&
33
0
         !txXPathNodeUtils::isAttribute(aNode)) ||
34
0
        (mNodeType == txXPathNodeType::DOCUMENT_NODE &&
35
0
         !txXPathNodeUtils::isRoot(aNode))) {
36
0
        aMatched = false;
37
0
        return NS_OK;
38
0
    }
39
0
40
0
    // Totally wild?
41
0
    if (mLocalName == nsGkAtoms::_asterisk && !mPrefix) {
42
0
        aMatched = true;
43
0
        return NS_OK;
44
0
    }
45
0
46
0
    // Compare namespaces
47
0
    if (mNamespace != txXPathNodeUtils::getNamespaceID(aNode)
48
0
        && !(mNamespace == kNameSpaceID_None &&
49
0
             txXPathNodeUtils::isHTMLElementInHTMLDocument(aNode))
50
0
       ) {
51
0
        aMatched = false;
52
0
        return NS_OK;
53
0
    }
54
0
55
0
    // Name wild?
56
0
    if (mLocalName == nsGkAtoms::_asterisk) {
57
0
        aMatched = true;
58
0
        return NS_OK;
59
0
    }
60
0
61
0
    // Compare local-names
62
0
    aMatched = txXPathNodeUtils::localNameEquals(aNode, mLocalName);
63
0
    return NS_OK;
64
0
}
65
66
/*
67
 * Returns the default priority of this txNodeTest
68
 */
69
double txNameTest::getDefaultPriority()
70
0
{
71
0
    if (mLocalName == nsGkAtoms::_asterisk) {
72
0
        if (!mPrefix)
73
0
            return -0.5;
74
0
        return -0.25;
75
0
    }
76
0
    return 0;
77
0
}
78
79
txNodeTest::NodeTestType
80
txNameTest::getType()
81
0
{
82
0
    return NAME_TEST;
83
0
}
84
85
bool
86
txNameTest::isSensitiveTo(Expr::ContextSensitivity aContext)
87
0
{
88
0
    return !!(aContext & Expr::NODE_CONTEXT);
89
0
}
90
91
#ifdef TX_TO_STRING
92
void
93
txNameTest::toString(nsAString& aDest)
94
{
95
    if (mPrefix) {
96
        nsAutoString prefix;
97
        mPrefix->ToString(prefix);
98
        aDest.Append(prefix);
99
        aDest.Append(char16_t(':'));
100
    }
101
    nsAutoString localName;
102
    mLocalName->ToString(localName);
103
    aDest.Append(localName);
104
}
105
#endif