1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +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:
Andreas Kling 2021-06-10 23:01:49 +02:00
parent c3c68399b5
commit f5feb1d2cd
3 changed files with 23 additions and 5 deletions

View file

@ -325,10 +325,16 @@ public:
// NOTE: This instruction is variable-width depending on the number of arguments!
class Call final : public Instruction {
public:
Call(Register callee, Register this_value, Vector<Register> const& arguments)
enum class CallType {
Call,
Construct,
};
Call(CallType type, Register callee, Register this_value, Vector<Register> const& arguments)
: Instruction(Type::Call)
, m_callee(callee)
, m_this_value(this_value)
, m_type(type)
, m_argument_count(arguments.size())
{
for (size_t i = 0; i < m_argument_count; ++i)
@ -343,6 +349,7 @@ public:
private:
Register m_callee;
Register m_this_value;
CallType m_type;
size_t m_argument_count { 0 };
Register m_arguments[];
};