GlobalObject.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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("NaN", js_nan());
  19. put("console", heap().allocate<ConsoleObject>());
  20. put("Date", heap().allocate<DateConstructor>());
  21. put("Error", heap().allocate<ErrorConstructor>());
  22. put("Math", heap().allocate<MathObject>());
  23. put("Object", heap().allocate<ObjectConstructor>());
  24. }
  25. GlobalObject::~GlobalObject()
  26. {
  27. }
  28. Value GlobalObject::gc(Interpreter& interpreter)
  29. {
  30. dbg() << "Forced garbage collection requested!";
  31. interpreter.heap().collect_garbage();
  32. return js_undefined();
  33. }
  34. Value GlobalObject::is_nan(Interpreter& interpreter)
  35. {
  36. if (interpreter.argument_count() < 1)
  37. return js_undefined();
  38. return Value(interpreter.argument(0).to_number().is_nan());
  39. }
  40. }