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>
|
|
|
|
#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-15 20:51:36 +01:00
|
|
|
put_native_function("gc", [](Object* this_object, Vector<Value>) -> Value {
|
2020-03-12 20:11:35 +01:00
|
|
|
dbg() << "Forced garbage collection requested!";
|
2020-03-15 20:51:36 +01:00
|
|
|
this_object->heap().collect_garbage();
|
2020-03-12 20:11:35 +01:00
|
|
|
return js_undefined();
|
2020-03-13 11:06:32 +01:00
|
|
|
});
|
2020-03-27 12:45:36 +01:00
|
|
|
put_native_function("isNaN", [](Object*, Vector<Value> arguments) -> Value {
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
return js_undefined();
|
2020-03-27 12:59:41 +01:00
|
|
|
return Value(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-12 20:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GlobalObject::~GlobalObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|