Explorar o código

LibJS: Add magical "$gc" function that can be called to trigger GC

This will be immensely useful for testing.
Andreas Kling %!s(int64=5) %!d(string=hai) anos
pai
achega
15d8b9c671
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      Libraries/LibJS/AST.cpp

+ 5 - 0
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();