1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 15:05:07 +00:00
serenity/Libraries/LibJS/GlobalObject.cpp
Andreas Kling d9c7009604 LibJS: Split Function into subclasses NativeFunction and ScriptFunction
Both types of functions are now Function and implement calling via:

    virtual Value call(Interpreter&, Vector<Value> arguments);

This removes the need for CallExpression::execute() to care about which
kind of function it's calling. :^)
2020-03-13 11:08:16 +01:00

30 lines
797 B
C++

#include <AK/LogStream.h>
#include <AK/String.h>
#include <LibJS/GlobalObject.h>
#include <LibJS/Heap.h>
#include <LibJS/Interpreter.h>
#include <LibJS/NativeFunction.h>
#include <LibJS/Value.h>
#include <stdio.h>
namespace JS {
GlobalObject::GlobalObject(Heap& heap)
{
put("print", heap.allocate<NativeFunction>([](Interpreter&, Vector<Value> arguments) -> Value {
for (auto& argument : arguments)
printf("%s ", argument.to_string().characters());
return js_undefined();
}));
put("gc", heap.allocate<NativeFunction>([](Interpreter& interpreter, Vector<Value>) -> Value {
dbg() << "Forced garbage collection requested!";
interpreter.heap().collect_garbage();
return js_undefined();
}));
}
GlobalObject::~GlobalObject()
{
}
}