mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +00:00
LibJS: Very basic support for "new" construction in bytecode VM
This patch adds a CallType to the Bytecode::Op::Call instruction, which can be either Call or Construct. We then generate Construct calls for the NewExpression AST node. When executed, these get fed into VM::construct().
This commit is contained in:
parent
c3c68399b5
commit
f5feb1d2cd
3 changed files with 23 additions and 5 deletions
|
@ -199,14 +199,17 @@ void Call::execute(Bytecode::Interpreter& interpreter) const
|
|||
|
||||
Value return_value;
|
||||
|
||||
if (m_argument_count == 0) {
|
||||
if (m_argument_count == 0 && m_type == CallType::Call) {
|
||||
return_value = interpreter.vm().call(function, this_value);
|
||||
} else {
|
||||
MarkedValueList argument_values { interpreter.vm().heap() };
|
||||
for (size_t i = 0; i < m_argument_count; ++i) {
|
||||
argument_values.append(interpreter.reg(m_arguments[i]));
|
||||
}
|
||||
return_value = interpreter.vm().call(function, this_value, move(argument_values));
|
||||
if (m_type == CallType::Call)
|
||||
return_value = interpreter.vm().call(function, this_value, move(argument_values));
|
||||
else
|
||||
return_value = interpreter.vm().construct(function, function, move(argument_values), interpreter.global_object());
|
||||
}
|
||||
|
||||
interpreter.accumulator() = return_value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue