From 15d8b9c6714f5153608d46d0454ce468a39e9ec0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 9 Mar 2020 21:27:52 +0100 Subject: [PATCH] LibJS: Add magical "$gc" function that can be called to trigger GC This will be immensely useful for testing. --- Libraries/LibJS/AST.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index acac0b3273..db80f0e569 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -46,6 +46,11 @@ Value FunctionDeclaration::execute(Interpreter& interpreter) const Value CallExpression::execute(Interpreter& interpreter) const { + if (name() == "$gc") { + interpreter.heap().collect_garbage(); + return js_undefined(); + } + auto callee = interpreter.global_object().get(name()); ASSERT(callee.is_object()); auto* callee_object = callee.as_object();