mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1466979 - Separate JS::ubi::EdgeVectorTracer and JS::ubi::SimpleEdgeRange into UbiNodeUtils.h r=jimb
Separated SimpleEdgeRange into the new UbiNodeUtils.h, updated build files, changed SimpleEdgeRange::init to SimpleEdgeRange::addTracerEdges, created bool addEdge to add new edges to the vector.
This commit is contained in:
parent
a71a9e006e
commit
19310fa39a
51
js/public/UbiNodeUtils.h
Normal file
51
js/public/UbiNodeUtils.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#ifndef js_UbiNodeUtils_h
|
||||
#define js_UbiNodeUtils_h
|
||||
|
||||
#include "jspubtd.h"
|
||||
|
||||
#include "js/UbiNode.h"
|
||||
#include "js/UniquePtr.h"
|
||||
|
||||
using JS::ubi::Edge;
|
||||
using JS::ubi::EdgeRange;
|
||||
using JS::ubi::EdgeVector;
|
||||
|
||||
namespace JS {
|
||||
namespace ubi {
|
||||
// An EdgeRange concrete class that simply holds a vector of Edges,
|
||||
// populated by the addTracerEdges method.
|
||||
class SimpleEdgeRange : public EdgeRange {
|
||||
EdgeVector edges;
|
||||
size_t i;
|
||||
|
||||
protected:
|
||||
void settle() {
|
||||
front_ = i < edges.length() ? &edges[i] : nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit SimpleEdgeRange() : edges(), i(0) { }
|
||||
|
||||
bool addTracerEdges(JSRuntime* rt, void* thing, JS::TraceKind kind, bool wantNames);
|
||||
|
||||
bool addEdge(Edge edge) {
|
||||
if (!edge.name || !edges.append(std::move(edge)))
|
||||
return false;
|
||||
settle();
|
||||
return true;
|
||||
}
|
||||
|
||||
void popFront() override { i++; settle(); }
|
||||
};
|
||||
|
||||
} // namespace JS
|
||||
} // namespace ubi
|
||||
|
||||
|
||||
#endif // js_UbiNodeUtils_h
|
@ -167,6 +167,7 @@ EXPORTS.js += [
|
||||
'../public/UbiNodeDominatorTree.h',
|
||||
'../public/UbiNodePostOrder.h',
|
||||
'../public/UbiNodeShortestPaths.h',
|
||||
'../public/UbiNodeUtils.h',
|
||||
'../public/UniquePtr.h',
|
||||
'../public/Utility.h',
|
||||
'../public/Value.h',
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "js/Debug.h"
|
||||
#include "js/TracingAPI.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "js/UbiNodeUtils.h"
|
||||
#include "js/Utility.h"
|
||||
#include "js/Vector.h"
|
||||
#include "util/Text.h"
|
||||
@ -222,7 +223,6 @@ Node::exposeToJS() const
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
// A JS::CallbackTracer subclass that adds a Edge to a Vector for each
|
||||
// edge on which it is invoked.
|
||||
class EdgeVectorTracer : public JS::CallbackTracer {
|
||||
@ -285,31 +285,6 @@ class EdgeVectorTracer : public JS::CallbackTracer {
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
// An EdgeRange concrete class that simply holds a vector of Edges,
|
||||
// populated by the init method.
|
||||
class SimpleEdgeRange : public EdgeRange {
|
||||
EdgeVector edges;
|
||||
size_t i;
|
||||
|
||||
void settle() {
|
||||
front_ = i < edges.length() ? &edges[i] : nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit SimpleEdgeRange() : edges(), i(0) { }
|
||||
|
||||
bool init(JSRuntime* rt, void* thing, JS::TraceKind kind, bool wantNames = true) {
|
||||
EdgeVectorTracer tracer(rt, &edges, wantNames);
|
||||
js::TraceChildren(&tracer, thing, kind);
|
||||
settle();
|
||||
return tracer.okay;
|
||||
}
|
||||
|
||||
void popFront() override { i++; settle(); }
|
||||
};
|
||||
|
||||
|
||||
template<typename Referent>
|
||||
JS::Zone*
|
||||
TracerConcrete<Referent>::zone() const
|
||||
@ -337,7 +312,7 @@ TracerConcrete<Referent>::edges(JSContext* cx, bool wantNames) const {
|
||||
if (!range)
|
||||
return nullptr;
|
||||
|
||||
if (!range->init(cx->runtime(), ptr, JS::MapTypeToTraceKind<Referent>::kind, wantNames))
|
||||
if (!range->addTracerEdges(cx->runtime(), ptr, JS::MapTypeToTraceKind<Referent>::kind, wantNames))
|
||||
return nullptr;
|
||||
|
||||
// Note: Clang 3.8 (or older) require an explicit construction of the
|
||||
@ -562,5 +537,13 @@ Concrete<RootList>::edges(JSContext* cx, bool wantNames) const {
|
||||
return js::MakeUnique<PreComputedEdgeRange>(get().edges);
|
||||
}
|
||||
|
||||
bool
|
||||
SimpleEdgeRange::addTracerEdges(JSRuntime* rt, void* thing, JS::TraceKind kind, bool wantNames) {
|
||||
EdgeVectorTracer tracer(rt, &edges, wantNames);
|
||||
js::TraceChildren(&tracer, thing, kind);
|
||||
settle();
|
||||
return tracer.okay;
|
||||
}
|
||||
|
||||
} // namespace ubi
|
||||
} // namespace JS
|
||||
|
Loading…
Reference in New Issue
Block a user