Commit a9406af1 authored by darin's avatar darin

Reviewed by Anders.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8995
          memory leak in XPath code -- seen in layout tests
        - fixed malloc error on exit due to SVGDOMImplementation destructor
        - attempted to fix the no-XPATH_SUPPORT build by adding an #if
        - changed around includes and header-file formatting in XPath code

        * bindings/scripts/CodeGeneratorJS.pm: Include PlatformString.h when
        generating the bindings for XPathNSResolver.

        * dom/DOMImplementation.h: Added a virtual destructor for the benefit of
        SVGDOMImplementation.
        * dom/DOMImplementation.cpp: (WebCore::DOMImplementation::~DOMImplementation): Added.

        * ksvg2/svg/SVGDOMImplementation.h: Reformatted a bit, removed unneeded declarations.
        * ksvg2/svg/SVGDOMImplementation.cpp:
        (SVGDOMImplementation::~SVGDOMImplementation): Remove commented-out code.
        (SVGDOMImplementation::createDocument): Remove a reference to KDOMView.

        * xpath/XPathExpression.cpp:
        (WebCore::XPathExpression::createExpression): Called release to avoid a tiny bit of
        reference count churn.
        (WebCore::XPathExpression::evaluate): Set exception code explicitly, because the code
        relies on it being 0 when the function succeeds.

        * xpath/XPathResult.cpp:
        (WebCore::InvalidatingEventListener::InvalidatingEventListener): Removed
        unneeded target node data member.
        (WebCore::XPathResult::XPathResult): Updated for enum name changes and
        InvalidatingEventListener name change. Added an assertion.

        * xpath/impl/XPathFunctions.h: Removed the FunctionLibrary class. Changed the parameter
        for createFunction to be a String instead of char*.
        * xpath/impl/XPathFunctions.cpp: Got rid of local implementation of "round", and
        used <wtf/MathExtras.h> instead. Also removed unused Interval::asString. Marked all
        the Interval functions inline.
        (WebCore::XPath::FunSubstring::doEvaluate): Use lround() instead of (long)round().
        (WebCore::XPath::FunLang::doEvaluate): Removed some unneeded temporary String variables.
        Use equalIgnoringCase() instead of calling lower() on two strings.
        (WebCore::XPath::createFunctionMap): Changed how this works so that it's all local to
        this function. Also removed a duplicate entry for the "last" function.
        (WebCore::XPath::createFunction): Changed from a member function to a separate function.
        Also changed so that if the args are not used in the function they are deleted.
        This was one of the sources of the storage leaks.

        * xpath/impl/XPathGrammar.y: Put XPATH_SUPPORT ifdef in. Replaced <num> with values of
        specific types (numop, eqop). Updated for name change from AxisType to Axis. Changed
        tokens that were declared as <str> but weren't actually using the string to be
        declared with no type (PLUS, MINUS, OR, AND, DOTDOT, SLASHSLASH). Replaced use of
        unregisterString, unregisterPredicateVector, and unregisterExpressionVector to
        call delete functions instead that both unregister and delete. Change call sites for
        createFunction to just use the String, removing the deprecatedString().latin1() call
        that is no longer needed. Added a call to unregisterParseNode that was missing in the
        "FilterExpr DescendantOrSelf RelativeLocationPath" production.

        * xpath/impl/XPathParser.h: Changed Token to hold a String, Step::Axis, NumericOp::Opcode,
        and EqTestOp::Opcode. The token ID number tells us which to use. Rearranged to put the private
        part of the Parser class last. Moved a number of private things inside the cpp file.
        * xpath/impl/XPathParser.cpp:
        (WebCore::XPath::charCat): Made this a separate function, instead of a static member.
        (WebCore::XPath::isAxisName): Ditto. Also put the global axis map inside the function,
        allowing use of a map instead of a map pointer.
        (WebCore::XPath::isNodeTypeName): Ditto.
        (WebCore::XPath::Parser::isOperatorContext): Made this const.
        (WebCore::XPath::Parser::makeTokenAndAdvance): Got rid of the "int" version of this.
        By using the actual types, we can safely use overload instead.
        (WebCore::XPath::Parser::lexString): Use substring() instead of deprecatedString().mid().
        (WebCore::XPath::Parser::lexNumber): Ditto.
        (WebCore::XPath::Parser::lexNCName): Changed to return a bool and a String instead of a
        Token. This avoids the hack of using a token value of "ERROR + 1" which I found quite
        confusing and is also a bit more explicit.
        (WebCore::XPath::Parser::lexQName): Ditto.
        (WebCore::XPath::Parser::nextTokenInternal): Changed to adapt to the changes above and
        to remove some unneeded else statements.
        (WebCore::XPath::Parser::lex): Changed the logic that sets up yylval to use the token ID
        to decide what the type is. This matches what the grammar expects, and removes the need
        for the token object to track which part of the value is good and the need to reserve 0
        to have a special meaning.
        (WebCore::XPath::Parser::parseStatement): Added code to delete the predicates and the
        expressions in the predicate and expression vectors. Before, we were only deleting
        the vectors. This was one of the sources of the storage leaks.
        (WebCore::XPath::Parser::deletePredicateVector): Renamed, and changed to delete
        the vector. However this does not delete the predicates in the vector.
        (WebCore::XPath::Parser::deleteExpressionVector): Renamed, and changed to delete
        the vector. However this does not delete the expressions in the vector.
        (WebCore::XPath::Parser::deleteString): Renamed, and changed to delete the string.

        * xpath/impl/XPathPredicate.h:
        * xpath/impl/XPathPredicate.cpp:
        (WebCore::XPath::NumericOp::NumericOp): Changed opcode from an int to an enum, and
        renamed to "opcode" instead of "opCode".
        (WebCore::XPath::NumericOp::doEvaluate): More of the same.
        (WebCore::XPath::EqTestOp::EqTestOp): Ditto.
        (WebCore::XPath::EqTestOp::doEvaluate): Ditto.
        (WebCore::XPath::LogicalOp::LogicalOp): Ditto.
        (WebCore::XPath::LogicalOp::shortCircuitOn): Ditto.
        (WebCore::XPath::Predicate::evaluate): Removed an unneeded "new".

        * xpath/impl/XPathStep.h:
        * xpath/impl/XPathStep.cpp: Renamed AxisType to Axis. Removed unused axisAsString
        function and default constructor.

        * xpath/impl/XPathValue.h: Renamed the type constants to have a Value suffix,
        instead of the underscore suffix used before on NodeVector and String.
        * xpath/impl/XPathValue.cpp: Updated for name change. Added asserts.

        * xpath/impl/XPathVariableReference.cpp: (WebCore::XPath::VariableReference::doEvaluate):
        Use a reference instead of a pointer.

        * xpath/XPathEvaluator.cpp:
        * xpath/XPathEvaluator.h:
        * xpath/XPathExpression.h:
        * xpath/XPathNSResolver.cpp:
        * xpath/XPathNSResolver.h:
        * xpath/XPathNamespace.cpp:
        * xpath/XPathNamespace.h:
        * xpath/XPathResult.h:
        * xpath/impl/XPathExpressionNode.cpp:
        * xpath/impl/XPathExpressionNode.h:
        * xpath/impl/XPathPath.cpp:
        * xpath/impl/XPathPath.h:
        * xpath/impl/XPathUtil.cpp:
        * xpath/impl/XPathUtil.h:
        * xpath/impl/XPathVariableReference.h:
        Reformatted and changed includes around; no substantive changes.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@14729 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 57617054
