dom/xslt/xpath/txVariableRefExpr.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txVariableRefExpr.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "txExpr.h"
    1.10 +#include "nsIAtom.h"
    1.11 +#include "txNodeSet.h"
    1.12 +#include "nsGkAtoms.h"
    1.13 +#include "txIXPathContext.h"
    1.14 +
    1.15 +  //-------------------/
    1.16 + //- VariableRefExpr -/
    1.17 +//-------------------/
    1.18 +
    1.19 +/**
    1.20 + * Creates a VariableRefExpr with the given variable name
    1.21 +**/
    1.22 +VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName,
    1.23 +                                 int32_t aNSID)
    1.24 +    : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID)
    1.25 +{
    1.26 +    NS_ASSERTION(mLocalName, "VariableRefExpr without local name?");
    1.27 +    if (mPrefix == nsGkAtoms::_empty)
    1.28 +        mPrefix = 0;
    1.29 +}
    1.30 +
    1.31 +/**
    1.32 + * Evaluates this Expr based on the given context node and processor state
    1.33 + * @param context the context node for evaluation of this Expr
    1.34 + * @param ps the ContextState containing the stack information needed
    1.35 + * for evaluation
    1.36 + * @return the result of the evaluation
    1.37 +**/
    1.38 +nsresult
    1.39 +VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
    1.40 +{
    1.41 +    nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult);
    1.42 +    if (NS_FAILED(rv)) {
    1.43 +      // XXX report error, undefined variable
    1.44 +      return rv;
    1.45 +    }
    1.46 +    return NS_OK;
    1.47 +}
    1.48 +
    1.49 +TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT)
    1.50 +
    1.51 +bool
    1.52 +VariableRefExpr::isSensitiveTo(ContextSensitivity aContext)
    1.53 +{
    1.54 +    return !!(aContext & VARIABLES_CONTEXT);
    1.55 +}
    1.56 +
    1.57 +#ifdef TX_TO_STRING
    1.58 +void
    1.59 +VariableRefExpr::toString(nsAString& aDest)
    1.60 +{
    1.61 +    aDest.Append(char16_t('$'));
    1.62 +    if (mPrefix) {
    1.63 +        nsAutoString prefix;
    1.64 +        mPrefix->ToString(prefix);
    1.65 +        aDest.Append(prefix);
    1.66 +        aDest.Append(char16_t(':'));
    1.67 +    }
    1.68 +    nsAutoString lname;
    1.69 +    mLocalName->ToString(lname);
    1.70 +    aDest.Append(lname);
    1.71 +}
    1.72 +#endif

mercurial