1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:48:14 +00:00

LibJS: Add Object::put_native_function() for convenience

This makes it a little bit nicer to add native function properties
to JavaScript objects.

Thanks to Sergey for suggesting it! :^)
This commit is contained in:
Andreas Kling 2020-03-13 11:06:32 +01:00
parent 6089d6566b
commit 9f38f4dbfb
5 changed files with 16 additions and 7 deletions

View file

@ -9,18 +9,18 @@
namespace JS {
GlobalObject::GlobalObject(Heap& heap)
GlobalObject::GlobalObject()
{
put("print", heap.allocate<NativeFunction>([](Interpreter&, Vector<Value> arguments) -> Value {
put_native_function("print", [](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 {
});
put_native_function("gc", [](Interpreter& interpreter, Vector<Value>) -> Value {
dbg() << "Forced garbage collection requested!";
interpreter.heap().collect_garbage();
return js_undefined();
}));
});
}
GlobalObject::~GlobalObject()