GlobalObject.cpp 757 B

123456789101112131415161718192021222324252627282930
  1. #include <AK/LogStream.h>
  2. #include <AK/String.h>
  3. #include <LibJS/GlobalObject.h>
  4. #include <LibJS/Heap.h>
  5. #include <LibJS/Interpreter.h>
  6. #include <LibJS/NativeFunction.h>
  7. #include <LibJS/Value.h>
  8. #include <stdio.h>
  9. namespace JS {
  10. GlobalObject::GlobalObject()
  11. {
  12. put_native_function("print", [](Interpreter&, Vector<Value> arguments) -> Value {
  13. for (auto& argument : arguments)
  14. printf("%s ", argument.to_string().characters());
  15. return js_undefined();
  16. });
  17. put_native_function("gc", [](Interpreter& interpreter, Vector<Value>) -> Value {
  18. dbg() << "Forced garbage collection requested!";
  19. interpreter.heap().collect_garbage();
  20. return js_undefined();
  21. });
  22. }
  23. GlobalObject::~GlobalObject()
  24. {
  25. }
  26. }