2006-06-04 Darin Adler <darin@apple.com>
Reviewed by Anders.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8995
memory leak in XPath code -- seen in layout tests
- fixed malloc error on exit due to SVGDOMImplementation destructor
- attempted to fix the no-XPATH_SUPPORT build by adding an #if
- changed around includes and header-file formatting in XPath code
* bindings/scripts/CodeGeneratorJS.pm: Include PlatformString.h when
generating the bindings for XPathNSResolver.
* dom/DOMImplementation.h: Added a virtual destructor for the benefit of
SVGDOMImplementation.
* dom/DOMImplementation.cpp: (WebCore::DOMImplementation::~DOMImplementation): Added.
* ksvg2/svg/SVGDOMImplementation.h: Reformatted a bit, removed unneeded declarations.
* ksvg2/svg/SVGDOMImplementation.cpp:
(SVGDOMImplementation::~SVGDOMImplementation): Remove commented-out code.
(SVGDOMImplementation::createDocument): Remove a reference to KDOMView.
* xpath/XPathExpression.cpp:
(WebCore::XPathExpression::createExpression): Called release to avoid a tiny bit of
reference count churn.
(WebCore::XPathExpression::evaluate): Set exception code explicitly, because the code
relies on it being 0 when the function succeeds.
* xpath/XPathResult.cpp:
(WebCore::InvalidatingEventListener::InvalidatingEventListener): Removed
unneeded target node data member.
(WebCore::XPathResult::XPathResult): Updated for enum name changes and
InvalidatingEventListener name change. Added an assertion.
* xpath/impl/XPathFunctions.h: Removed the FunctionLibrary class. Changed the parameter
for createFunction to be a String instead of char*.
* xpath/impl/XPathFunctions.cpp: Got rid of local implementation of "round", and
used <wtf/MathExtras.h> instead. Also removed unused Interval::asString. Marked all
the Interval functions inline.
(WebCore::XPath::FunSubstring::doEvaluate): Use lround() instead of (long)round().
(WebCore::XPath::FunLang::doEvaluate): Removed some unneeded temporary String variables.
Use equalIgnoringCase() instead of calling lower() on two strings.
(WebCore::XPath::createFunctionMap): Changed how this works so that it's all local to
this function. Also removed a duplicate entry for the "last" function.
(WebCore::XPath::createFunction): Changed from a member function to a separate function.
Also changed so that if the args are not used in the function they are deleted.
This was one of the sources of the storage leaks.
* xpath/impl/XPathGrammar.y: Put XPATH_SUPPORT ifdef in. Replaced <num> with values of
specific types (numop, eqop). Updated for name change from AxisType to Axis. Changed
tokens that were declared as <str> but weren't actually using the string to be
declared with no type (PLUS, MINUS, OR, AND, DOTDOT, SLASHSLASH). Replaced use of
unregisterString, unregisterPredicateVector, and unregisterExpressionVector to
call delete functions instead that both unregister and delete. Change call sites for
createFunction to just use the String, removing the deprecatedString().latin1() call
that is no longer needed. Added a call to unregisterParseNode that was missing in the
"FilterExpr DescendantOrSelf RelativeLocationPath" production.
* xpath/impl/XPathParser.h: Changed Token to hold a String, Step::Axis, NumericOp::Opcode,
and EqTestOp::Opcode. The token ID number tells us which to use. Rearranged to put the private
part of the Parser class last. Moved a number of private things inside the cpp file.
* xpath/impl/XPathParser.cpp:
(WebCore::XPath::charCat): Made this a separate function, instead of a static member.
(WebCore::XPath::isAxisName): Ditto. Also put the global axis map inside the function,
allowing use of a map instead of a map pointer.
(WebCore::XPath::isNodeTypeName): Ditto.
(WebCore::XPath::Parser::isOperatorContext): Made this const.
(WebCore::XPath::Parser::makeTokenAndAdvance): Got rid of the "int" version of this.
By using the actual types, we can safely use overload instead.
(WebCore::XPath::Parser::lexString): Use substring() instead of deprecatedString().mid().
(WebCore::XPath::Parser::lexNumber): Ditto.
(WebCore::XPath::Parser::lexNCName): Changed to return a bool and a String instead of a
Token. This avoids the hack of using a token value of "ERROR + 1" which I found quite
confusing and is also a bit more explicit.
(WebCore::XPath::Parser::lexQName): Ditto.
(WebCore::XPath::Parser::nextTokenInternal): Changed to adapt to the changes above and
to remove some unneeded else statements.
(WebCore::XPath::Parser::lex): Changed the logic that sets up yylval to use the token ID
to decide what the type is. This matches what the grammar expects, and removes the need
for the token object to track which part of the value is good and the need to reserve 0
to have a special meaning.
(WebCore::XPath::Parser::parseStatement): Added code to delete the predicates and the
expressions in the predicate and expression vectors. Before, we were only deleting
the vectors. This was one of the sources of the storage leaks.
(WebCore::XPath::Parser::deletePredicateVector): Renamed, and changed to delete
the vector. However this does not delete the predicates in the vector.
(WebCore::XPath::Parser::deleteExpressionVector): Renamed, and changed to delete
the vector. However this does not delete the expressions in the vector.
(WebCore::XPath::Parser::deleteString): Renamed, and changed to delete the string.
* xpath/impl/XPathPredicate.h:
* xpath/impl/XPathPredicate.cpp:
(WebCore::XPath::NumericOp::NumericOp): Changed opcode from an int to an enum, and
renamed to "opcode" instead of "opCode".
(WebCore::XPath::NumericOp::doEvaluate): More of the same.
(WebCore::XPath::EqTestOp::EqTestOp): Ditto.
(WebCore::XPath::EqTestOp::doEvaluate): Ditto.
(WebCore::XPath::LogicalOp::LogicalOp): Ditto.
(WebCore::XPath::LogicalOp::shortCircuitOn): Ditto.
(WebCore::XPath::Predicate::evaluate): Removed an unneeded "new".
* xpath/impl/XPathStep.h:
* xpath/impl/XPathStep.cpp: Renamed AxisType to Axis. Removed unused axisAsString
function and default constructor.
* xpath/impl/XPathValue.h: Renamed the type constants to have a Value suffix,
instead of the underscore suffix used before on NodeVector and String.
* xpath/impl/XPathValue.cpp: Updated for name change. Added asserts.
* xpath/impl/XPathVariableReference.cpp: (WebCore::XPath::VariableReference::doEvaluate):
Use a reference instead of a pointer.
* xpath/XPathEvaluator.cpp:
* xpath/XPathEvaluator.h:
* xpath/XPathExpression.h:
* xpath/XPathNSResolver.cpp:
* xpath/XPathNSResolver.h:
* xpath/XPathNamespace.cpp:
* xpath/XPathNamespace.h:
* xpath/XPathResult.h:
* xpath/impl/XPathExpressionNode.cpp:
* xpath/impl/XPathExpressionNode.h:
* xpath/impl/XPathPath.cpp:
* xpath/impl/XPathPath.h:
* xpath/impl/XPathUtil.cpp:
* xpath/impl/XPathUtil.h:
* xpath/impl/XPathVariableReference.h:
Reformatted and changed includes around; no substantive changes.
2006-06-04 Sam Weinig <sam.weinig@gmail.com>
Reviewed by hyatt.
......
......@@ -148,8 +148,7 @@ sub AddIncludesForType
my $type = $codeGenerator->StripModule(shift);
# When we're finished with the one-file-per-class
# reorganization, we don't need these special cases.
# reorganization, we won't need these special cases.
if ($type eq "MutationEvent" or
$type eq "KeyboardEvent" or
$type eq "MouseEvent" or
......@@ -157,19 +156,23 @@ sub AddIncludesForType
$type eq "UIEvent" or
$type eq "WheelEvent") {
$implIncludes{"dom2_eventsimpl.h"} = 1;
} elsif ($type eq "CanvasRenderingContext2D") {
} elsif ($codeGenerator->IsPrimitiveType($type)
or $type eq "DOMString" or $type eq "DOMObject" or $type eq "RGBColor" or $type eq "Rect") {
} else {
# default, include the same named file
$implIncludes{"${type}.h"} = 1;
}
# additional includes (things needed to compile the bindings but not the header)
if ($type eq "CanvasRenderingContext2D") {
$implIncludes{"CanvasGradient.h"} = 1;
$implIncludes{"CanvasPattern.h"} = 1;
$implIncludes{"CanvasRenderingContext2D.h"} = 1;
$implIncludes{"CanvasStyle.h"} = 1;
} elsif ($type eq "CanvasGradient") {
$implIncludes{"CanvasGradient.h"} = 1;
}
if ($type eq "CanvasGradient" or $type eq "XPathNSResolver") {
$implIncludes{"PlatformString.h"} = 1;
} elsif ($codeGenerator->IsPrimitiveType($type) or
$type eq "DOMString" or $type eq "DOMObject" or $type eq "RGBColor" or $type eq "Rect") {
} else {
# default, include the same named file
$implIncludes{"${type}.h"} = 1;
}
}
......
......@@ -46,6 +46,10 @@ static bool qualifiedNameIsMalformed(const String&)
return false;
}
DOMImplementation::~DOMImplementation()
{
}
bool DOMImplementation::hasFeature (const String& feature, const String& version) const
{
String lower = feature.lower();
......
......@@ -43,6 +43,8 @@ typedef int ExceptionCode;
class DOMImplementation : public Shared<DOMImplementation> {
public:
virtual ~DOMImplementation();
// DOM methods & attributes for DOMImplementation
bool hasFeature(const String& feature, const String& version) const;
PassRefPtr<DocumentType> createDocumentType(const String& qualifiedName, const String& publicId, const String &systemId, ExceptionCode&);
......
......@@ -39,8 +39,6 @@ public:
virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const;
virtual void parseMappedAttribute(MappedAttribute*);
virtual int start() const { return 1; }
bool compact() const;
void setCompact(bool);
......
......@@ -99,8 +99,6 @@ SVGDOMImplementation::SVGDOMImplementation() : DOMImplementation()
SVGDOMImplementation::~SVGDOMImplementation()
{
// clean up static data
//SVGRenderStyle::cleanup();
}
SVGDOMImplementation *SVGDOMImplementation::instance()
......@@ -155,7 +153,7 @@ PassRefPtr<Document> SVGDOMImplementation::createDocument(StringImpl *namespaceU
return createDocument(namespaceURI, qualifiedNameImpl, doctype, true, 0, ec);
}
PassRefPtr<Document> SVGDOMImplementation::createDocument(StringImpl *namespaceURIImpl, StringImpl *qualifiedNameImpl, DocumentType *doctype, bool createDocElement, KDOMView *view, ExceptionCode& ec) const
PassRefPtr<Document> SVGDOMImplementation::createDocument(StringImpl *namespaceURIImpl, StringImpl *qualifiedNameImpl, DocumentType *doctype, bool createDocElement, FrameView *view, ExceptionCode& ec) const
{
String namespaceURI(namespaceURIImpl);
String qualifiedName(qualifiedNameImpl);
......
......@@ -25,34 +25,27 @@
#if SVG_SUPPORT
#include "DOMImplementation.h"
#include "DeprecatedStringList.h"
namespace WebCore {
class CSSStyleSheet;
class Document;
class DocumentType;
class String;
class StringImpl;
typedef FrameView KDOMView;
class StringImpl;
class SVGDOMImplementation : public DOMImplementation
{
class SVGDOMImplementation : public DOMImplementation {
public:
SVGDOMImplementation();
virtual ~SVGDOMImplementation();
static SVGDOMImplementation *instance();
static SVGDOMImplementation* instance();
// 'SVGDOMImplementation' functions
bool hasFeature(StringImpl *feature, StringImpl *version) const;
PassRefPtr<DocumentType> createDocumentType(StringImpl *qualifiedName, StringImpl *publicId, StringImpl *systemId, ExceptionCode&) const;
PassRefPtr<Document> createDocument(StringImpl *namespaceURI, StringImpl *qualifiedName, DocumentType *doctype, ExceptionCode&) const;
PassRefPtr<Document> createDocument(StringImpl *namespaceURI, StringImpl *qualifiedName, DocumentType *doctype, bool createDocElement, FrameView*, ExceptionCode&) const;
bool hasFeature(StringImpl* feature, StringImpl* version) const;
PassRefPtr<DocumentType> createDocumentType(StringImpl* qualifiedName, StringImpl* publicId, StringImpl* systemId, ExceptionCode&) const;
PassRefPtr<Document> createDocument(StringImpl* namespaceURI, StringImpl* qualifiedName, DocumentType*, ExceptionCode&) const;
PassRefPtr<Document> createDocument(StringImpl* namespaceURI, StringImpl* qualifiedName, DocumentType*, bool createDocElement, FrameView*, ExceptionCode&) const;
virtual PassRefPtr<CSSStyleSheet> createCSSStyleSheet(StringImpl *title, StringImpl *media) const;
virtual PassRefPtr<CSSStyleSheet> createCSSStyleSheet(StringImpl* title, StringImpl* media) const;
virtual DocumentType *defaultDocumentType() const;
virtual DocumentType* defaultDocumentType() const;
bool inAnimationContext() const;
void setAnimationContext(bool value);
......@@ -63,6 +56,7 @@ namespace WebCore {
private:
bool m_animationContext : 1;
};
}
#endif // SVG_SUPPORT
......
......@@ -23,17 +23,17 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "XPathEvaluator.h"
#if XPATH_SUPPORT
#include "XPathEvaluator.h"
#include "ExceptionCode.h"
#include "Node.h"
#include "XPathExpression.h"
#include "XPathNSResolver.h"
#include "XPathResult.h"
#include "ExceptionCode.h"
#include "XPathUtil.h"
namespace WebCore {
......
......@@ -23,47 +23,40 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef XPathEvaluator_H
#define XPathEvaluator_H
#if XPATH_SUPPORT
#include "Shared.h"
#include <wtf/Forward.h>
#include "PlatformString.h"
#include "ExceptionCode.h"
namespace WebCore
{
class Node;
namespace WebCore {
class XPathExpression;
class XPathNSResolver;
class XPathResult;
typedef int ExceptionCode;
const int XPathExceptionOffset = 400;
const int XPathExceptionMax = 499;
class Node;
class String;
class XPathExpression;
class XPathNSResolver;
class XPathResult;
enum XPathExceptionCode { INVALID_EXPRESSION_ERR = XPathExceptionOffset + 51, TYPE_ERR };
// FIXME: Should these exception codes move to another header?
const int XPathExceptionOffset = 400;
const int XPathExceptionMax = 499;
enum XPathExceptionCode { INVALID_EXPRESSION_ERR = XPathExceptionOffset + 51, TYPE_ERR };
class XPathEvaluator : public Shared<XPathEvaluator>
{
public:
PassRefPtr<XPathExpression> createExpression(const String& expression,
XPathNSResolver*,
ExceptionCode&);
PassRefPtr<XPathNSResolver> createNSResolver(Node* nodeResolver);
PassRefPtr<XPathResult> evaluate(const String& expression,
Node* contextNode,
XPathNSResolver*,
unsigned short type,
XPathResult*,
ExceptionCode&);
};
class XPathEvaluator : public Shared<XPathEvaluator> {
public:
PassRefPtr<XPathExpression> createExpression(const String& expression, XPathNSResolver*, ExceptionCode&);
PassRefPtr<XPathNSResolver> createNSResolver(Node* nodeResolver);
PassRefPtr<XPathResult> evaluate(const String& expression, Node* contextNode,
XPathNSResolver*, unsigned short type, XPathResult*, ExceptionCode&);
};
}
#endif // XPATH_SUPPORT
#endif // XPathEvaluator_H
......@@ -23,11 +23,12 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "XPathExpression.h"
#if XPATH_SUPPORT
#include "XPathExpression.h"
#include "PlatformString.h"
#include "Document.h"
#include "Node.h"
......@@ -46,12 +47,12 @@ PassRefPtr<XPathExpression> XPathExpression::createExpression(const String& expr
{
RefPtr<XPathExpression> expr = new XPathExpression;
Parser parser;
expr->m_topExpression = parser.parseStatement(expression, resolver, ec);
if (!expr->m_topExpression)
return 0;
return expr;
return expr.release();
}
XPathExpression::~XPathExpression()
......@@ -59,28 +60,24 @@ XPathExpression::~XPathExpression()
delete m_topExpression;
}
PassRefPtr<XPathResult> XPathExpression::evaluate(Node* contextNode,
unsigned short type,
XPathResult*,
ExceptionCode& ec)
PassRefPtr<XPathResult> XPathExpression::evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode& ec)
{
if (!isValidContextNode(contextNode)) {
ec = NOT_SUPPORTED_ERR;
return 0;
}
Node* eventTarget = contextNode->ownerDocument() ?
contextNode->ownerDocument() : contextNode;
EventTargetNode* eventTarget = contextNode->ownerDocument()
? contextNode->ownerDocument()
: static_cast<EventTargetNode*>(contextNode);
Expression::evaluationContext().node = contextNode;
m_topExpression->optimize();
RefPtr<XPathResult> result = new XPathResult(static_cast<EventTargetNode*>(eventTarget),
m_topExpression->evaluate());
RefPtr<XPathResult> result = new XPathResult(eventTarget, m_topExpression->evaluate());
if (type != XPathResult::ANY_TYPE) {
ec = 0;
result->convertTo(type, ec);
if (ec)
return 0;
}
......
......@@ -23,46 +23,40 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef XPathExpression_H
#define XPathExpression_H
#if XPATH_SUPPORT
#include "Shared.h"
#include "PlatformString.h"
#include "ExceptionCode.h"
#include <wtf/Forward.h>
#include "XPathExpressionNode.h"
namespace WebCore {
namespace WebCore
{
class Node;
typedef int ExceptionCode;
class XPathNSResolver;
class XPathResult;
class Node;
class String;
class XPathNSResolver;
class XPathResult;
class XPathExpression : public Shared<XPathExpression>
{
public:
~XPathExpression();
namespace XPath {
class Expression;
}
static PassRefPtr<XPathExpression> createExpression(const String& expression,
XPathNSResolver*,
ExceptionCode&);
PassRefPtr<XPathResult> evaluate(Node* contextNode,
unsigned short type,
XPathResult*,
ExceptionCode&);
private:
XPath::Expression* m_topExpression;
};
class XPathExpression : public Shared<XPathExpression> {
public:
~XPathExpression();
static PassRefPtr<XPathExpression> createExpression(const String& expression, XPathNSResolver*, ExceptionCode&);
PassRefPtr<XPathResult> evaluate(Node* contextNode, unsigned short type, XPathResult*, ExceptionCode&);
private:
XPath::Expression* m_topExpression;
};
}
#endif // XPATH_SUPPORT
#endif // XPathExpression_H
......@@ -23,11 +23,12 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "XPathNSResolver.h"
#if XPATH_SUPPORT
#include "XPathNSResolver.h"
#include "Node.h"
namespace WebCore {
......@@ -37,6 +38,10 @@ XPathNSResolver::XPathNSResolver(PassRefPtr<Node> node)
{
}
XPathNSResolver::~XPathNSResolver()
{
}
String XPathNSResolver::lookupNamespaceURI(const String& prefix)
{
// This is not done by Node::lookupNamespaceURI as per the DOM3 Core spec,
......
......@@ -23,30 +23,31 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef XPathNSResolver_H
#define XPathNSResolver_H
#if XPATH_SUPPORT
#include "Shared.h"
#include "PlatformString.h"
#include "Node.h"
#include <wtf/Forward.h>
#include <wtf/RefPtr.h>
namespace WebCore
{
namespace WebCore {
class Node;
class Node;
class String;
class XPathNSResolver : public Shared<XPathNSResolver>
{
class XPathNSResolver : public Shared<XPathNSResolver> {
public:
XPathNSResolver(PassRefPtr<Node>);
~XPathNSResolver();
String lookupNamespaceURI(const String& prefix);
private:
RefPtr<Node> m_node;
};
};
}
......
......@@ -23,20 +23,21 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "XPathNamespace.h"
#if XPATH_SUPPORT
#include "XPathNamespace.h"
#include "Document.h"
#include "Element.h"
namespace WebCore {
XPathNamespace::XPathNamespace(PassRefPtr<Element> ownerElement, const String& prefix, const String& uri)
: Node(ownerElement->document()),
m_ownerElement(ownerElement),
m_prefix(prefix),
m_uri(uri)
: Node(ownerElement->document())
, m_ownerElement(ownerElement)
, m_prefix(prefix)
, m_uri(uri)
{
}
......@@ -82,4 +83,3 @@ Node::NodeType XPathNamespace::nodeType() const
}
#endif // XPATH_SUPPORT
......@@ -23,41 +23,40 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef XPathNamespace_H
#define XPathNamespace_H
#if XPATH_SUPPORT
#include "Element.h"
#include "AtomicString.h"
#include "Node.h"
namespace WebCore
{
namespace WebCore {
class Document;
class Document;
class Element;
class XPathNamespace : public Node
{
public:
XPathNamespace(PassRefPtr<Element> ownerElement,
const String& prefix, const String& uri);
virtual ~XPathNamespace();
class XPathNamespace : public Node {
public: