GlobalObject.cpp 931 B

123456789101112131415161718192021222324252627282930313233
  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/GlobalObject.h>
  7. #include <LibJS/Runtime/MathObject.h>
  8. #include <LibJS/Runtime/NativeFunction.h>
  9. #include <LibJS/Runtime/Value.h>
  10. namespace JS {
  11. GlobalObject::GlobalObject()
  12. {
  13. put("console", heap().allocate<ConsoleObject>());
  14. put_native_function("gc", [](Object* this_object, Vector<Value>) -> Value {
  15. dbg() << "Forced garbage collection requested!";
  16. this_object->heap().collect_garbage();
  17. return js_undefined();
  18. });
  19. put_native_function("isNaN", [](Object*, Vector<Value> arguments) -> Value {
  20. if (arguments.size() < 1)
  21. return js_undefined();
  22. return Value(arguments[0].to_number().is_nan());
  23. });
  24. put("Math", heap().allocate<MathObject>());
  25. }
  26. GlobalObject::~GlobalObject()
  27. {
  28. }
  29. }