summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/NativeFunction.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-28 22:48:35 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-28 22:51:09 +0100
commit7c4e53f31e23223e67bcb04156ed8b12b515b1b5 (patch)
treea11de166c7587e4488c46f8f64680cd04fb8720d /Libraries/LibJS/Runtime/NativeFunction.cpp
parentc209ea1985087ac135cbbd40635de13d5cf701c6 (diff)
downloadserenity-7c4e53f31e23223e67bcb04156ed8b12b515b1b5.zip
LibJS: Rework how native functions are called to improve |this| value
Native functions now only get the Interpreter& as an argument. They can then extract |this| along with any indexed arguments it wants from it. This forces functions that want |this| to actually deal with calling interpreter.this_value().to_object(), and dealing with the possibility of a non-object |this|. This is still not great but let's keep massaging it forward.
Diffstat (limited to 'Libraries/LibJS/Runtime/NativeFunction.cpp')
-rw-r--r--Libraries/LibJS/Runtime/NativeFunction.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/Libraries/LibJS/Runtime/NativeFunction.cpp b/Libraries/LibJS/Runtime/NativeFunction.cpp
index 7f02afd6ac..9383409bda 100644
--- a/Libraries/LibJS/Runtime/NativeFunction.cpp
+++ b/Libraries/LibJS/Runtime/NativeFunction.cpp
@@ -30,7 +30,7 @@
namespace JS {
-NativeFunction::NativeFunction(AK::Function<Value(Object*, const Vector<Value>&)> native_function)
+NativeFunction::NativeFunction(AK::Function<Value(Interpreter&)> native_function)
: m_native_function(move(native_function))
{
}
@@ -39,14 +39,9 @@ NativeFunction::~NativeFunction()
{
}
-Value NativeFunction::call(Interpreter& interpreter, const Vector<Value>& arguments)
+Value NativeFunction::call(Interpreter& interpreter)
{
- auto this_value = interpreter.this_value();
- // FIXME: Why are we here with a non-object 'this'?
- Object* this_object = nullptr;
- if (this_value.is_object())
- this_object = this_value.as_object();
- return m_native_function(this_object, arguments);
+ return m_native_function(interpreter);
}
}