1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 00:35:06 +00:00

LibJS: Make sure we mark everything reachable from the scope stack

This ensures that local variables survive GC.
This commit is contained in:
Andreas Kling 2020-03-09 21:29:22 +01:00
parent 26165cd92a
commit 363c40e3f3
3 changed files with 17 additions and 1 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Badge.h>
#include <LibJS/AST.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Object.h>
@ -100,4 +101,16 @@ Value Interpreter::get_variable(const String& name)
return global_object().get(name);
}
void Interpreter::collect_roots(Badge<Heap>, HashTable<Cell*>& roots)
{
roots.set(m_global_object);
for (auto& scope : m_scope_stack) {
for (auto& it : scope.variables) {
if (it.value.is_object())
roots.set(it.value.as_object());
}
}
}
}