2018-07-07 02:52:42 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "NodeUbiReporting.h"
|
|
|
|
#include "js/UbiNodeUtils.h"
|
|
|
|
#include "nsWindowSizes.h"
|
|
|
|
|
|
|
|
using JS::ubi::SimpleEdgeRange;
|
|
|
|
using JS::ubi::EdgeRange;
|
|
|
|
|
|
|
|
const char16_t JS::ubi::Concrete<nsIDocument>::concreteTypeName[] = u"nsIDocument";
|
|
|
|
const char16_t JS::ubi::Concrete<nsIContent>::concreteTypeName[] = u"nsIContent";
|
|
|
|
const char16_t JS::ubi::Concrete<Attr>::concreteTypeName[] = u"Attr";
|
|
|
|
|
|
|
|
void
|
|
|
|
JS::ubi::Concrete<nsINode>::construct(void* storage, nsINode* ptr)
|
|
|
|
{
|
|
|
|
// nsINode is abstract, and all of its inherited instances have
|
|
|
|
// an overridden function with instructions to construct ubi::Nodes.
|
|
|
|
// We actually want to call that function and construct from those instances.
|
|
|
|
ptr->ConstructUbiNode(storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
js::UniquePtr<EdgeRange>
|
|
|
|
JS::ubi::Concrete<nsINode>::edges(JSContext* cx, bool wantNames) const
|
|
|
|
{
|
|
|
|
AutoSuppressGCAnalysis suppress;
|
|
|
|
auto range = js::MakeUnique<SimpleEdgeRange>();
|
|
|
|
if (!range) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (get().GetParent()) {
|
|
|
|
char16_t* edgeName = nullptr;
|
|
|
|
if (wantNames) {
|
|
|
|
edgeName = NS_strdup(u"Parent Node");
|
|
|
|
}
|
|
|
|
if (!range->addEdge(JS::ubi::Edge(edgeName, get().GetParent()))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto curr = get().GetFirstChild(); curr; curr = curr->GetNextSibling()) {
|
|
|
|
char16_t* edgeName = nullptr;
|
|
|
|
if (wantNames) {
|
|
|
|
edgeName = NS_strdup(u"Child Node");
|
|
|
|
}
|
|
|
|
if (!range->addEdge(JS::ubi::Edge(edgeName, curr))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 21:00:40 +03:00
|
|
|
return js::UniquePtr<EdgeRange>(range.release());
|
2018-07-07 02:52:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::ubi::Node::Size
|
|
|
|
JS::ubi::Concrete<nsINode>::size(mozilla::MallocSizeOf mallocSizeOf) const
|
|
|
|
{
|
|
|
|
AutoSuppressGCAnalysis suppress;
|
|
|
|
mozilla::SizeOfState sz(mallocSizeOf);
|
|
|
|
nsWindowSizes wn(sz);
|
|
|
|
size_t n = 0;
|
|
|
|
get().AddSizeOfIncludingThis(wn, &n);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-07-17 00:42:07 +03:00
|
|
|
const char16_t*
|
|
|
|
JS::ubi::Concrete<nsINode>::descriptiveTypeName() const
|
|
|
|
{
|
|
|
|
return get().NodeName().get();
|
|
|
|
}
|
|
|
|
|
2018-07-07 02:52:42 +03:00
|
|
|
JS::ubi::Node::Size
|
|
|
|
JS::ubi::Concrete<nsIDocument>::size(mozilla::MallocSizeOf mallocSizeOf) const
|
|
|
|
{
|
|
|
|
AutoSuppressGCAnalysis suppress;
|
|
|
|
mozilla::SizeOfState sz(mallocSizeOf);
|
|
|
|
nsWindowSizes wn(sz);
|
|
|
|
getDoc().DocAddSizeOfIncludingThis(wn);
|
|
|
|
return wn.getTotalSize();
|
|
|
|
}
|