1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 01:08:11 +00:00

LibJS: Add a NewObject bytecode instruction for ObjectExpression :^)

This commit is contained in:
Andreas Kling 2021-06-04 20:30:23 +02:00
parent f2863b5a89
commit bea6e31ddc
4 changed files with 38 additions and 0 deletions

View file

@ -1040,6 +1040,7 @@ public:
virtual Value execute(Interpreter&, GlobalObject&) const override;
virtual void dump(int indent) const override;
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
private:
NonnullRefPtrVector<ObjectProperty> m_properties;

View file

@ -115,4 +115,16 @@ Optional<Bytecode::Register> DoWhileStatement::generate_bytecode(Bytecode::Gener
return body_result_reg;
}
Optional<Bytecode::Register> ObjectExpression::generate_bytecode(Bytecode::Generator& generator) const
{
auto reg = generator.allocate_register();
generator.emit<Bytecode::Op::NewObject>(reg);
if (!m_properties.is_empty()) {
TODO();
}
return reg;
}
}

View file

@ -41,6 +41,11 @@ void NewString::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = js_string(interpreter.vm(), m_string);
}
void NewObject::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Object::create_empty(interpreter.global_object());
}
void GetVariable::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = interpreter.vm().get_variable(m_identifier, interpreter.global_object());
@ -102,6 +107,11 @@ String NewString::to_string() const
return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string);
}
String NewObject::to_string() const
{
return String::formatted("NewObject dst:{}", m_dst);
}
String GetVariable::to_string() const
{
return String::formatted("GetVariable dst:{}, identifier:{}", m_dst, m_identifier);

View file

@ -125,6 +125,21 @@ private:
String m_string;
};
class NewObject final : public Instruction {
public:
explicit NewObject(Register dst)
: m_dst(dst)
{
}
virtual ~NewObject() override { }
virtual void execute(Bytecode::Interpreter&) const override;
virtual String to_string() const override;
private:
Register m_dst;
};
class SetVariable final : public Instruction {
public:
SetVariable(FlyString identifier, Register src)