summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Function.cpp
diff options
context:
space:
mode:
authorJack Karamanian <karamanian.jack@gmail.com>2020-04-19 14:42:00 -0500
committerAndreas Kling <kling@serenityos.org>2020-04-21 12:23:07 +0200
commit5750edd859a375a7a8e8f1e5d1131b3d92502fcc (patch)
tree098abe1e343c78ae594a031004f920f23bc0cd75 /Libraries/LibJS/Runtime/Function.cpp
parent6a66207efa32f807a62bf387dccdee6b10ff1d2a (diff)
downloadserenity-5750edd859a375a7a8e8f1e5d1131b3d92502fcc.zip
LibJS: Allow Function objects to be constructed with a bound |this|
value and bound arguments This allows Function objects produced by Function.prototype.bind, as well as arrow functions to track their |this| values and bound arguments.
Diffstat (limited to 'Libraries/LibJS/Runtime/Function.cpp')
-rw-r--r--Libraries/LibJS/Runtime/Function.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/Function.cpp b/Libraries/LibJS/Runtime/Function.cpp
index 18f3018e18..d5f5e813b9 100644
--- a/Libraries/LibJS/Runtime/Function.cpp
+++ b/Libraries/LibJS/Runtime/Function.cpp
@@ -30,8 +30,28 @@
namespace JS {
Function::Function(Object& prototype)
+ : Function(prototype, {}, {})
+{
+}
+
+Function::Function(Object& prototype, Optional<Value> bound_this, Vector<Value> bound_arguments)
: Object(&prototype)
+ , m_bound_this(bound_this)
+ , m_bound_arguments(move(bound_arguments))
+{
+}
+
+void Function::visit_children(Visitor& visitor)
{
+ Object::visit_children(visitor);
+
+ if (m_bound_this.has_value()) {
+ visitor.visit(m_bound_this.value());
+ }
+
+ for (auto argument : m_bound_arguments) {
+ visitor.visit(argument);
+ }
}
Function::~Function()