Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsTraversal.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 *
3
 * This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "nsTraversal.h"
8
9
#include "nsError.h"
10
#include "nsINode.h"
11
#include "mozilla/AutoRestore.h"
12
#include "mozilla/dom/NodeFilterBinding.h"
13
14
#include "nsGkAtoms.h"
15
16
using namespace mozilla;
17
using namespace mozilla::dom;
18
19
nsTraversal::nsTraversal(nsINode *aRoot,
20
                         uint32_t aWhatToShow,
21
                         NodeFilter* aFilter) :
22
    mRoot(aRoot),
23
    mWhatToShow(aWhatToShow),
24
    mFilter(aFilter),
25
    mInAcceptNode(false)
26
0
{
27
0
    NS_ASSERTION(aRoot, "invalid root in call to nsTraversal constructor");
28
0
}
29
30
nsTraversal::~nsTraversal()
31
0
{
32
0
    /* destructor code */
33
0
}
34
35
/*
36
 * Tests if and how a node should be filtered. Uses mWhatToShow and
37
 * mFilter to test the node.
38
 * @param aNode     Node to test
39
 * @param aResult   Whether we succeeded
40
 * @returns         Filtervalue. See NodeFilter.webidl
41
 */
42
int16_t
43
nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult)
44
0
{
45
0
    if (mInAcceptNode) {
46
0
        aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
47
0
        return 0;
48
0
    }
49
0
50
0
    uint16_t nodeType = aNode->NodeType();
51
0
52
0
    if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) {
53
0
        return NodeFilter_Binding::FILTER_SKIP;
54
0
    }
55
0
56
0
    if (!mFilter) {
57
0
        // No filter, just accept
58
0
        return NodeFilter_Binding::FILTER_ACCEPT;
59
0
    }
60
0
61
0
    AutoRestore<bool> inAcceptNode(mInAcceptNode);
62
0
    mInAcceptNode = true;
63
0
    // No need to pass in an execution reason, since the generated default,
64
0
    // "NodeFilter.acceptNode", is pretty much exactly what we'd say anyway.
65
0
    return mFilter->AcceptNode(*aNode, aResult, nullptr,
66
0
                               CallbackObject::eRethrowExceptions);
67
0
}