Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/xslt/xpath/txLiteralExpr.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
8
nsresult
9
txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
10
0
{
11
0
    NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY);
12
0
13
0
    *aResult = mValue;
14
0
    NS_ADDREF(*aResult);
15
0
16
0
    return NS_OK;
17
0
}
18
19
static Expr::ResultType resultTypes[] =
20
{
21
    Expr::NODESET_RESULT, // NODESET
22
    Expr::BOOLEAN_RESULT, // BOOLEAN
23
    Expr::NUMBER_RESULT,  // NUMBER
24
    Expr::STRING_RESULT,  // STRING
25
    Expr::RTF_RESULT      // RESULT_TREE_FRAGMENT
26
};
27
28
Expr::ResultType
29
txLiteralExpr::getReturnType()
30
0
{
31
0
    return resultTypes[mValue->getResultType()];
32
0
}
33
34
Expr*
35
txLiteralExpr::getSubExprAt(uint32_t aPos)
36
0
{
37
0
    return nullptr;
38
0
}
39
void
40
txLiteralExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
41
0
{
42
0
    MOZ_ASSERT_UNREACHABLE("setting bad subexpression index");
43
0
}
44
45
bool
46
txLiteralExpr::isSensitiveTo(ContextSensitivity aContext)
47
0
{
48
0
    return false;
49
0
}
50
51
#ifdef TX_TO_STRING
52
void
53
txLiteralExpr::toString(nsAString& aStr)
54
{
55
    switch (mValue->getResultType()) {
56
        case txAExprResult::NODESET:
57
        {
58
            aStr.AppendLiteral(" { Nodeset literal } ");
59
            return;
60
        }
61
        case txAExprResult::BOOLEAN:
62
        {
63
            if (mValue->booleanValue()) {
64
              aStr.AppendLiteral("true()");
65
            }
66
            else {
67
              aStr.AppendLiteral("false()");
68
            }
69
            return;
70
        }
71
        case txAExprResult::NUMBER:
72
        {
73
            txDouble::toString(mValue->numberValue(), aStr);
74
            return;
75
        }
76
        case txAExprResult::STRING:
77
        {
78
            StringResult* strRes =
79
                static_cast<StringResult*>(static_cast<txAExprResult*>
80
                                       (mValue));
81
            char16_t ch = '\'';
82
            if (strRes->mValue.Contains(ch)) {
83
                ch = '\"';
84
            }
85
            aStr.Append(ch);
86
            aStr.Append(strRes->mValue);
87
            aStr.Append(ch);
88
            return;
89
        }
90
        case txAExprResult::RESULT_TREE_FRAGMENT:
91
        {
92
            aStr.AppendLiteral(" { RTF literal } ");
93
            return;
94
        }
95
    }
96
}
97
#endif