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