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>
|
2020-03-30 00:21:56 +01:00
|
|
|
#include <LibJS/Runtime/DateConstructor.h>
|
2020-04-01 19:42:07 +01:00
|
|
|
#include <LibJS/Runtime/ErrorConstructor.h>
|
2020-04-04 14:34:31 +01:00
|
|
|
#include <LibJS/Runtime/FunctionConstructor.h>
|
2020-03-16 14:20:30 +01:00
|
|
|
#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-28 23:10:37 +01:00
|
|
|
put_native_function("gc", gc);
|
2020-04-04 14:13:53 +01:00
|
|
|
put_native_function("isNaN", is_nan, 1);
|
2020-03-28 23:10:37 +01:00
|
|
|
|
2020-04-02 16:59:01 +01:00
|
|
|
// FIXME: These are read-only in ES5
|
2020-04-01 21:00:09 +01:00
|
|
|
put("NaN", js_nan());
|
2020-04-02 16:59:01 +01:00
|
|
|
put("Infinity", js_infinity());
|
2020-04-02 22:08:14 +01:00
|
|
|
put("undefined", js_undefined());
|
2020-04-02 16:59:01 +01:00
|
|
|
|
2020-03-16 14:58:20 +01:00
|
|
|
put("console", heap().allocate<ConsoleObject>());
|
2020-03-30 00:21:56 +01:00
|
|
|
put("Date", heap().allocate<DateConstructor>());
|
2020-04-01 19:42:07 +01:00
|
|
|
put("Error", heap().allocate<ErrorConstructor>());
|
2020-04-04 14:34:31 +01:00
|
|
|
put("Function", heap().allocate<FunctionConstructor>());
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-28 23:10:37 +01:00
|
|
|
Value GlobalObject::gc(Interpreter& interpreter)
|
|
|
|
{
|
|
|
|
dbg() << "Forced garbage collection requested!";
|
|
|
|
interpreter.heap().collect_garbage();
|
|
|
|
return js_undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value GlobalObject::is_nan(Interpreter& interpreter)
|
|
|
|
{
|
2020-04-01 22:38:59 +02:00
|
|
|
if (interpreter.argument_count() < 1)
|
2020-03-28 23:10:37 +01:00
|
|
|
return js_undefined();
|
2020-04-01 22:38:59 +02:00
|
|
|
return Value(interpreter.argument(0).to_number().is_nan());
|
2020-03-28 23:10:37 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 20:11:35 +01:00
|
|
|
}
|