1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-30 10:12:07 +00:00

LibJS: Replace $gc() hack with a NativeFunction on the global object

To make this work, also start passing Interpreter& to native functions.
This commit is contained in:
Andreas Kling 2020-03-12 20:04:54 +01:00
parent 9ad17d4674
commit d1d136b4e5
5 changed files with 12 additions and 12 deletions

View file

@ -38,11 +38,16 @@ Interpreter::Interpreter()
: m_heap(*this)
{
m_global_object = heap().allocate<Object>();
m_global_object->put("print", heap().allocate<NativeFunction>([](Vector<Argument> arguments) -> Value {
m_global_object->put("print", heap().allocate<NativeFunction>([](Interpreter&, Vector<Argument> arguments) -> Value {
for (auto& argument : arguments)
printf("%s ", argument.value.to_string().characters());
return js_undefined();
}));
m_global_object->put("gc", heap().allocate<NativeFunction>([](Interpreter& interpreter, Vector<Argument>) -> Value {
dbg() << "Forced garbage collection requested!";
interpreter.heap().collect_garbage();
return js_undefined();
}));
}
Interpreter::~Interpreter()