NodeUbiReporting.h (2826B)
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/. */ 6 7 #ifndef dom_NodeUbiReporting_h 8 #define dom_NodeUbiReporting_h 9 10 #include "Attr.h" 11 #include "Document.h" 12 #include "js/UbiNode.h" 13 #include "nsIContent.h" 14 #include "nsIContentInlines.h" 15 #include "nsINode.h" 16 17 /* 18 * This file defines specializations of JS::ubi::Concrete for DOM nodes 19 * so that the JS memory tools, which operate on the UbiNode graph, can 20 * define subclasses of JS::ubi::Base that represent DOM nodes and 21 * yield the outgoing edges in a DOM node graph for reporting. 22 */ 23 24 namespace JS::ubi { 25 26 // The DOM node base class. 27 // This is an abstract class and therefore does not require a concreteTypeName. 28 template <> 29 class Concrete<nsINode> : public Base { 30 protected: 31 explicit Concrete(nsINode* ptr) : Base(ptr) {} 32 33 public: 34 static void construct(void* storage, nsINode* ptr); 35 Size size(mozilla::MallocSizeOf mallocSizeOf) const override; 36 js::UniquePtr<EdgeRange> edges(JSContext* cx, bool wantNames) const override; 37 38 nsINode& get() const { return *static_cast<nsINode*>(ptr); } 39 CoarseType coarseType() const final { return CoarseType::DOMNode; } 40 const char16_t* descriptiveTypeName() const override; 41 }; 42 43 template <> 44 class Concrete<nsIContent> : public Concrete<nsINode> { 45 protected: 46 explicit Concrete(nsIContent* ptr) : Concrete<nsINode>(ptr) {} 47 48 public: 49 static void construct(void* storage, nsIContent* ptr) { 50 new (storage) Concrete(ptr); 51 } 52 const char16_t* typeName() const override { return concreteTypeName; }; 53 static const char16_t concreteTypeName[]; 54 }; 55 56 template <> 57 class Concrete<mozilla::dom::Document> : public Concrete<nsINode> { 58 protected: 59 explicit Concrete(mozilla::dom::Document* ptr) : Concrete<nsINode>(ptr) {} 60 61 public: 62 static void construct(void* storage, mozilla::dom::Document* ptr) { 63 new (storage) Concrete(ptr); 64 } 65 Size size(mozilla::MallocSizeOf mallocSizeOf) const override; 66 67 mozilla::dom::Document& getDoc() const { 68 return *static_cast<mozilla::dom::Document*>(ptr); 69 } 70 const char16_t* typeName() const override { return concreteTypeName; }; 71 static const char16_t concreteTypeName[]; 72 }; 73 74 template <> 75 class Concrete<mozilla::dom::Attr> : public Concrete<nsINode> { 76 protected: 77 explicit Concrete(mozilla::dom::Attr* ptr) : Concrete<nsINode>(ptr) {} 78 79 public: 80 static void construct(void* storage, mozilla::dom::Attr* ptr) { 81 new (storage) Concrete(ptr); 82 } 83 const char16_t* typeName() const override { return concreteTypeName; }; 84 static const char16_t concreteTypeName[]; 85 }; 86 87 } // namespace JS::ubi 88 89 #endif