1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:55:08 +00:00

LibJS: Add basic prototype support

Object will now traverse up the prototype chain when doing a get().
When a function is called on an object, that object will now also be
the "this" value inside the function. This stuff is probably not very
correct, but we will improve things as we go! :^)
This commit is contained in:
Andreas Kling 2020-03-15 15:01:10 +01:00
parent d02c37f3e3
commit f7c15d00c9
5 changed files with 42 additions and 2 deletions

View file

@ -63,7 +63,18 @@ Value CallExpression::execute(Interpreter& interpreter) const
for (size_t i = 0; i < m_arguments.size(); ++i)
argument_values.append(m_arguments[i].execute(interpreter));
return function->call(interpreter, move(argument_values));
Value this_value = js_undefined();
if (m_callee->is_member_expression())
this_value = static_cast<const MemberExpression&>(*m_callee).object().execute(interpreter).to_object(interpreter.heap());
if (!this_value.is_undefined())
interpreter.push_this_value(this_value);
auto result = function->call(interpreter, move(argument_values));
if (!this_value.is_undefined())
interpreter.pop_this_value();
return result;
}
Value ReturnStatement::execute(Interpreter& interpreter) const