diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-04 20:30:23 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-07 18:11:59 +0200 |
commit | bea6e31ddcc85936eb920fc2ec0326b5e06ff65b (patch) | |
tree | dffe7b15306318c37d26a9e58627cd8d26c71d7e /Userland/Libraries | |
parent | f2863b5a89abaa5b4569b23ea4e314aa93cee95e (diff) | |
download | serenity-bea6e31ddcc85936eb920fc2ec0326b5e06ff65b.zip |
LibJS: Add a NewObject bytecode instruction for ObjectExpression :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.h | 15 |
4 files changed, 38 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 8a7c2cf1a9..b7a2d72e1e 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -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; diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index b515870349..d009fdce40 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -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; +} + } diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 51eba805ce..bff5b53347 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -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); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 7b3c38bc17..a7fe80d306 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -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) |