mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +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
|
@ -632,7 +632,15 @@ void CallExpression::generate_bytecode(Bytecode::Generator& generator) const
|
|||
generator.emit<Bytecode::Op::Store>(arg_reg);
|
||||
argument_registers.append(arg_reg);
|
||||
}
|
||||
generator.emit_with_extra_register_slots<Bytecode::Op::Call>(argument_registers.size(), callee_reg, this_reg, argument_registers);
|
||||
|
||||
Bytecode::Op::Call::CallType call_type;
|
||||
if (is<NewExpression>(*this)) {
|
||||
call_type = Bytecode::Op::Call::CallType::Construct;
|
||||
} else {
|
||||
call_type = Bytecode::Op::Call::CallType::Call;
|
||||
}
|
||||
|
||||
generator.emit_with_extra_register_slots<Bytecode::Op::Call>(argument_registers.size(), call_type, callee_reg, this_reg, argument_registers);
|
||||
}
|
||||
|
||||
void ReturnStatement::generate_bytecode(Bytecode::Generator& generator) const
|
||||
|
@ -813,7 +821,7 @@ void TaggedTemplateLiteral::generate_bytecode(Bytecode::Generator& generator) co
|
|||
auto this_reg = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::Store>(this_reg);
|
||||
|
||||
generator.emit_with_extra_register_slots<Bytecode::Op::Call>(argument_regs.size(), tag_reg, this_reg, move(argument_regs));
|
||||
generator.emit_with_extra_register_slots<Bytecode::Op::Call>(argument_regs.size(), Bytecode::Op::Call::CallType::Call, tag_reg, this_reg, move(argument_regs));
|
||||
}
|
||||
|
||||
void UpdateExpression::generate_bytecode(Bytecode::Generator& generator) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue