Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/xslt/xpath/txVariableRefExpr.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 "txNodeSet.h"
9
#include "nsGkAtoms.h"
10
#include "txIXPathContext.h"
11
12
  //-------------------/
13
 //- VariableRefExpr -/
14
//-------------------/
15
16
/**
17
 * Creates a VariableRefExpr with the given variable name
18
**/
19
VariableRefExpr::VariableRefExpr(nsAtom* aPrefix, nsAtom* aLocalName,
20
                                 int32_t aNSID)
21
    : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID)
22
0
{
23
0
    NS_ASSERTION(mLocalName, "VariableRefExpr without local name?");
24
0
    if (mPrefix == nsGkAtoms::_empty)
25
0
        mPrefix = nullptr;
26
0
}
27
28
/**
29
 * Evaluates this Expr based on the given context node and processor state
30
 * @param context the context node for evaluation of this Expr
31
 * @param ps the ContextState containing the stack information needed
32
 * for evaluation
33
 * @return the result of the evaluation
34
**/
35
nsresult
36
VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
37
0
{
38
0
    nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult);
39
0
    if (NS_FAILED(rv)) {
40
0
      // XXX report error, undefined variable
41
0
      return rv;
42
0
    }
43
0
    return NS_OK;
44
0
}
45
46
TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT)
47
48
bool
49
VariableRefExpr::isSensitiveTo(ContextSensitivity aContext)
50
0
{
51
0
    return !!(aContext & VARIABLES_CONTEXT);
52
0
}
53
54
#ifdef TX_TO_STRING
55
void
56
VariableRefExpr::toString(nsAString& aDest)
57
{
58
    aDest.Append(char16_t('$'));
59
    if (mPrefix) {
60
        nsAutoString prefix;
61
        mPrefix->ToString(prefix);
62
        aDest.Append(prefix);
63
        aDest.Append(char16_t(':'));
64
    }
65
    nsAutoString lname;
66
    mLocalName->ToString(lname);
67
    aDest.Append(lname);
68
}
69
#endif