From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/base/nsTraversal.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dom/base/nsTraversal.cpp (limited to 'dom/base/nsTraversal.cpp') diff --git a/dom/base/nsTraversal.cpp b/dom/base/nsTraversal.cpp new file mode 100644 index 000000000..2f7594e8e --- /dev/null +++ b/dom/base/nsTraversal.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsTraversal.h" + +#include "nsIDOMNode.h" +#include "nsError.h" +#include "nsINode.h" +#include "mozilla/AutoRestore.h" + +#include "nsGkAtoms.h" + +using namespace mozilla; +using namespace mozilla::dom; + +nsTraversal::nsTraversal(nsINode *aRoot, + uint32_t aWhatToShow, + NodeFilterHolder aFilter) : + mRoot(aRoot), + mWhatToShow(aWhatToShow), + mFilter(Move(aFilter)), + mInAcceptNode(false) +{ + NS_ASSERTION(aRoot, "invalid root in call to nsTraversal constructor"); +} + +nsTraversal::~nsTraversal() +{ + /* destructor code */ +} + +/* + * Tests if and how a node should be filtered. Uses mWhatToShow and + * mFilter to test the node. + * @param aNode Node to test + * @param aResult Whether we succeeded + * @returns Filtervalue. See nsIDOMNodeFilter.idl + */ +int16_t +nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult) +{ + if (mInAcceptNode) { + aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return 0; + } + + uint16_t nodeType = aNode->NodeType(); + + if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) { + return nsIDOMNodeFilter::FILTER_SKIP; + } + + if (!mFilter.GetISupports()) { + // No filter, just accept + return nsIDOMNodeFilter::FILTER_ACCEPT; + } + + if (mFilter.HasWebIDLCallback()) { + AutoRestore inAcceptNode(mInAcceptNode); + mInAcceptNode = true; + // No need to pass in an execution reason, since the generated default, + // "NodeFilter.acceptNode", is pretty much exactly what we'd say anyway. + return mFilter.GetWebIDLCallback()-> + AcceptNode(*aNode, aResult, nullptr, + CallbackObject::eRethrowExceptions); + } + + nsCOMPtr domNode = do_QueryInterface(aNode); + AutoRestore inAcceptNode(mInAcceptNode); + mInAcceptNode = true; + int16_t filtered; + nsresult rv = mFilter.GetXPCOMCallback()->AcceptNode(domNode, &filtered); + if (NS_FAILED(rv)) { + aResult.Throw(rv); + } + return filtered; +} -- cgit v1.2.3