Selaa lähdekoodia

LibJS: Add Cell::interpreter() convenience helper

This allows you to go from any Cell* to the Interpreter.
Andreas Kling 5 vuotta sitten
vanhempi
commit
9b4358e150
3 muutettua tiedostoa jossa 9 lisäystä ja 0 poistoa
  1. 6 0
      Libraries/LibJS/Cell.cpp
  2. 1 0
      Libraries/LibJS/Cell.h
  3. 2 0
      Libraries/LibJS/Heap.h

+ 6 - 0
Libraries/LibJS/Cell.cpp

@@ -26,6 +26,7 @@
 
 #include <AK/LogStream.h>
 #include <LibJS/Cell.h>
+#include <LibJS/Heap.h>
 #include <LibJS/HeapBlock.h>
 #include <LibJS/Object.h>
 #include <LibJS/PrimitiveString.h>
@@ -44,6 +45,11 @@ Heap& Cell::heap()
     return HeapBlock::from_cell(this)->heap();
 }
 
+Interpreter& Cell::interpreter()
+{
+    return heap().interpreter();
+}
+
 const LogStream& operator<<(const LogStream& stream, const Cell* cell)
 {
     if (!cell)

+ 1 - 0
Libraries/LibJS/Cell.h

@@ -52,6 +52,7 @@ public:
     virtual void visit_children(Visitor&) {}
 
     Heap& heap();
+    Interpreter& interpreter();
 
 private:
     bool m_mark { false };

+ 2 - 0
Libraries/LibJS/Heap.h

@@ -53,6 +53,8 @@ public:
 
     void collect_garbage();
 
+    Interpreter& interpreter() { return m_interpreter; }
+
 private:
     Cell* allocate_cell(size_t);