GlobalObject.cpp 1.0 KB

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