XPathExpression.h (2456B)
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/. */ 5 6 #ifndef mozilla_dom_XPathExpression_h 7 #define mozilla_dom_XPathExpression_h 8 9 #include "mozilla/UniquePtr.h" 10 #include "mozilla/dom/NonRefcountedDOMObject.h" 11 #include "mozilla/dom/XPathExpressionBinding.h" 12 #include "nsCycleCollectionParticipant.h" 13 #include "nsIWeakReferenceUtils.h" 14 15 class Expr; 16 17 class nsINode; 18 class txResultRecycler; 19 20 namespace mozilla::dom { 21 22 class Document; 23 class XPathResult; 24 25 /** 26 * A class for evaluating an XPath expression string 27 */ 28 class XPathExpression final : public NonRefcountedDOMObject { 29 public: 30 XPathExpression(mozilla::UniquePtr<Expr>&& aExpression, 31 txResultRecycler* aRecycler, Document* aDocument); 32 ~XPathExpression(); 33 34 bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, 35 JS::MutableHandle<JSObject*> aReflector) { 36 return XPathExpression_Binding::Wrap(aCx, this, aGivenProto, aReflector); 37 } 38 39 already_AddRefed<XPathResult> Evaluate(JSContext* aCx, nsINode& aContextNode, 40 uint16_t aType, 41 JS::Handle<JSObject*> aInResult, 42 ErrorResult& aRv) { 43 return EvaluateWithContext(aCx, aContextNode, 1, 1, aType, aInResult, aRv); 44 } 45 already_AddRefed<XPathResult> EvaluateWithContext( 46 JSContext* aCx, nsINode& aContextNode, uint32_t aContextPosition, 47 uint32_t aContextSize, uint16_t aType, JS::Handle<JSObject*> aInResult, 48 ErrorResult& aRv); 49 already_AddRefed<XPathResult> Evaluate(nsINode& aContextNode, uint16_t aType, 50 XPathResult* aInResult, 51 ErrorResult& aRv) { 52 return EvaluateWithContext(aContextNode, 1, 1, aType, aInResult, aRv); 53 } 54 already_AddRefed<XPathResult> EvaluateWithContext( 55 nsINode& aContextNode, uint32_t aContextPosition, uint32_t aContextSize, 56 uint16_t aType, XPathResult* aInResult, ErrorResult& aRv); 57 58 private: 59 mozilla::UniquePtr<Expr> mExpression; 60 RefPtr<txResultRecycler> mRecycler; 61 nsWeakPtr mDocument; 62 bool mCheckDocument; 63 }; 64 65 } // namespace mozilla::dom 66 67 #endif /* mozilla_dom_XPathExpression_h */