NodeUbiReporting.cpp (2534B)
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 #include "NodeUbiReporting.h" 8 9 #include "js/UbiNodeUtils.h" 10 #include "nsWindowSizes.h" 11 12 using JS::ubi::EdgeRange; 13 using JS::ubi::SimpleEdgeRange; 14 15 const char16_t JS::ubi::Concrete<mozilla::dom::Document>::concreteTypeName[] = 16 u"Document"; 17 const char16_t JS::ubi::Concrete<nsIContent>::concreteTypeName[] = 18 u"nsIContent"; 19 const char16_t JS::ubi::Concrete<mozilla::dom::Attr>::concreteTypeName[] = 20 u"Attr"; 21 22 void JS::ubi::Concrete<nsINode>::construct(void* storage, nsINode* ptr) { 23 // nsINode is abstract, and all of its inherited instances have 24 // an overridden function with instructions to construct ubi::Nodes. 25 // We actually want to call that function and construct from those instances. 26 ptr->ConstructUbiNode(storage); 27 } 28 29 js::UniquePtr<EdgeRange> JS::ubi::Concrete<nsINode>::edges( 30 JSContext* cx, bool wantNames) const { 31 AutoSuppressGCAnalysis suppress; 32 auto range = js::MakeUnique<SimpleEdgeRange>(); 33 if (!range) { 34 return nullptr; 35 } 36 if (get().GetParent()) { 37 char16_t* edgeName = nullptr; 38 if (wantNames) { 39 edgeName = NS_xstrdup(u"Parent Node"); 40 } 41 if (!range->addEdge(JS::ubi::Edge(edgeName, get().GetParent()))) { 42 return nullptr; 43 } 44 } 45 for (auto curr = get().GetFirstChild(); curr; curr = curr->GetNextSibling()) { 46 char16_t* edgeName = nullptr; 47 if (wantNames) { 48 edgeName = NS_xstrdup(u"Child Node"); 49 } 50 if (!range->addEdge(JS::ubi::Edge(edgeName, curr))) { 51 return nullptr; 52 } 53 } 54 return js::UniquePtr<EdgeRange>(range.release()); 55 } 56 57 JS::ubi::Node::Size JS::ubi::Concrete<nsINode>::size( 58 mozilla::MallocSizeOf mallocSizeOf) const { 59 AutoSuppressGCAnalysis suppress; 60 mozilla::SizeOfState sz(mallocSizeOf); 61 nsWindowSizes wn(sz); 62 size_t n = 0; 63 get().AddSizeOfIncludingThis(wn, &n); 64 return n; 65 } 66 67 const char16_t* JS::ubi::Concrete<nsINode>::descriptiveTypeName() const { 68 return get().NodeName().get(); 69 } 70 71 JS::ubi::Node::Size JS::ubi::Concrete<mozilla::dom::Document>::size( 72 mozilla::MallocSizeOf mallocSizeOf) const { 73 AutoSuppressGCAnalysis suppress; 74 mozilla::SizeOfState sz(mallocSizeOf); 75 nsWindowSizes wn(sz); 76 getDoc().DocAddSizeOfIncludingThis(wn); 77 return wn.getTotalSize(); 78 }