2020-03-12 20:11:35 +01:00
|
|
|
#include <AK/LogStream.h>
|
|
|
|
#include <AK/String.h>
|
2020-03-16 14:20:30 +01:00
|
|
|
#include <LibJS/Heap/Heap.h>
|
2020-03-12 20:11:35 +01:00
|
|
|
#include <LibJS/Interpreter.h>
|
2020-03-16 14:20:30 +01:00
|
|
|
#include <LibJS/Runtime/ConsoleObject.h>
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-03-21 17:52:12 +01:00
|
|
|
#include <LibJS/Runtime/MathObject.h>
|
2020-03-16 14:20:30 +01:00
|
|
|
#include <LibJS/Runtime/NativeFunction.h>
|
2020-03-28 17:23:54 +01:00
|
|
|
#include <LibJS/Runtime/ObjectConstructor.h>
|
2020-03-16 14:20:30 +01:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
2020-03-12 20:11:35 +01:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2020-03-13 11:06:32 +01:00
|
|
|
GlobalObject::GlobalObject()
|
2020-03-12 20:11:35 +01:00
|
|
|
{
|
2020-03-16 14:58:20 +01:00
|
|
|
put("console", heap().allocate<ConsoleObject>());
|
2020-03-28 22:48:35 +01:00
|
|
|
put_native_function("gc", [](Interpreter& interpreter) -> Value {
|
2020-03-12 20:11:35 +01:00
|
|
|
dbg() << "Forced garbage collection requested!";
|
2020-03-28 22:48:35 +01:00
|
|
|
interpreter.heap().collect_garbage();
|
2020-03-12 20:11:35 +01:00
|
|
|
return js_undefined();
|
2020-03-13 11:06:32 +01:00
|
|
|
});
|
2020-03-28 22:48:35 +01:00
|
|
|
put_native_function("isNaN", [](Interpreter& interpreter) -> Value {
|
|
|
|
if (interpreter.call_frame().arguments.size() < 1)
|
2020-03-27 12:45:36 +01:00
|
|
|
return js_undefined();
|
2020-03-28 22:48:35 +01:00
|
|
|
return Value(interpreter.call_frame().arguments[0].to_number().is_nan());
|
2020-03-27 12:45:36 +01:00
|
|
|
});
|
2020-03-21 17:52:12 +01:00
|
|
|
put("Math", heap().allocate<MathObject>());
|
2020-03-28 17:23:54 +01:00
|
|
|
put("Object", heap().allocate<ObjectConstructor>());
|
2020-03-12 20:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GlobalObject::~GlobalObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|