diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-13 11:06:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-13 11:08:16 +0100 |
commit | 9f38f4dbfb27ecdfa741ba0057fa7a88f622ce27 (patch) | |
tree | d8d4d3fda40267a2db757319407b6f3966546336 /Libraries/LibJS/Object.cpp | |
parent | 6089d6566b6db7a4c4064a3ea343a78fff98e544 (diff) | |
download | serenity-9f38f4dbfb27ecdfa741ba0057fa7a88f622ce27.zip |
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! :^)
Diffstat (limited to 'Libraries/LibJS/Object.cpp')
-rw-r--r-- | Libraries/LibJS/Object.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Libraries/LibJS/Object.cpp b/Libraries/LibJS/Object.cpp index 2d4f021a9f..ae1d43397a 100644 --- a/Libraries/LibJS/Object.cpp +++ b/Libraries/LibJS/Object.cpp @@ -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); |