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
[] =
16 const char16_t
JS::ubi::Concrete
<nsIContent
>::concreteTypeName
[] =
18 const char16_t
JS::ubi::Concrete
<mozilla::dom::Attr
>::concreteTypeName
[] =
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
>();
35 if (get().GetParent()) {
36 char16_t
* edgeName
= nullptr;
38 edgeName
= NS_xstrdup(u
"Parent Node");
40 if (!range
->addEdge(JS::ubi::Edge(edgeName
, get().GetParent()))) {
44 for (auto curr
= get().GetFirstChild(); curr
; curr
= curr
->GetNextSibling()) {
45 char16_t
* edgeName
= nullptr;
47 edgeName
= NS_xstrdup(u
"Child Node");
49 if (!range
->addEdge(JS::ubi::Edge(edgeName
, curr
))) {
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
);
62 get().AddSizeOfIncludingThis(wn
, &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
);
75 getDoc().DocAddSizeOfIncludingThis(wn
);
76 return wn
.getTotalSize();