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