GlobalObject.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <AK/LogStream.h>
  2. #include <AK/String.h>
  3. #include <LibJS/Heap/Heap.h>
  4. #include <LibJS/Interpreter.h>
  5. #include <LibJS/Runtime/ConsoleObject.h>
  6. #include <LibJS/Runtime/DateConstructor.h>
  7. #include <LibJS/Runtime/ErrorConstructor.h>
  8. #include <LibJS/Runtime/GlobalObject.h>
  9. #include <LibJS/Runtime/MathObject.h>
  10. #include <LibJS/Runtime/NativeFunction.h>
  11. #include <LibJS/Runtime/ObjectConstructor.h>
  12. #include <LibJS/Runtime/Value.h>
  13. namespace JS {
  14. GlobalObject::GlobalObject()
  15. {
  16. put_native_function("gc", gc);
  17. put_native_function("isNaN", is_nan);
  18. put("console", heap().allocate<ConsoleObject>());
  19. put("Date", heap().allocate<DateConstructor>());
  20. put("Error", heap().allocate<ErrorConstructor>());
  21. put("Math", heap().allocate<MathObject>());
  22. put("Object", heap().allocate<ObjectConstructor>());
  23. }
  24. GlobalObject::~GlobalObject()
  25. {
  26. }
  27. Value GlobalObject::gc(Interpreter& interpreter)
  28. {
  29. dbg() << "Forced garbage collection requested!";
  30. interpreter.heap().collect_garbage();
  31. return js_undefined();
  32. }
  33. Value GlobalObject::is_nan(Interpreter& interpreter)
  34. {
  35. if (interpreter.call_frame().arguments.size() < 1)
  36. return js_undefined();
  37. return Value(interpreter.call_frame().arguments[0].to_number().is_nan());
  38. }
  39. }