LibJS: Pass "this" as an Object* to NativeFunction callbacks

Instead of every NativeFunction callback having to ask the Interpreter
for the current "this" value and then converting it to an Object etc,
just pass "this" as an Object* directly.
This commit is contained in:
Andreas Kling 2020-03-15 20:51:36 +01:00
parent 3163929990
commit 63b3cfdc73
Notes: sideshowbarker 2024-07-19 08:17:26 +09:00
9 changed files with 28 additions and 26 deletions

View file

@ -30,7 +30,7 @@
namespace JS {
NativeFunction::NativeFunction(AK::Function<Value(Interpreter&, Vector<Value>)> native_function)
NativeFunction::NativeFunction(AK::Function<Value(Object*, Vector<Value>)> native_function)
: m_native_function(move(native_function))
{
}
@ -41,7 +41,9 @@ NativeFunction::~NativeFunction()
Value NativeFunction::call(Interpreter& interpreter, Vector<Value> arguments)
{
return m_native_function(interpreter, move(arguments));
auto this_value = interpreter.this_value();
ASSERT(this_value.is_object());
return m_native_function(this_value.as_object(), move(arguments));
}
}