summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/GlobalObject.cpp
blob: b45fb867cab911f6405010bb023bff796066c1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <AK/LogStream.h>
#include <AK/String.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/MathObject.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Value.h>

namespace JS {

GlobalObject::GlobalObject()
{
    put("console", heap().allocate<ConsoleObject>());
    put_native_function("gc", [](Object* this_object, Vector<Value>) -> Value {
        dbg() << "Forced garbage collection requested!";
        this_object->heap().collect_garbage();
        return js_undefined();
    });
    put_native_function("isNaN", [](Object*, Vector<Value> arguments) -> Value {
        if (arguments.size() < 1)
            return js_undefined();
        return Value(arguments[0].to_number().is_nan());
    });
    put("Math", heap().allocate<MathObject>());
}

GlobalObject::~GlobalObject()
{
}

}