mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 11:20:03 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user