mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 19:05:08 +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:
parent
6089d6566b
commit
9f38f4dbfb
5 changed files with 16 additions and 7 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue