2020-03-12 20:11:35 +01:00
|
|
|
#include <AK/LogStream.h>
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <LibJS/GlobalObject.h>
|
|
|
|
#include <LibJS/Heap.h>
|
|
|
|
#include <LibJS/Interpreter.h>
|
|
|
|
#include <LibJS/NativeFunction.h>
|
|
|
|
#include <LibJS/Value.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
GlobalObject::GlobalObject(Heap& heap)
|
|
|
|
{
|
2020-03-13 10:08:52 +01:00
|
|
|
put("print", heap.allocate<NativeFunction>([](Interpreter&, Vector<Value> arguments) -> Value {
|
2020-03-12 20:11:35 +01:00
|
|
|
for (auto& argument : arguments)
|
2020-03-13 10:08:52 +01:00
|
|
|
printf("%s ", argument.to_string().characters());
|
2020-03-12 20:11:35 +01:00
|
|
|
return js_undefined();
|
|
|
|
}));
|
2020-03-13 10:08:52 +01:00
|
|
|
put("gc", heap.allocate<NativeFunction>([](Interpreter& interpreter, Vector<Value>) -> Value {
|
2020-03-12 20:11:35 +01:00
|
|
|
dbg() << "Forced garbage collection requested!";
|
|
|
|
interpreter.heap().collect_garbage();
|
|
|
|
return js_undefined();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalObject::~GlobalObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|