Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / nsChildContentList.h
blobaf43253cbf546cf81e83c579f3a0d0ad6861edf4
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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/. */
7 #ifndef nsChildContentList_h__
8 #define nsChildContentList_h__
10 #include "mozilla/RefPtr.h"
11 #include "nsISupportsImpl.h"
12 #include "nsINodeList.h" // base class
13 #include "js/TypeDecls.h" // for Handle, Value, JSObject, JSContext
15 class nsIContent;
16 class nsINode;
18 /**
19 * Class that implements the nsINodeList interface (a list of children of
20 * the content), by holding a reference to the content and delegating Length
21 * and Item to its existing child list.
22 * @see nsINodeList
24 class nsAttrChildContentList : public nsINodeList {
25 public:
26 explicit nsAttrChildContentList(nsINode* aNode) : mNode(aNode) {}
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
29 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_WRAPPERCACHE_CLASS(nsAttrChildContentList)
31 // nsWrapperCache
32 virtual JSObject* WrapObject(JSContext* cx,
33 JS::Handle<JSObject*> aGivenProto) override;
35 // nsINodeList interface
36 virtual int32_t IndexOf(nsIContent* aContent) override;
37 virtual nsIContent* Item(uint32_t aIndex) override;
38 uint32_t Length() override;
39 nsINode* GetParentObject() final { return mNode; }
41 virtual void InvalidateCacheIfAvailable() {}
43 protected:
44 virtual ~nsAttrChildContentList() = default;
46 private:
47 // The node whose children make up the list.
48 RefPtr<nsINode> mNode;
51 class nsParentNodeChildContentList final : public nsAttrChildContentList {
52 public:
53 explicit nsParentNodeChildContentList(nsINode* aNode)
54 : nsAttrChildContentList(aNode), mIsCacheValid(false) {
55 ValidateCache();
58 // nsINodeList interface
59 virtual int32_t IndexOf(nsIContent* aContent) override;
60 virtual nsIContent* Item(uint32_t aIndex) override;
61 uint32_t Length() override;
63 void InvalidateCacheIfAvailable() final { InvalidateCache(); }
65 void InvalidateCache() {
66 mIsCacheValid = false;
67 mCachedChildArray.Clear();
70 private:
71 ~nsParentNodeChildContentList() = default;
73 // Return true if validation succeeds, false otherwise
74 bool ValidateCache();
76 // Whether cached array of child nodes is valid
77 bool mIsCacheValid;
79 // Cached array of child nodes
80 AutoTArray<nsIContent*, 8> mCachedChildArray;
83 #endif /* nsChildContentList_h__ */