mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-03-06 05:24:17 +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:
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/Heap.h>
|
||||
#include <LibJS/NativeFunction.h>
|
||||
#include <LibJS/Object.h>
|
||||
#include <LibJS/Value.h>
|
||||
|
||||
@@ -48,6 +50,11 @@ void Object::put(String property_name, Value value)
|
||||
m_properties.set(property_name, move(value));
|
||||
}
|
||||
|
||||
void Object::put_native_function(String property_name, AK::Function<Value(Interpreter&, Vector<Value>)> native_function)
|
||||
{
|
||||
put(property_name, heap().allocate<NativeFunction>(move(native_function)));
|
||||
}
|
||||
|
||||
void Object::visit_children(Cell::Visitor& visitor)
|
||||
{
|
||||
Cell::visit_children(visitor);
|
||||
|
||||
Reference in New Issue
Block a user