1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
10 #include "txIXPathContext.h"
12 //-------------------/
13 //- VariableRefExpr -/
14 //-------------------/
17 * Creates a VariableRefExpr with the given variable name
19 VariableRefExpr::VariableRefExpr(nsAtom
* aPrefix
, nsAtom
* aLocalName
,
21 : mPrefix(aPrefix
), mLocalName(aLocalName
), mNamespace(aNSID
) {
22 NS_ASSERTION(mLocalName
, "VariableRefExpr without local name?");
23 if (mPrefix
== nsGkAtoms::_empty
) mPrefix
= nullptr;
27 * Evaluates this Expr based on the given context node and processor state
28 * @param context the context node for evaluation of this Expr
29 * @param ps the ContextState containing the stack information needed
31 * @return the result of the evaluation
33 nsresult
VariableRefExpr::evaluate(txIEvalContext
* aContext
,
34 txAExprResult
** aResult
) {
35 nsresult rv
= aContext
->getVariable(mNamespace
, mLocalName
, *aResult
);
37 // XXX report error, undefined variable
43 TX_IMPL_EXPR_STUBS_0(VariableRefExpr
, ANY_RESULT
)
45 bool VariableRefExpr::isSensitiveTo(ContextSensitivity aContext
) {
46 return !!(aContext
& VARIABLES_CONTEXT
);
50 void VariableRefExpr::toString(nsAString
& aDest
) {
51 aDest
.Append(char16_t('$'));
54 mPrefix
->ToString(prefix
);
56 aDest
.Append(char16_t(':'));
59 mLocalName
->ToString(lname
);