dom/xslt/xpath/txVariableRefExpr.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #include "txExpr.h"
     7 #include "nsIAtom.h"
     8 #include "txNodeSet.h"
     9 #include "nsGkAtoms.h"
    10 #include "txIXPathContext.h"
    12   //-------------------/
    13  //- VariableRefExpr -/
    14 //-------------------/
    16 /**
    17  * Creates a VariableRefExpr with the given variable name
    18 **/
    19 VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName,
    20                                  int32_t aNSID)
    21     : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID)
    22 {
    23     NS_ASSERTION(mLocalName, "VariableRefExpr without local name?");
    24     if (mPrefix == nsGkAtoms::_empty)
    25         mPrefix = 0;
    26 }
    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 {
    38     nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult);
    39     if (NS_FAILED(rv)) {
    40       // XXX report error, undefined variable
    41       return rv;
    42     }
    43     return NS_OK;
    44 }
    46 TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT)
    48 bool
    49 VariableRefExpr::isSensitiveTo(ContextSensitivity aContext)
    50 {
    51     return !!(aContext & VARIABLES_CONTEXT);
    52 }
    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

mercurial