File indexing completed on 2024-04-28 15:24:58

0001 /*
0002  * variablereference.cc - Copyright 2005 Frerich Raabe <raabe@kde.org>
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  *
0014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024  */
0025 #include "variablereference.h"
0026 #include <dom_stringimpl.h>
0027 using namespace khtml;
0028 using namespace khtml::XPath;
0029 
0030 VariableReference::VariableReference(const DOM::DOMString &name)
0031     : m_name(name)
0032 {
0033 }
0034 
0035 bool VariableReference::isConstant() const
0036 {
0037     return false;
0038 }
0039 
0040 QString VariableReference::dump() const
0041 {
0042     return QString() + "<variablereference name=\"" + m_name.string() + "\"/>";
0043 }
0044 
0045 Value VariableReference::doEvaluate() const
0046 {
0047     QHash<DOM::DOMString, DOM::DOMString> &bindings = evaluationContext().variableBindings;
0048     if (!bindings.contains(m_name)) {
0049         // XXX What to do if an unknown variable is referenced?
0050         return Value(DOMString());
0051     }
0052     return Value(bindings[ m_name ]);
0053 }
0054