浏览代码

LibJS: Allow SpreadExpressions to generate bytecode

Hendiadyoin1 2 年之前
父节点
当前提交
ab763a56f6
共有 2 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      Userland/Libraries/LibJS/AST.h
  2. 7 0
      Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

+ 1 - 0
Userland/Libraries/LibJS/AST.h

@@ -1436,6 +1436,7 @@ public:
 
     virtual Completion execute(Interpreter&) const override;
     virtual void dump(int indent) const override;
+    virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override;
 
 private:
     NonnullRefPtr<Expression> m_target;

+ 7 - 0
Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

@@ -1959,6 +1959,13 @@ Bytecode::CodeGenerationErrorOr<void> ClassExpression::generate_bytecode(Bytecod
     return {};
 }
 
+Bytecode::CodeGenerationErrorOr<void> SpreadExpression::generate_bytecode(Bytecode::Generator& generator) const
+{
+    // NOTE: All users of this should handle the behaviour of this on their own,
+    //       assuming it returns an Array-like object
+    return m_target->generate_bytecode(generator);
+}
+
 Bytecode::CodeGenerationErrorOr<void> ThisExpression::generate_bytecode(Bytecode::Generator& generator) const
 {
     generator.emit<Bytecode::Op::ResolveThisBinding>();