Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/xslt/xpath/txUnionExpr.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 "txIXPathContext.h"
8
#include "txNodeSet.h"
9
10
  //-------------/
11
 //- UnionExpr -/
12
//-------------/
13
14
    //-----------------------------/
15
  //- Virtual methods from Expr -/
16
//-----------------------------/
17
18
/**
19
 * Evaluates this Expr based on the given context node and processor state
20
 * @param context the context node for evaluation of this Expr
21
 * @param ps the ContextState containing the stack information needed
22
 * for evaluation
23
 * @return the result of the evaluation
24
**/
25
nsresult
26
UnionExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
27
0
{
28
0
    *aResult = nullptr;
29
0
    RefPtr<txNodeSet> nodes;
30
0
    nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes));
31
0
    NS_ENSURE_SUCCESS(rv, rv);
32
0
33
0
    uint32_t i, len = mExpressions.Length();
34
0
    for (i = 0; i < len; ++i) {
35
0
        RefPtr<txAExprResult> exprResult;
36
0
        rv = mExpressions[i]->evaluate(aContext, getter_AddRefs(exprResult));
37
0
        NS_ENSURE_SUCCESS(rv, rv);
38
0
39
0
        if (exprResult->getResultType() != txAExprResult::NODESET) {
40
0
            //XXX ErrorReport: report nonnodeset error
41
0
            return NS_ERROR_XSLT_NODESET_EXPECTED;
42
0
        }
43
0
44
0
        RefPtr<txNodeSet> resultSet, ownedSet;
45
0
        resultSet = static_cast<txNodeSet*>
46
0
                               (static_cast<txAExprResult*>(exprResult));
47
0
        exprResult = nullptr;
48
0
        rv = aContext->recycler()->
49
0
            getNonSharedNodeSet(resultSet, getter_AddRefs(ownedSet));
50
0
        NS_ENSURE_SUCCESS(rv, rv);
51
0
52
0
        rv = nodes->addAndTransfer(ownedSet);
53
0
        NS_ENSURE_SUCCESS(rv, rv);
54
0
    }
55
0
56
0
    *aResult = nodes;
57
0
    NS_ADDREF(*aResult);
58
0
59
0
    return NS_OK;
60
0
} //-- evaluate
61
62
Expr::ExprType
63
UnionExpr::getType()
64
0
{
65
0
  return UNION_EXPR;
66
0
}
67
68
TX_IMPL_EXPR_STUBS_LIST(UnionExpr, NODESET_RESULT, mExpressions)
69
70
bool
71
UnionExpr::isSensitiveTo(ContextSensitivity aContext)
72
0
{
73
0
    uint32_t i, len = mExpressions.Length();
74
0
    for (i = 0; i < len; ++i) {
75
0
        if (mExpressions[i]->isSensitiveTo(aContext)) {
76
0
            return true;
77
0
        }
78
0
    }
79
0
80
0
    return false;
81
0
}
82
83
#ifdef TX_TO_STRING
84
void
85
UnionExpr::toString(nsAString& dest)
86
{
87
    uint32_t i;
88
    for (i = 0; i < mExpressions.Length(); ++i) {
89
        if (i > 0)
90
            dest.AppendLiteral(" | ");
91
        mExpressions[i]->toString(dest);
92
    }
93
}
94
#endif