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/. */
6 
7 #ifndef js_UbiNodeUtils_h
8 #define js_UbiNodeUtils_h
9 
10 #include "jspubtd.h"
11 
12 #include "js/UbiNode.h"
13 #include "js/UniquePtr.h"
14 
15 using JS::ubi::Edge;
16 using JS::ubi::EdgeRange;
17 using JS::ubi::EdgeVector;
18 
19 namespace JS {
20 namespace ubi {
21 // An EdgeRange concrete class that simply holds a vector of Edges,
22 // populated by the addTracerEdges method.
23 class SimpleEdgeRange : public EdgeRange {
24   EdgeVector edges;
25   size_t i;
26 
27  protected:
settle()28   void settle() { front_ = i < edges.length() ? &edges[i] : nullptr; }
29 
30  public:
SimpleEdgeRange()31   explicit SimpleEdgeRange() : edges(), i(0) {}
32 
33   bool addTracerEdges(JSRuntime* rt, void* thing, JS::TraceKind kind,
34                       bool wantNames);
35 
addEdge(Edge edge)36   bool addEdge(Edge edge) {
37     if (!edges.append(std::move(edge))) return false;
38     settle();
39     return true;
40   }
41 
popFront()42   void popFront() override {
43     i++;
44     settle();
45   }
46 };
47 
48 }  // namespace ubi
49 }  // namespace JS
50 
51 #endif  // js_UbiNodeUtils_h
52