Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/TreeWalker.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* vim: set ts=4 et sw=4 tw=80: */
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
/*
8
 * Implementation of DOM Traversal's TreeWalker
9
 */
10
11
#ifndef mozilla_dom_TreeWalker_h
12
#define mozilla_dom_TreeWalker_h
13
14
#include "nsISupports.h"
15
#include "nsTraversal.h"
16
#include "nsCOMPtr.h"
17
#include "nsTArray.h"
18
#include "nsCycleCollectionParticipant.h"
19
20
class nsINode;
21
22
namespace mozilla {
23
namespace dom {
24
25
class TreeWalker final : public nsISupports, public nsTraversal
26
{
27
    virtual ~TreeWalker();
28
29
public:
30
    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31
32
    TreeWalker(nsINode *aRoot,
33
               uint32_t aWhatToShow,
34
               NodeFilter* aFilter);
35
36
    NS_DECL_CYCLE_COLLECTION_CLASS(TreeWalker)
37
38
    // WebIDL API
39
    nsINode* Root() const
40
0
    {
41
0
        return mRoot;
42
0
    }
43
    uint32_t WhatToShow() const
44
0
    {
45
0
        return mWhatToShow;
46
0
    }
47
    NodeFilter* GetFilter()
48
0
    {
49
0
        return mFilter;
50
0
    }
51
    nsINode* CurrentNode() const
52
0
    {
53
0
        return mCurrentNode;
54
0
    }
55
    void SetCurrentNode(nsINode& aNode, ErrorResult& aResult);
56
    // All our traversal methods return strong refs because filtering can
57
    // remove nodes from the tree.
58
    already_AddRefed<nsINode> ParentNode(ErrorResult& aResult);
59
    already_AddRefed<nsINode> FirstChild(ErrorResult& aResult);
60
    already_AddRefed<nsINode> LastChild(ErrorResult& aResult);
61
    already_AddRefed<nsINode> PreviousSibling(ErrorResult& aResult);
62
    already_AddRefed<nsINode> NextSibling(ErrorResult& aResult);
63
    already_AddRefed<nsINode> PreviousNode(ErrorResult& aResult);
64
    already_AddRefed<nsINode> NextNode(ErrorResult& aResult);
65
66
    bool WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
67
68
private:
69
    nsCOMPtr<nsINode> mCurrentNode;
70
71
    /*
72
     * Implements FirstChild and LastChild which only vary in which direction
73
     * they search.
74
     * @param aReversed Controls whether we search forwards or backwards
75
     * @param aResult   Whether we threw or not.
76
     * @returns         The desired node. Null if no child is found
77
     */
78
    already_AddRefed<nsINode> FirstChildInternal(bool aReversed,
79
                                                 ErrorResult& aResult);
80
81
    /*
82
     * Implements NextSibling and PreviousSibling which only vary in which
83
     * direction they search.
84
     * @param aReversed Controls whether we search forwards or backwards
85
     * @param aResult   Whether we threw or not.
86
     * @returns         The desired node. Null if no child is found
87
     */
88
    already_AddRefed<nsINode> NextSiblingInternal(bool aReversed,
89
                                                  ErrorResult& aResult);
90
};
91
92
} // namespace dom
93
} // namespace mozilla
94
95
#endif // mozilla_dom_TreeWalker_h
96