diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index df33c27149..fb96958992 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, Andreas Kling + * Copyright (c) 2020-2024, Andreas Kling * Copyright (c) 2020-2022, Linus Groh * Copyright (c) 2021-2022, David Tuin * @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,7 @@ public: // NOTE: This is here to stop ASAN complaining about mismatch between new/delete sizes in ASTNodeWithTailArray. void operator delete(void* ptr) { ::operator delete(ptr); } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const; virtual void dump(int indent) const; [[nodiscard]] SourceRange source_range() const; @@ -173,8 +174,8 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const; DeprecatedFlyString const& label() const { return m_label; } DeprecatedFlyString& label() { return m_label; } @@ -202,7 +203,7 @@ class IterationStatement : public Statement { public: using Statement::Statement; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const; private: virtual bool is_iteration_statement() const final { return true; } @@ -214,7 +215,7 @@ public: : Statement(move(source_range)) { } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; }; class ErrorStatement final : public Statement { @@ -234,7 +235,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; Expression const& expression() const { return m_expression; } @@ -297,7 +298,7 @@ public: Vector> const& children() const { return m_children; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; void add_var_scoped_declaration(NonnullRefPtr variables); void add_lexical_declaration(NonnullRefPtr variables); @@ -385,7 +386,7 @@ public: virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; bool has_bound_name(DeprecatedFlyString const& name) const; Vector const& entries() const { return m_entries; } @@ -482,7 +483,7 @@ public: virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; bool has_export(DeprecatedFlyString const& export_name) const; @@ -670,7 +671,7 @@ public: void set_is_global() { m_is_global = true; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: virtual bool is_identifier() const override { return true; } @@ -752,7 +753,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override; @@ -778,8 +779,8 @@ public: virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode_with_lhs_name(Bytecode::Generator&, Optional lhs_name) const; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode_with_lhs_name(Bytecode::Generator&, Optional lhs_name, Optional preferred_dst = {}) const; bool has_name() const { return !name().is_empty(); } @@ -810,7 +811,7 @@ public: bool is_yield_from() const { return m_is_yield_from; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: RefPtr m_argument; @@ -826,7 +827,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_argument; @@ -843,7 +844,7 @@ public: Expression const* argument() const { return m_argument; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: RefPtr m_argument; @@ -864,7 +865,7 @@ public: Statement const* alternate() const { return m_alternate; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_predicate; @@ -885,8 +886,8 @@ public: Statement const& body() const { return *m_body; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_test; @@ -906,8 +907,8 @@ public: Statement const& body() const { return *m_body; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_test; @@ -927,7 +928,7 @@ public: Statement const& body() const { return *m_body; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_object; @@ -951,8 +952,8 @@ public: Statement const& body() const { return *m_body; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const override; private: RefPtr m_init; @@ -975,8 +976,8 @@ public: Expression const& rhs() const { return *m_rhs; } Statement const& body() const { return *m_body; } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const override; virtual void dump(int indent) const override; private: @@ -999,8 +1000,8 @@ public: Expression const& rhs() const { return *m_rhs; } Statement const& body() const { return *m_body; } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const override; virtual void dump(int indent) const override; private: @@ -1019,8 +1020,8 @@ public: { } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const override; virtual void dump(int indent) const override; private: @@ -1065,7 +1066,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: BinaryOp m_op; @@ -1090,7 +1091,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: LogicalOp m_op; @@ -1118,7 +1119,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: UnaryOp m_op; @@ -1135,7 +1136,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: Vector> m_expressions; @@ -1161,7 +1162,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; virtual Value value() const override { return Value(m_value); } @@ -1178,7 +1179,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; virtual Value value() const override { return m_value; } @@ -1195,7 +1196,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: ByteString m_value; @@ -1210,7 +1211,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; StringView value() const { return m_value; } @@ -1228,7 +1229,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; virtual Value value() const override { return js_null(); } }; @@ -1246,7 +1247,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; regex::Parser::Result const& parsed_regex() const { return m_parsed_regex; } ByteString const& parsed_pattern() const { return m_parsed_pattern; } @@ -1391,7 +1392,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; virtual bool is_super_expression() const override { return true; } }; @@ -1414,8 +1415,8 @@ public: RefPtr constructor() const { return m_constructor; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode_with_lhs_name(Bytecode::Generator&, Optional lhs_name) const; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode_with_lhs_name(Bytecode::Generator&, Optional lhs_name, Optional preferred_dst = {}) const; bool has_name() const { return m_name; } @@ -1443,7 +1444,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override; @@ -1471,7 +1472,7 @@ public: } virtual void dump(int) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_expression; @@ -1487,7 +1488,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_target; @@ -1500,7 +1501,7 @@ public: { } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; }; struct CallExpressionArgument { @@ -1530,7 +1531,7 @@ public: static NonnullRefPtr create(SourceRange, NonnullRefPtr callee, ReadonlySpan arguments, InvocationStyleEnum invocation_style, InsideParenthesesEnum inside_parens); virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; Expression const& callee() const { return m_callee; } @@ -1598,7 +1599,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: Vector const m_arguments; @@ -1643,7 +1644,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: AssignmentOp m_op; @@ -1667,7 +1668,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: virtual bool is_update_expression() const override { return true; } @@ -1727,7 +1728,7 @@ public: DeclarationKind declaration_kind() const { return m_declaration_kind; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; Vector> const& declarations() const { return m_declarations; } @@ -1813,7 +1814,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: virtual bool is_object_expression() const override { return true; } @@ -1832,7 +1833,7 @@ public: Vector> const& elements() const { return m_elements; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: virtual bool is_array_expression() const override { return true; } @@ -1856,7 +1857,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; Vector> const& expressions() const { return m_expressions; } Vector> const& raw_strings() const { return m_raw_strings; } @@ -1876,7 +1877,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr const m_tag; @@ -1894,7 +1895,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; bool is_computed() const { return m_computed; } Expression const& object() const { return *m_object; } @@ -1946,7 +1947,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; Expression const& base() const { return *m_base; } Vector const& references() const { return m_references; } @@ -1970,7 +1971,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: Type m_type; @@ -1986,7 +1987,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: virtual bool is_import_call() const override { return true; } @@ -2006,7 +2007,7 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_test; @@ -2055,7 +2056,7 @@ public: BlockStatement const* finalizer() const { return m_finalizer; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_block; @@ -2074,7 +2075,7 @@ public: Expression const& argument() const { return m_argument; } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: NonnullRefPtr m_argument; @@ -2105,8 +2106,8 @@ public: } virtual void dump(int indent) const override; - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual Bytecode::CodeGenerationErrorOr generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_labelled_evaluation(Bytecode::Generator&, Vector const&, Optional preferred_dst = {}) const; void add_case(NonnullRefPtr switch_case) { m_cases.append(move(switch_case)); } @@ -2124,7 +2125,7 @@ public: } DeprecatedFlyString const& target_label() const { return m_target_label; } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; private: DeprecatedFlyString m_target_label; @@ -2138,7 +2139,7 @@ public: { } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; DeprecatedFlyString const& target_label() const { return m_target_label; } @@ -2153,7 +2154,7 @@ public: { } - virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; + virtual Bytecode::CodeGenerationErrorOr> generate_bytecode(Bytecode::Generator&, Optional preferred_dst = {}) const override; }; class SyntheticReferenceExpression final : public Expression { diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index db4b5da00c..17acb46770 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, Andreas Kling + * Copyright (c) 2021-2024, Andreas Kling * Copyright (c) 2021, Linus Groh * Copyright (c) 2021, Gunnar Beutner * Copyright (c) 2021, Marcin Gasperowicz @@ -7,6 +7,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#define FIXME_NEWBC (void) + #include #include #include @@ -19,7 +21,7 @@ namespace JS { -Bytecode::CodeGenerationErrorOr ASTNode::generate_bytecode(Bytecode::Generator&) const +Bytecode::CodeGenerationErrorOr> ASTNode::generate_bytecode(Bytecode::Generator&, [[maybe_unused]] Optional preferred_dst) const { return Bytecode::CodeGenerationError { this, @@ -27,7 +29,7 @@ Bytecode::CodeGenerationErrorOr ASTNode::generate_bytecode(Bytecode::Gener }; } -Bytecode::CodeGenerationErrorOr ScopeNode::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ScopeNode::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); bool did_create_lexical_environment = false; @@ -44,7 +46,7 @@ Bytecode::CodeGenerationErrorOr ScopeNode::generate_bytecode(Bytecode::Gen } for (auto& child : children()) { - TRY(child->generate_bytecode(generator)); + FIXME_NEWBC TRY(child->generate_bytecode(generator)); if (generator.is_current_block_terminated()) break; } @@ -52,35 +54,35 @@ Bytecode::CodeGenerationErrorOr ScopeNode::generate_bytecode(Bytecode::Gen if (did_create_lexical_environment) generator.end_variable_scope(); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr EmptyStatement::generate_bytecode(Bytecode::Generator&) const +Bytecode::CodeGenerationErrorOr> EmptyStatement::generate_bytecode(Bytecode::Generator&, [[maybe_unused]] Optional preferred_dst) const { - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ExpressionStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ExpressionStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return m_expression->generate_bytecode(generator); } -Bytecode::CodeGenerationErrorOr BinaryExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> BinaryExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (m_op == BinaryOp::In && is(*m_lhs)) { auto const& private_identifier = static_cast(*m_lhs).string(); - TRY(m_rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_rhs->generate_bytecode(generator)); generator.emit(generator.intern_identifier(private_identifier)); - return {}; + return Optional {}; } - TRY(m_lhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_lhs->generate_bytecode(generator)); auto lhs_reg = generator.allocate_register(); generator.emit(lhs_reg); - TRY(m_rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_rhs->generate_bytecode(generator)); switch (m_op) { case BinaryOp::Addition: @@ -152,13 +154,13 @@ Bytecode::CodeGenerationErrorOr BinaryExpression::generate_bytecode(Byteco default: VERIFY_NOT_REACHED(); } - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr LogicalExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> LogicalExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); - TRY(m_lhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_lhs->generate_bytecode(generator)); // lhs // jump op (true) end (false) rhs @@ -190,14 +192,14 @@ Bytecode::CodeGenerationErrorOr LogicalExpression::generate_bytecode(Bytec } generator.switch_to_basic_block(rhs_block); - TRY(m_rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_rhs->generate_bytecode(generator)); generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(end_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr UnaryExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> UnaryExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (m_op == UnaryOp::Delete) @@ -205,7 +207,7 @@ Bytecode::CodeGenerationErrorOr UnaryExpression::generate_bytecode(Bytecod // Typeof needs some special handling for when the LHS is an Identifier. Namely, it shouldn't throw on unresolvable references, but instead return "undefined". if (m_op != UnaryOp::Typeof) - TRY(m_lhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_lhs->generate_bytecode(generator)); switch (m_op) { case UnaryOp::BitwiseNot: @@ -231,7 +233,7 @@ Bytecode::CodeGenerationErrorOr UnaryExpression::generate_bytecode(Bytecod break; } - TRY(m_lhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_lhs->generate_bytecode(generator)); generator.emit(); break; case UnaryOp::Void: @@ -242,31 +244,31 @@ Bytecode::CodeGenerationErrorOr UnaryExpression::generate_bytecode(Bytecod VERIFY_NOT_REACHED(); } - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr NumericLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> NumericLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); generator.emit(m_value); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr BooleanLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> BooleanLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); generator.emit(Value(m_value)); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr NullLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> NullLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); generator.emit(js_null()); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr BigIntLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> BigIntLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // 1. Return the NumericValue of NumericLiteral as defined in 12.8.3. @@ -282,17 +284,17 @@ Bytecode::CodeGenerationErrorOr BigIntLiteral::generate_bytecode(Bytecode: }(); generator.emit(integer); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr StringLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> StringLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); generator.emit(generator.intern_string(m_value)); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr RegExpLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> RegExpLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto source_index = generator.intern_string(m_pattern); @@ -303,10 +305,10 @@ Bytecode::CodeGenerationErrorOr RegExpLiteral::generate_bytecode(Bytecode: .flags = m_parsed_flags, }); generator.emit(source_index, flags_index, regex_index); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr Identifier::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> Identifier::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (is_global()) { @@ -316,15 +318,15 @@ Bytecode::CodeGenerationErrorOr Identifier::generate_bytecode(Bytecode::Ge } else { generator.emit(generator.intern_identifier(m_string), generator.next_environment_variable_cache()); } - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr arguments_to_array_for_call(Bytecode::Generator& generator, ReadonlySpan arguments) +static Bytecode::CodeGenerationErrorOr> arguments_to_array_for_call(Bytecode::Generator& generator, ReadonlySpan arguments, [[maybe_unused]] Optional preferred_dst = {}) { if (arguments.is_empty()) { generator.emit(); - return {}; + return Optional {}; } auto first_spread = find_if(arguments.begin(), arguments.end(), [](auto el) { return el.is_spread; }); @@ -339,7 +341,7 @@ static Bytecode::CodeGenerationErrorOr arguments_to_array_for_call(Bytecod for (auto it = arguments.begin(); it != first_spread; ++it, ++i) { VERIFY(it->is_spread == false); Bytecode::Register reg { args_start_reg.index() + i }; - TRY(it->value->generate_bytecode(generator)); + FIXME_NEWBC TRY(it->value->generate_bytecode(generator)); generator.emit(reg); } @@ -352,16 +354,16 @@ static Bytecode::CodeGenerationErrorOr arguments_to_array_for_call(Bytecod auto array_reg = generator.allocate_register(); generator.emit(array_reg); for (auto it = first_spread; it != arguments.end(); ++it) { - TRY(it->value->generate_bytecode(generator)); + FIXME_NEWBC TRY(it->value->generate_bytecode(generator)); generator.emit(array_reg, it->is_spread); } generator.emit(array_reg); } - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr SuperCall::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> SuperCall::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (m_is_synthetic == IsPartOfSyntheticConstructor::Yes) { @@ -371,26 +373,26 @@ Bytecode::CodeGenerationErrorOr SuperCall::generate_bytecode(Bytecode::Gen VERIFY(m_arguments[0].is_spread); auto const& argument = m_arguments[0]; // This generates a single argument, which will be implicitly passed in accumulator - MUST(argument.value->generate_bytecode(generator)); + FIXME_NEWBC MUST(argument.value->generate_bytecode(generator)); } else { - TRY(arguments_to_array_for_call(generator, m_arguments)); + FIXME_NEWBC TRY(arguments_to_array_for_call(generator, m_arguments)); } generator.emit(m_is_synthetic == IsPartOfSyntheticConstructor::Yes); - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode, Bytecode::Register const& value_reg, bool create_variables); +static Bytecode::CodeGenerationErrorOr> generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode, Bytecode::Register const& value_reg, bool create_variables, [[maybe_unused]] Optional preferred_dst = {}); -Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> AssignmentExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (m_op == AssignmentOp::Assignment) { // AssignmentExpression : LeftHandSideExpression = AssignmentExpression return m_lhs.visit( // 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then - [&](NonnullRefPtr const& lhs) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& lhs) -> Bytecode::CodeGenerationErrorOr> { // a. Let lref be the result of evaluating LeftHandSideExpression. // b. ReturnIfAbrupt(lref). Optional base_object_register; @@ -405,7 +407,7 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By base_object_register = generator.allocate_register(); if (!lhs_is_super_expression) { - TRY(expression.object().generate_bytecode(generator)); + FIXME_NEWBC TRY(expression.object().generate_bytecode(generator)); generator.emit(*base_object_register); } else { // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation @@ -421,7 +423,7 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By } if (expression.is_computed()) { - TRY(expression.property().generate_bytecode(generator)); + FIXME_NEWBC TRY(expression.property().generate_bytecode(generator)); computed_property_register = generator.allocate_register(); generator.emit(*computed_property_register); @@ -452,7 +454,7 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By // NOTE: For Identifiers, we cannot perform GetVariable and then write into the reference it retrieves, only SetVariable can do this. // FIXME: However, this breaks spec as we are doing variable lookup after evaluating the RHS. This is observable in an object environment, where we visibly perform HasOwnProperty and Get(@@unscopables) on the binded object. } else { - TRY(lhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(lhs->generate_bytecode(generator)); } // FIXME: c. If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then @@ -464,7 +466,7 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By if (lhs->is_identifier()) { TRY(generator.emit_named_evaluation_if_anonymous_function(*m_rhs, generator.intern_identifier(static_cast(*lhs).string()))); } else { - TRY(m_rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_rhs->generate_bytecode(generator)); } // e. Perform ? PutValue(lref, rval). @@ -503,22 +505,22 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By // f. Return rval. // NOTE: This is already in the accumulator. - return {}; + return Optional {}; }, // 2. Let assignmentPattern be the AssignmentPattern that is covered by LeftHandSideExpression. - [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr> { // 3. Let rref be the result of evaluating AssignmentExpression. // 4. Let rval be ? GetValue(rref). - TRY(m_rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_rhs->generate_bytecode(generator)); auto value_register = generator.allocate_register(); generator.emit(value_register); // 5. Perform ? DestructuringAssignmentEvaluation of assignmentPattern with argument rval. - TRY(generate_binding_pattern_bytecode(generator, pattern, Bytecode::Op::SetVariable::InitializationMode::Set, value_register, false)); + FIXME_NEWBC TRY(generate_binding_pattern_bytecode(generator, pattern, Bytecode::Op::SetVariable::InitializationMode::Set, value_register, false)); // 6. Return rval. generator.emit(value_register); - return {}; + return Optional {}; }); } @@ -565,7 +567,7 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By if (lhs->is_identifier()) TRY(generator.emit_named_evaluation_if_anonymous_function(*m_rhs, generator.intern_identifier(static_cast(*lhs).string()))); else - TRY(m_rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_rhs->generate_bytecode(generator)); switch (m_op) { case AssignmentOp::AdditionAssignment: @@ -616,21 +618,21 @@ Bytecode::CodeGenerationErrorOr AssignmentExpression::generate_bytecode(By } if (reference_registers.has_value()) - TRY(generator.emit_store_to_reference(*reference_registers)); + FIXME_NEWBC TRY(generator.emit_store_to_reference(*reference_registers)); else - TRY(generator.emit_store_to_reference(lhs)); + FIXME_NEWBC TRY(generator.emit_store_to_reference(lhs)); if (end_block_ptr) { generator.emit(Bytecode::Label { *end_block_ptr }); generator.switch_to_basic_block(*end_block_ptr); } - return {}; + return Optional {}; } // 14.13.3 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-labelled-statements-runtime-semantics-evaluation // LabelledStatement : LabelIdentifier : LabelledItem -Bytecode::CodeGenerationErrorOr LabelledStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> LabelledStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // Return ? LabelledEvaluation of this LabelledStatement with argument « ». @@ -639,7 +641,7 @@ Bytecode::CodeGenerationErrorOr LabelledStatement::generate_bytecode(Bytec // 14.13.4 Runtime Semantics: LabelledEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-labelledevaluation // LabelledStatement : LabelIdentifier : LabelledItem -Bytecode::CodeGenerationErrorOr LabelledStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> LabelledStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // Convert the m_labelled_item NNRP to a reference early so we don't have to do it every single time we want to use it. @@ -657,19 +659,19 @@ Bytecode::CodeGenerationErrorOr LabelledStatement::generate_labelled_evalu // NOTE: stmtResult will be in the accumulator after running the generated bytecode. if (is(labelled_item)) { auto const& iteration_statement = static_cast(labelled_item); - TRY(iteration_statement.generate_labelled_evaluation(generator, new_label_set)); + FIXME_NEWBC TRY(iteration_statement.generate_labelled_evaluation(generator, new_label_set)); } else if (is(labelled_item)) { auto const& switch_statement = static_cast(labelled_item); - TRY(switch_statement.generate_labelled_evaluation(generator, new_label_set)); + FIXME_NEWBC TRY(switch_statement.generate_labelled_evaluation(generator, new_label_set)); } else if (is(labelled_item)) { auto const& labelled_statement = static_cast(labelled_item); - TRY(labelled_statement.generate_labelled_evaluation(generator, new_label_set)); + FIXME_NEWBC TRY(labelled_statement.generate_labelled_evaluation(generator, new_label_set)); } else { auto& labelled_break_block = generator.make_block(); // NOTE: We do not need a continuable scope as `continue;` is not allowed outside of iteration statements, throwing a SyntaxError in the parser. generator.begin_breakable_scope(Bytecode::Label { labelled_break_block }, new_label_set); - TRY(labelled_item.generate_bytecode(generator)); + FIXME_NEWBC TRY(labelled_item.generate_bytecode(generator)); generator.end_breakable_scope(); if (!generator.is_current_block_terminated()) { @@ -685,10 +687,10 @@ Bytecode::CodeGenerationErrorOr LabelledStatement::generate_labelled_evalu // 5. Return Completion(stmtResult). // NOTE: This is in the accumulator. - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr IterationStatement::generate_labelled_evaluation(Bytecode::Generator&, Vector const&) const +Bytecode::CodeGenerationErrorOr> IterationStatement::generate_labelled_evaluation(Bytecode::Generator&, Vector const&, [[maybe_unused]] Optional preferred_dst) const { return Bytecode::CodeGenerationError { this, @@ -696,13 +698,13 @@ Bytecode::CodeGenerationErrorOr IterationStatement::generate_labelled_eval }; } -Bytecode::CodeGenerationErrorOr WhileStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> WhileStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } -Bytecode::CodeGenerationErrorOr WhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> WhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // test @@ -724,7 +726,7 @@ Bytecode::CodeGenerationErrorOr WhileStatement::generate_labelled_evaluati generator.switch_to_basic_block(test_block); generator.emit(result_reg); - TRY(m_test->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_test->generate_bytecode(generator)); generator.emit( Bytecode::Label { body_block }, Bytecode::Label { load_result_and_jump_to_end_block }); @@ -733,7 +735,7 @@ Bytecode::CodeGenerationErrorOr WhileStatement::generate_labelled_evaluati generator.begin_continuable_scope(Bytecode::Label { test_block }, label_set); generator.begin_breakable_scope(Bytecode::Label { end_block }, label_set); generator.emit(js_undefined()); - TRY(m_body->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_body->generate_bytecode(generator)); generator.end_breakable_scope(); generator.end_continuable_scope(); @@ -746,16 +748,16 @@ Bytecode::CodeGenerationErrorOr WhileStatement::generate_labelled_evaluati generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(end_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr DoWhileStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> DoWhileStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } -Bytecode::CodeGenerationErrorOr DoWhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> DoWhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // jump always (true) body @@ -779,7 +781,7 @@ Bytecode::CodeGenerationErrorOr DoWhileStatement::generate_labelled_evalua generator.switch_to_basic_block(test_block); generator.emit(result_reg); - TRY(m_test->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_test->generate_bytecode(generator)); generator.emit( Bytecode::Label { body_block }, Bytecode::Label { load_result_and_jump_to_end_block }); @@ -787,7 +789,7 @@ Bytecode::CodeGenerationErrorOr DoWhileStatement::generate_labelled_evalua generator.switch_to_basic_block(body_block); generator.begin_continuable_scope(Bytecode::Label { test_block }, label_set); generator.begin_breakable_scope(Bytecode::Label { end_block }, label_set); - TRY(m_body->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_body->generate_bytecode(generator)); generator.end_breakable_scope(); generator.end_continuable_scope(); @@ -800,16 +802,16 @@ Bytecode::CodeGenerationErrorOr DoWhileStatement::generate_labelled_evalua generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(end_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ForStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ForStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } -Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> ForStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // init @@ -861,7 +863,7 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation } } - TRY(m_init->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_init->generate_bytecode(generator)); } body_block_ptr = &generator.make_block(); @@ -891,7 +893,7 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation if (!m_update) generator.emit(result_reg); - TRY(m_test->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_test->generate_bytecode(generator)); generator.emit( Bytecode::Label { *body_block_ptr }, Bytecode::Label { *load_result_and_jump_to_end_block_ptr }); @@ -903,7 +905,7 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation if (m_test) generator.emit(result_reg); - TRY(m_update->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_update->generate_bytecode(generator)); generator.emit(Bytecode::Label { *test_block_ptr }); } @@ -911,7 +913,7 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation generator.begin_continuable_scope(Bytecode::Label { m_update ? *update_block_ptr : *test_block_ptr }, label_set); generator.begin_breakable_scope(Bytecode::Label { end_block }, label_set); generator.emit(js_undefined()); - TRY(m_body->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_body->generate_bytecode(generator)); generator.end_breakable_scope(); generator.end_continuable_scope(); @@ -934,15 +936,15 @@ Bytecode::CodeGenerationErrorOr ForStatement::generate_labelled_evaluation if (has_lexical_environment) generator.end_variable_scope(); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ObjectExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ObjectExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); generator.emit(); if (m_properties.is_empty()) - return {}; + return Optional {}; auto object_reg = generator.allocate_register(); generator.emit(object_reg); @@ -974,7 +976,7 @@ Bytecode::CodeGenerationErrorOr ObjectExpression::generate_bytecode(Byteco Bytecode::IdentifierTableIndex key_name = generator.intern_identifier(string_literal.value()); if (property_kind == Bytecode::Op::PropertyKind::ProtoSetter) { - TRY(property->value().generate_bytecode(generator)); + FIXME_NEWBC TRY(property->value().generate_bytecode(generator)); } else if (property_kind != Bytecode::Op::PropertyKind::Spread) { ByteString identifier = string_literal.value(); if (property_kind == Bytecode::Op::PropertyKind::Getter) @@ -987,12 +989,12 @@ Bytecode::CodeGenerationErrorOr ObjectExpression::generate_bytecode(Byteco generator.emit(object_reg, key_name, property_kind, generator.next_property_lookup_cache()); } else { - TRY(property->key().generate_bytecode(generator)); + FIXME_NEWBC TRY(property->key().generate_bytecode(generator)); auto property_reg = generator.allocate_register(); generator.emit(property_reg); if (property_kind != Bytecode::Op::PropertyKind::Spread) - TRY(property->value().generate_bytecode(generator)); + FIXME_NEWBC TRY(property->value().generate_bytecode(generator)); generator.emit(object_reg, property_reg, property_kind); } @@ -1001,15 +1003,15 @@ Bytecode::CodeGenerationErrorOr ObjectExpression::generate_bytecode(Byteco generator.emit(object_reg); generator.pop_home_object(); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ArrayExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ArrayExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (m_elements.is_empty()) { generator.emit(); - return {}; + return Optional {}; } if (all_of(m_elements, [](auto element) { return !element || is(*element); })) { @@ -1022,7 +1024,7 @@ Bytecode::CodeGenerationErrorOr ArrayExpression::generate_bytecode(Bytecod values[i] = static_cast(*m_elements[i]).value(); } generator.emit(move(values)); - return {}; + return Optional {}; } auto first_spread = find_if(m_elements.begin(), m_elements.end(), [](auto el) { return el && is(*el); }); @@ -1039,7 +1041,7 @@ Bytecode::CodeGenerationErrorOr ArrayExpression::generate_bytecode(Bytecod if (!*it) generator.emit(Value {}); else { - TRY((*it)->generate_bytecode(generator)); + FIXME_NEWBC TRY((*it)->generate_bytecode(generator)); } generator.emit(reg); } @@ -1057,24 +1059,24 @@ Bytecode::CodeGenerationErrorOr ArrayExpression::generate_bytecode(Bytecod generator.emit(Value {}); generator.emit(array_reg, false); } else { - TRY((*it)->generate_bytecode(generator)); + FIXME_NEWBC TRY((*it)->generate_bytecode(generator)); generator.emit(array_reg, *it && is(**it)); } } generator.emit(array_reg); } - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr MemberExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> MemberExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); (void)TRY(generator.emit_load_from_reference(*this, Bytecode::Generator::CollectRegisters::No)); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr FunctionDeclaration::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> FunctionDeclaration::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { if (m_is_hoisted) { Bytecode::Generator::SourceLocationScope scope(generator, *this); @@ -1082,10 +1084,10 @@ Bytecode::CodeGenerationErrorOr FunctionDeclaration::generate_bytecode(Byt generator.emit(index, generator.next_environment_variable_cache()); generator.emit(index, generator.next_environment_variable_cache(), Bytecode::Op::SetVariable::InitializationMode::Set, Bytecode::Op::EnvironmentMode::Var); } - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr FunctionExpression::generate_bytecode_with_lhs_name(Bytecode::Generator& generator, Optional lhs_name) const +Bytecode::CodeGenerationErrorOr> FunctionExpression::generate_bytecode_with_lhs_name(Bytecode::Generator& generator, Optional lhs_name, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); bool has_name = !name().is_empty(); @@ -1105,16 +1107,16 @@ Bytecode::CodeGenerationErrorOr FunctionExpression::generate_bytecode_with generator.end_variable_scope(); } - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr FunctionExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> FunctionExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_bytecode_with_lhs_name(generator, {}); } -static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables) +static Bytecode::CodeGenerationErrorOr> generate_object_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables, [[maybe_unused]] Optional preferred_dst = {}) { generator.emit(); @@ -1137,12 +1139,12 @@ static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_byt } generator.emit_set_variable(*identifier, initialization_mode); - return {}; + return Optional {}; } if (alias.has>()) { generator.emit_with_extra_register_slots(excluded_property_names.size(), value_reg, excluded_property_names); - TRY(generator.emit_store_to_reference(alias.get>())); - return {}; + FIXME_NEWBC TRY(generator.emit_store_to_reference(alias.get>())); + return Optional {}; } VERIFY_NOT_REACHED(); } @@ -1164,7 +1166,7 @@ static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_byt generator.emit_get_by_id(generator.intern_identifier(identifier)); } else { auto expression = name.get>(); - TRY(expression->generate_bytecode(generator)); + FIXME_NEWBC TRY(expression->generate_bytecode(generator)); if (has_rest) { auto excluded_name_reg = generator.allocate_register(); @@ -1189,7 +1191,7 @@ static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_byt } else if (auto const* lhs = name.get_pointer>()) { TRY(generator.emit_named_evaluation_if_anonymous_function(*initializer, generator.intern_identifier((*lhs)->string()))); } else { - TRY(initializer->generate_bytecode(generator)); + FIXME_NEWBC TRY(initializer->generate_bytecode(generator)); } generator.emit(Bytecode::Label { if_not_undefined_block }); @@ -1200,7 +1202,7 @@ static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_byt auto& binding_pattern = *alias.get>(); auto nested_value_reg = generator.allocate_register(); generator.emit(nested_value_reg); - TRY(generate_binding_pattern_bytecode(generator, binding_pattern, initialization_mode, nested_value_reg, create_variables)); + FIXME_NEWBC TRY(generate_binding_pattern_bytecode(generator, binding_pattern, initialization_mode, nested_value_reg, create_variables)); } else if (alias.has()) { if (name.has>()) { // This needs some sort of SetVariableByValue opcode, as it's a runtime binding @@ -1216,7 +1218,7 @@ static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_byt generator.emit(identifier_ref, Bytecode::Op::EnvironmentMode::Lexical, false); generator.emit_set_variable(identifier, initialization_mode); } else if (alias.has>()) { - TRY(generator.emit_store_to_reference(alias.get>())); + FIXME_NEWBC TRY(generator.emit_store_to_reference(alias.get>())); } else { auto const& identifier = *alias.get>(); auto identifier_ref = generator.intern_identifier(identifier.string()); @@ -1225,10 +1227,10 @@ static Bytecode::CodeGenerationErrorOr generate_object_binding_pattern_byt generator.emit_set_variable(identifier, initialization_mode); } } - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr generate_array_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables) +static Bytecode::CodeGenerationErrorOr> generate_array_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables, [[maybe_unused]] Optional preferred_dst = {}) { /* * Consider the following destructuring assignment: @@ -1265,24 +1267,24 @@ static Bytecode::CodeGenerationErrorOr generate_array_binding_pattern_byte auto assign_accumulator_to_alias = [&](auto& alias) { return alias.visit( - [&](Empty) -> Bytecode::CodeGenerationErrorOr { + [&](Empty) -> Bytecode::CodeGenerationErrorOr> { // This element is an elision - return {}; + return Optional {}; }, - [&](NonnullRefPtr const& identifier) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& identifier) -> Bytecode::CodeGenerationErrorOr> { auto interned_index = generator.intern_identifier(identifier->string()); if (create_variables) generator.emit(interned_index, Bytecode::Op::EnvironmentMode::Lexical, false); generator.emit_set_variable(*identifier, initialization_mode); - return {}; + return Optional {}; }, - [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr> { // Store the accumulator value in a permanent register auto target_reg = generator.allocate_register(); generator.emit(target_reg); return generate_binding_pattern_bytecode(generator, pattern, initialization_mode, target_reg, create_variables); }, - [&](NonnullRefPtr const& expr) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& expr) -> Bytecode::CodeGenerationErrorOr> { return generator.emit_store_to_reference(*expr); }); }; @@ -1388,14 +1390,14 @@ static Bytecode::CodeGenerationErrorOr generate_array_binding_pattern_byte } else if (auto const* name_identifier = name.get_pointer>()) { TRY(generator.emit_named_evaluation_if_anonymous_function(*initializer, generator.intern_identifier((*name_identifier)->string()))); } else { - TRY(initializer->generate_bytecode(generator)); + FIXME_NEWBC TRY(initializer->generate_bytecode(generator)); } generator.emit(Bytecode::Label { value_is_not_undefined_block }); generator.switch_to_basic_block(value_is_not_undefined_block); } - TRY(assign_accumulator_to_alias(alias)); + FIXME_NEWBC TRY(assign_accumulator_to_alias(alias)); first = false; } @@ -1414,10 +1416,10 @@ static Bytecode::CodeGenerationErrorOr generate_array_binding_pattern_byte generator.emit(Bytecode::Label { done_block }); generator.switch_to_basic_block(done_block); - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables) +static Bytecode::CodeGenerationErrorOr> generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Register const& value_reg, bool create_variables, [[maybe_unused]] Optional preferred_dst) { if (pattern.kind == BindingPattern::Kind::Object) return generate_object_binding_pattern_bytecode(generator, pattern, initialization_mode, value_reg, create_variables); @@ -1425,23 +1427,23 @@ static Bytecode::CodeGenerationErrorOr generate_binding_pattern_bytecode(B return generate_array_binding_pattern_bytecode(generator, pattern, initialization_mode, value_reg, create_variables); } -static Bytecode::CodeGenerationErrorOr assign_accumulator_to_variable_declarator(Bytecode::Generator& generator, VariableDeclarator const& declarator, VariableDeclaration const& declaration) +static Bytecode::CodeGenerationErrorOr> assign_accumulator_to_variable_declarator(Bytecode::Generator& generator, VariableDeclarator const& declarator, VariableDeclaration const& declaration, [[maybe_unused]] Optional preferred_dst = {}) { auto initialization_mode = declaration.is_lexical_declaration() ? Bytecode::Op::SetVariable::InitializationMode::Initialize : Bytecode::Op::SetVariable::InitializationMode::Set; return declarator.target().visit( - [&](NonnullRefPtr const& id) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& id) -> Bytecode::CodeGenerationErrorOr> { generator.emit_set_variable(*id, initialization_mode); - return {}; + return Optional {}; }, - [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& pattern) -> Bytecode::CodeGenerationErrorOr> { auto value_register = generator.allocate_register(); generator.emit(value_register); return generate_binding_pattern_bytecode(generator, pattern, initialization_mode, value_register, false); }); } -Bytecode::CodeGenerationErrorOr VariableDeclaration::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> VariableDeclaration::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // The completion value of a VariableDeclaration is empty, but there might already be a non-empty @@ -1454,20 +1456,20 @@ Bytecode::CodeGenerationErrorOr VariableDeclaration::generate_bytecode(Byt if (auto const* lhs = declarator->target().get_pointer>()) { TRY(generator.emit_named_evaluation_if_anonymous_function(*declarator->init(), generator.intern_identifier((*lhs)->string()))); } else { - TRY(declarator->init()->generate_bytecode(generator)); + FIXME_NEWBC TRY(declarator->init()->generate_bytecode(generator)); } - TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + FIXME_NEWBC TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); } else if (m_declaration_kind != DeclarationKind::Var) { generator.emit(js_undefined()); - TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + FIXME_NEWBC TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); } } generator.emit(saved_accumulator); - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr get_base_and_value_from_member_expression(Bytecode::Generator& generator, MemberExpression const& member_expression, Bytecode::Register this_reg) +static Bytecode::CodeGenerationErrorOr> get_base_and_value_from_member_expression(Bytecode::Generator& generator, MemberExpression const& member_expression, Bytecode::Register this_reg, [[maybe_unused]] Optional preferred_dst = {}) { // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation if (is(member_expression.object())) { @@ -1482,7 +1484,7 @@ static Bytecode::CodeGenerationErrorOr get_base_and_value_from_member_expr // SuperProperty : super [ Expression ] // 3. Let propertyNameReference be ? Evaluation of Expression. // 4. Let propertyNameValue be ? GetValue(propertyNameReference). - TRY(member_expression.property().generate_bytecode(generator)); + FIXME_NEWBC TRY(member_expression.property().generate_bytecode(generator)); computed_property_value_register = generator.allocate_register(); generator.emit(*computed_property_value_register); } @@ -1509,10 +1511,10 @@ static Bytecode::CodeGenerationErrorOr get_base_and_value_from_member_expr generator.emit_get_by_id_with_this(identifier_table_ref, this_reg); } } else { - TRY(member_expression.object().generate_bytecode(generator)); + FIXME_NEWBC TRY(member_expression.object().generate_bytecode(generator)); generator.emit(this_reg); if (member_expression.is_computed()) { - TRY(member_expression.property().generate_bytecode(generator)); + FIXME_NEWBC TRY(member_expression.property().generate_bytecode(generator)); generator.emit(this_reg); } else if (is(member_expression.property())) { generator.emit(generator.intern_identifier(verify_cast(member_expression.property()).string())); @@ -1521,12 +1523,12 @@ static Bytecode::CodeGenerationErrorOr get_base_and_value_from_member_expr } } - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr generate_optional_chain(Bytecode::Generator& generator, OptionalChain const& optional_chain, Bytecode::Register current_value_register, Bytecode::Register current_base_register); +static Bytecode::CodeGenerationErrorOr> generate_optional_chain(Bytecode::Generator& generator, OptionalChain const& optional_chain, Bytecode::Register current_value_register, Bytecode::Register current_base_register, [[maybe_unused]] Optional preferred_dst = {}); -Bytecode::CodeGenerationErrorOr CallExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> CallExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto callee_reg = generator.allocate_register(); @@ -1537,16 +1539,16 @@ Bytecode::CodeGenerationErrorOr CallExpression::generate_bytecode(Bytecode Optional builtin; if (is(this)) { - TRY(m_callee->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_callee->generate_bytecode(generator)); generator.emit(callee_reg); } else if (is(*m_callee)) { auto& member_expression = static_cast(*m_callee); - TRY(get_base_and_value_from_member_expression(generator, member_expression, this_reg)); + FIXME_NEWBC TRY(get_base_and_value_from_member_expression(generator, member_expression, this_reg)); generator.emit(callee_reg); builtin = Bytecode::get_builtin(member_expression); } else if (is(*m_callee)) { auto& optional_chain = static_cast(*m_callee); - TRY(generate_optional_chain(generator, optional_chain, callee_reg, this_reg)); + FIXME_NEWBC TRY(generate_optional_chain(generator, optional_chain, callee_reg, this_reg)); } else if (is(*m_callee)) { // If the callee is an identifier, we may need to extract a `this` value. // This is important when we're inside a `with` statement and calling a method on @@ -1557,12 +1559,12 @@ Bytecode::CodeGenerationErrorOr CallExpression::generate_bytecode(Bytecode if (!identifier.is_local() && !identifier.is_global()) { generator.emit(generator.intern_identifier(identifier.string()), callee_reg, this_reg, generator.next_environment_variable_cache()); } else { - TRY(m_callee->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_callee->generate_bytecode(generator)); generator.emit(callee_reg); } } else { // FIXME: this = global object in sloppy mode. - TRY(m_callee->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_callee->generate_bytecode(generator)); generator.emit(callee_reg); } @@ -1582,7 +1584,7 @@ Bytecode::CodeGenerationErrorOr CallExpression::generate_bytecode(Bytecode bool has_spread = any_of(arguments(), [](auto& argument) { return argument.is_spread; }); if (has_spread) { - TRY(arguments_to_array_for_call(generator, arguments())); + FIXME_NEWBC TRY(arguments_to_array_for_call(generator, arguments())); generator.emit(call_type, callee_reg, this_reg, expression_string_index); } else { Optional first_argument_reg {}; @@ -1593,27 +1595,27 @@ Bytecode::CodeGenerationErrorOr CallExpression::generate_bytecode(Bytecode } u32 register_offset = 0; for (auto const& argument : arguments()) { - TRY(argument.value->generate_bytecode(generator)); + FIXME_NEWBC TRY(argument.value->generate_bytecode(generator)); generator.emit(Bytecode::Register { first_argument_reg.value().index() + register_offset }); register_offset += 1; } generator.emit(call_type, callee_reg, this_reg, first_argument_reg.value_or(Bytecode::Register { 0 }), arguments().size(), expression_string_index, builtin); } - return {}; + return Optional {}; } static void generate_await(Bytecode::Generator& generator, Bytecode::Register received_completion_register, Bytecode::Register received_completion_type_register, Bytecode::Register received_completion_value_register, Bytecode::IdentifierTableIndex type_identifier, Bytecode::IdentifierTableIndex value_identifier); // https://tc39.es/ecma262/#sec-return-statement-runtime-semantics-evaluation -Bytecode::CodeGenerationErrorOr ReturnStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ReturnStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (m_argument) { // ReturnStatement : return Expression ; // 1. Let exprRef be ? Evaluation of Expression. // 2. Let exprValue be ? GetValue(exprRef). - TRY(m_argument->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_argument->generate_bytecode(generator)); // 3. If GetGeneratorKind() is async, set exprValue to ? Await(exprValue). // Spec Issue?: The spec doesn't seem to do implicit await on explicit return for async functions, but does for @@ -1646,7 +1648,7 @@ Bytecode::CodeGenerationErrorOr ReturnStatement::generate_bytecode(Bytecod generator.emit(); } - return {}; + return Optional {}; } static void get_received_completion_type_and_value(Bytecode::Generator& generator, Bytecode::Register received_completion_register, Bytecode::Register received_completion_type_register, Bytecode::Register received_completion_value_register, Bytecode::IdentifierTableIndex type_identifier, Bytecode::IdentifierTableIndex value_identifier) @@ -1719,7 +1721,7 @@ static void generate_yield(Bytecode::Generator& generator, Bytecode::Label conti generator.emit(continuation_label); } -Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> YieldExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); VERIFY(generator.is_in_generator_function()); @@ -1739,7 +1741,7 @@ Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecod // 2. Let exprRef be ? Evaluation of AssignmentExpression. // 3. Let value be ? GetValue(exprRef). VERIFY(m_argument); - TRY(m_argument->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_argument->generate_bytecode(generator)); // 4. Let iteratorRecord be ? GetIterator(value, generatorKind). auto iterator_record_register = generator.allocate_register(); @@ -2006,11 +2008,11 @@ Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecod generator.emit(Bytecode::Label { loop_block }); generator.switch_to_basic_block(loop_end_block); - return {}; + return Optional {}; } if (m_argument) - TRY(m_argument->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_argument->generate_bytecode(generator)); else generator.emit(js_undefined()); @@ -2052,10 +2054,10 @@ Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecod generator.switch_to_basic_block(normal_completion_continuation_block); generator.emit(received_completion_value_register); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr IfStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> IfStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // test @@ -2070,14 +2072,14 @@ Bytecode::CodeGenerationErrorOr IfStatement::generate_bytecode(Bytecode::G auto& false_block = generator.make_block(); auto& end_block = generator.make_block(); - TRY(m_predicate->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_predicate->generate_bytecode(generator)); generator.emit( Bytecode::Label { true_block }, Bytecode::Label { false_block }); generator.switch_to_basic_block(true_block); generator.emit(js_undefined()); - TRY(m_consequent->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_consequent->generate_bytecode(generator)); if (!generator.is_current_block_terminated()) { generator.emit(Bytecode::Label { end_block }); } @@ -2086,15 +2088,15 @@ Bytecode::CodeGenerationErrorOr IfStatement::generate_bytecode(Bytecode::G generator.emit(js_undefined()); if (m_alternate) - TRY(m_alternate->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_alternate->generate_bytecode(generator)); if (!generator.is_current_block_terminated()) generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(end_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ContinueStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ContinueStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // FIXME: Handle finally blocks in a graceful manner @@ -2102,19 +2104,19 @@ Bytecode::CodeGenerationErrorOr ContinueStatement::generate_bytecode(Bytec // execution at the designated block if (m_target_label.is_null()) { generator.generate_continue(); - return {}; + return Optional {}; } generator.generate_continue(m_target_label); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr DebuggerStatement::generate_bytecode(Bytecode::Generator&) const +Bytecode::CodeGenerationErrorOr> DebuggerStatement::generate_bytecode(Bytecode::Generator&, [[maybe_unused]] Optional preferred_dst) const { - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ConditionalExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ConditionalExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // test @@ -2129,39 +2131,39 @@ Bytecode::CodeGenerationErrorOr ConditionalExpression::generate_bytecode(B auto& false_block = generator.make_block(); auto& end_block = generator.make_block(); - TRY(m_test->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_test->generate_bytecode(generator)); generator.emit( Bytecode::Label { true_block }, Bytecode::Label { false_block }); generator.switch_to_basic_block(true_block); - TRY(m_consequent->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_consequent->generate_bytecode(generator)); generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(false_block); - TRY(m_alternate->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_alternate->generate_bytecode(generator)); generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(end_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr SequenceExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> SequenceExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); for (auto& expression : m_expressions) - TRY(expression->generate_bytecode(generator)); + FIXME_NEWBC TRY(expression->generate_bytecode(generator)); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr TemplateLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> TemplateLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto string_reg = generator.allocate_register(); for (size_t i = 0; i < m_expressions.size(); i++) { - TRY(m_expressions[i]->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_expressions[i]->generate_bytecode(generator)); if (i == 0) { generator.emit(string_reg); } else { @@ -2170,13 +2172,13 @@ Bytecode::CodeGenerationErrorOr TemplateLiteral::generate_bytecode(Bytecod } generator.emit(string_reg); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr TaggedTemplateLiteral::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> TaggedTemplateLiteral::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); - TRY(m_tag->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_tag->generate_bytecode(generator)); auto tag_reg = generator.allocate_register(); generator.emit(tag_reg); @@ -2206,7 +2208,7 @@ Bytecode::CodeGenerationErrorOr TaggedTemplateLiteral::generate_bytecode(B if (is(expressions[i])) generator.emit(js_undefined()); else - TRY(expressions[i]->generate_bytecode(generator)); + FIXME_NEWBC TRY(expressions[i]->generate_bytecode(generator)); auto string_reg = string_regs[reg_index++]; generator.emit(string_reg); @@ -2227,7 +2229,7 @@ Bytecode::CodeGenerationErrorOr TaggedTemplateLiteral::generate_bytecode(B for (size_t i = 1; i < expressions.size(); i += 2) { auto string_reg = argument_regs[1 + i / 2]; - TRY(expressions[i]->generate_bytecode(generator)); + FIXME_NEWBC TRY(expressions[i]->generate_bytecode(generator)); generator.emit(string_reg); } @@ -2237,7 +2239,7 @@ Bytecode::CodeGenerationErrorOr TaggedTemplateLiteral::generate_bytecode(B reg_index = 0; for (auto& raw_string : m_template_literal->raw_strings()) { - TRY(raw_string->generate_bytecode(generator)); + FIXME_NEWBC TRY(raw_string->generate_bytecode(generator)); auto raw_string_reg = string_regs[reg_index++]; generator.emit(raw_string_reg); raw_string_regs.append(raw_string_reg); @@ -2263,10 +2265,10 @@ Bytecode::CodeGenerationErrorOr TaggedTemplateLiteral::generate_bytecode(B generator.emit(); generator.emit(Bytecode::Op::CallType::Call, tag_reg, this_reg); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr UpdateExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> UpdateExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto reference_registers = TRY(generator.emit_load_from_reference(*m_argument, Bytecode::Generator::CollectRegisters::Yes)); @@ -2284,25 +2286,25 @@ Bytecode::CodeGenerationErrorOr UpdateExpression::generate_bytecode(Byteco generator.emit(); if (reference_registers.has_value()) - TRY(generator.emit_store_to_reference(*reference_registers)); + FIXME_NEWBC TRY(generator.emit_store_to_reference(*reference_registers)); else - TRY(generator.emit_store_to_reference(*m_argument)); + FIXME_NEWBC TRY(generator.emit_store_to_reference(*m_argument)); if (!m_prefixed) generator.emit(*previous_value_for_postfix_reg); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ThrowStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ThrowStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); - TRY(m_argument->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_argument->generate_bytecode(generator)); generator.perform_needed_unwinds(); generator.emit(); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr BreakStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> BreakStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // FIXME: Handle finally blocks in a graceful manner @@ -2310,14 +2312,14 @@ Bytecode::CodeGenerationErrorOr BreakStatement::generate_bytecode(Bytecode // execution at the designated block if (m_target_label.is_null()) { generator.generate_break(); - return {}; + return Optional {}; } generator.generate_break(m_target_label); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> TryStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto& saved_block = generator.current_block(); @@ -2333,7 +2335,7 @@ Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode:: auto& finalizer_block = generator.make_block(); generator.switch_to_basic_block(finalizer_block); generator.emit(); - TRY(m_finalizer->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_finalizer->generate_bytecode(generator)); if (!generator.is_current_block_terminated()) { next_block = &generator.make_block(); auto next_target = Bytecode::Label { *next_block }; @@ -2356,8 +2358,8 @@ Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode:: // OPTIMIZATION: We avoid creating a lexical environment if the catch clause has no parameter. bool did_create_variable_scope_for_catch_clause = false; - TRY(m_handler->parameter().visit( - [&](DeprecatedFlyString const& parameter) -> Bytecode::CodeGenerationErrorOr { + FIXME_NEWBC TRY(m_handler->parameter().visit( + [&](DeprecatedFlyString const& parameter) -> Bytecode::CodeGenerationErrorOr> { if (!parameter.is_empty()) { generator.begin_variable_scope(); did_create_variable_scope_for_catch_clause = true; @@ -2365,16 +2367,16 @@ Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode:: generator.emit(parameter_identifier, Bytecode::Op::EnvironmentMode::Lexical, false); generator.emit(parameter_identifier, generator.next_environment_variable_cache(), Bytecode::Op::SetVariable::InitializationMode::Initialize); } - return {}; + return Optional {}; }, - [&](NonnullRefPtr const& binding_pattern) -> Bytecode::CodeGenerationErrorOr { + [&](NonnullRefPtr const& binding_pattern) -> Bytecode::CodeGenerationErrorOr> { generator.begin_variable_scope(); did_create_variable_scope_for_catch_clause = true; auto value_register = generator.allocate_register(); generator.emit(value_register); - TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Initialize, value_register, true)); - return {}; + FIXME_NEWBC TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Initialize, value_register, true)); + return Optional {}; })); // Set accumulator to undefined, otherwise we leak the error object through the accumulator. @@ -2382,7 +2384,7 @@ Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode:: // the exception _is_ caught here, it just leaks the error object through to the result. generator.emit(js_undefined()); - TRY(m_handler->body().generate_bytecode(generator)); + FIXME_NEWBC TRY(m_handler->body().generate_bytecode(generator)); handler_target = Bytecode::Label { handler_block }; if (did_create_variable_scope_for_catch_clause) @@ -2416,7 +2418,7 @@ Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode:: generator.start_boundary(Bytecode::Generator::BlockBoundaryType::ReturnToFinally); generator.switch_to_basic_block(target_block); - TRY(m_block->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_block->generate_bytecode(generator)); if (!generator.is_current_block_terminated()) { if (m_finalizer) { generator.emit(*finalizer_target); @@ -2435,20 +2437,20 @@ Bytecode::CodeGenerationErrorOr TryStatement::generate_bytecode(Bytecode:: generator.end_boundary(Bytecode::Generator::BlockBoundaryType::Unwind); generator.switch_to_basic_block(next_block ? *next_block : saved_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr SwitchStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> SwitchStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } -Bytecode::CodeGenerationErrorOr SwitchStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> SwitchStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto discriminant_reg = generator.allocate_register(); - TRY(m_discriminant->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_discriminant->generate_bytecode(generator)); generator.emit(discriminant_reg); Vector case_blocks; Bytecode::BasicBlock* entry_block_for_default { nullptr }; @@ -2465,7 +2467,7 @@ Bytecode::CodeGenerationErrorOr SwitchStatement::generate_labelled_evaluat auto& case_entry_block = generator.make_block(); if (switch_case->test()) { generator.switch_to_basic_block(*next_test_block); - TRY(switch_case->test()->generate_bytecode(generator)); + FIXME_NEWBC TRY(switch_case->test()->generate_bytecode(generator)); generator.emit(discriminant_reg); next_test_block = &generator.make_block(); generator.emit( @@ -2498,7 +2500,7 @@ Bytecode::CodeGenerationErrorOr SwitchStatement::generate_labelled_evaluat generator.switch_to_basic_block(*current_block); for (auto& statement : switch_case->children()) { - TRY(statement->generate_bytecode(generator)); + FIXME_NEWBC TRY(statement->generate_bytecode(generator)); if (generator.is_current_block_terminated()) break; } @@ -2520,30 +2522,30 @@ Bytecode::CodeGenerationErrorOr SwitchStatement::generate_labelled_evaluat if (has_lexical_declarations) generator.end_variable_scope(); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr SuperExpression::generate_bytecode(Bytecode::Generator&) const +Bytecode::CodeGenerationErrorOr> SuperExpression::generate_bytecode(Bytecode::Generator&, [[maybe_unused]] Optional preferred_dst) const { // The semantics for SuperExpression are handled in CallExpression and SuperCall. VERIFY_NOT_REACHED(); } -Bytecode::CodeGenerationErrorOr ClassDeclaration::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ClassDeclaration::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto accumulator_backup_reg = generator.allocate_register(); generator.emit(accumulator_backup_reg); - TRY(m_class_expression->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_class_expression->generate_bytecode(generator)); generator.emit_set_variable(*m_class_expression.ptr()->m_name, Bytecode::Op::SetVariable::InitializationMode::Initialize); generator.emit(accumulator_backup_reg); - return {}; + return Optional {}; } // 15.7.14 Runtime Semantics: ClassDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation -Bytecode::CodeGenerationErrorOr ClassExpression::generate_bytecode_with_lhs_name(Bytecode::Generator& generator, Optional lhs_name) const +Bytecode::CodeGenerationErrorOr> ClassExpression::generate_bytecode_with_lhs_name(Bytecode::Generator& generator, Optional lhs_name, [[maybe_unused]] Optional preferred_dst) const { // NOTE: Step 2 is not a part of NewClass instruction because it is assumed to be done before super class expression evaluation generator.emit(); @@ -2555,31 +2557,31 @@ Bytecode::CodeGenerationErrorOr ClassExpression::generate_bytecode_with_lh } if (m_super_class) - TRY(m_super_class->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_super_class->generate_bytecode(generator)); generator.emit(*this, lhs_name); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ClassExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ClassExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_bytecode_with_lhs_name(generator, {}); } -Bytecode::CodeGenerationErrorOr SpreadExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> SpreadExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) 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 ThisExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ThisExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); generator.emit(); - return {}; + return Optional {}; } static void generate_await(Bytecode::Generator& generator, Bytecode::Register received_completion_register, Bytecode::Register received_completion_type_register, Bytecode::Register received_completion_value_register, Bytecode::IdentifierTableIndex type_identifier, Bytecode::IdentifierTableIndex value_identifier) @@ -2612,10 +2614,10 @@ static void generate_await(Bytecode::Generator& generator, Bytecode::Register re generator.emit(received_completion_value_register); } -Bytecode::CodeGenerationErrorOr AwaitExpression::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> AwaitExpression::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); - TRY(m_argument->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_argument->generate_bytecode(generator)); auto received_completion_register = generator.allocate_register(); auto received_completion_type_register = generator.allocate_register(); @@ -2625,13 +2627,13 @@ Bytecode::CodeGenerationErrorOr AwaitExpression::generate_bytecode(Bytecod auto value_identifier = generator.intern_identifier("value"); generate_await(generator, received_completion_register, received_completion_type_register, received_completion_value_register, type_identifier, value_identifier); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr WithStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> WithStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); - TRY(m_object->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_object->generate_bytecode(generator)); generator.emit(); // EnterObjectEnvironment sets the running execution context's lexical_environment to a new Object Environment. @@ -2639,13 +2641,13 @@ Bytecode::CodeGenerationErrorOr WithStatement::generate_bytecode(Bytecode: generator.emit(js_undefined()); - TRY(m_body->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_body->generate_bytecode(generator)); generator.end_boundary(Bytecode::Generator::BlockBoundaryType::LeaveLexicalEnvironment); if (!generator.is_current_block_terminated()) generator.emit(); - return {}; + return Optional {}; } enum class LHSKind { @@ -2727,7 +2729,7 @@ static Bytecode::CodeGenerationErrorOr for_in_of_he } // 3. Let exprRef be the result of evaluating expr. - TRY(rhs->generate_bytecode(generator)); + FIXME_NEWBC TRY(rhs->generate_bytecode(generator)); // 4. Set the running execution context's LexicalEnvironment to oldEnv. if (entered_lexical_scope) @@ -2772,7 +2774,7 @@ static Bytecode::CodeGenerationErrorOr for_in_of_he } // 14.7.5.7 ForIn/OfBodyEvaluation ( lhs, stmt, iteratorRecord, iterationKind, lhsKind, labelSet [ , iteratorKind ] ), https://tc39.es/ecma262/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset -static Bytecode::CodeGenerationErrorOr for_in_of_body_evaluation(Bytecode::Generator& generator, ASTNode const& node, Variant, NonnullRefPtr> const& lhs, ASTNode const& body, ForInOfHeadEvaluationResult const& head_result, Vector const& label_set, Bytecode::BasicBlock& loop_end, Bytecode::BasicBlock& loop_update, IteratorHint iterator_kind = IteratorHint::Sync) +static Bytecode::CodeGenerationErrorOr> for_in_of_body_evaluation(Bytecode::Generator& generator, ASTNode const& node, Variant, NonnullRefPtr> const& lhs, ASTNode const& body, ForInOfHeadEvaluationResult const& head_result, Vector const& label_set, Bytecode::BasicBlock& loop_end, Bytecode::BasicBlock& loop_update, IteratorHint iterator_kind = IteratorHint::Sync, [[maybe_unused]] Optional preferred_dst = {}) { auto iterator_register = generator.allocate_register(); generator.emit(iterator_register); @@ -2847,15 +2849,15 @@ static Bytecode::CodeGenerationErrorOr for_in_of_body_evaluation(Bytecode: if (head_result.lhs_kind == LHSKind::VarBinding) { auto& declaration = static_cast(*lhs.get>()); VERIFY(declaration.declarations().size() == 1); - TRY(assign_accumulator_to_variable_declarator(generator, declaration.declarations().first(), declaration)); + FIXME_NEWBC TRY(assign_accumulator_to_variable_declarator(generator, declaration.declarations().first(), declaration)); } else { if (auto ptr = lhs.get_pointer>()) { - TRY(generator.emit_store_to_reference(**ptr)); + FIXME_NEWBC TRY(generator.emit_store_to_reference(**ptr)); } else { auto& binding_pattern = lhs.get>(); auto value_register = generator.allocate_register(); generator.emit(value_register); - TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Set, value_register, false)); + FIXME_NEWBC TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Set, value_register, false)); } } } @@ -2945,7 +2947,7 @@ static Bytecode::CodeGenerationErrorOr for_in_of_body_evaluation(Bytecode: auto value_register = generator.allocate_register(); generator.emit(value_register); - TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, head_result.lhs_kind == LHSKind::VarBinding ? Bytecode::Op::SetVariable::InitializationMode::Set : Bytecode::Op::SetVariable::InitializationMode::Initialize, value_register, false)); + FIXME_NEWBC TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, head_result.lhs_kind == LHSKind::VarBinding ? Bytecode::Op::SetVariable::InitializationMode::Set : Bytecode::Op::SetVariable::InitializationMode::Initialize, value_register, false)); } else { return Bytecode::CodeGenerationError { &node, @@ -2967,7 +2969,7 @@ static Bytecode::CodeGenerationErrorOr for_in_of_body_evaluation(Bytecode: generator.emit(js_undefined()); // l. Let result be the result of evaluating stmt. - TRY(body.generate_bytecode(generator)); + FIXME_NEWBC TRY(body.generate_bytecode(generator)); auto result_register = generator.allocate_register(); if (!generator.is_current_block_terminated()) @@ -2996,17 +2998,17 @@ static Bytecode::CodeGenerationErrorOr for_in_of_body_evaluation(Bytecode: generator.switch_to_basic_block(loop_end); generator.emit(result_register); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ForInStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ForInStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } // 14.7.5.5 Runtime Semantics: ForInOfLoopEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-forinofloopevaluation -Bytecode::CodeGenerationErrorOr ForInStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> ForInStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { auto& loop_end = generator.make_block(); auto& loop_update = generator.make_block(); @@ -3018,13 +3020,13 @@ Bytecode::CodeGenerationErrorOr ForInStatement::generate_labelled_evaluati return for_in_of_body_evaluation(generator, *this, m_lhs, body(), head_result, label_set, loop_end, loop_update); } -Bytecode::CodeGenerationErrorOr ForOfStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ForOfStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } -Bytecode::CodeGenerationErrorOr ForOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> ForOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { auto& loop_end = generator.make_block(); auto& loop_update = generator.make_block(); @@ -3036,13 +3038,13 @@ Bytecode::CodeGenerationErrorOr ForOfStatement::generate_labelled_evaluati return for_in_of_body_evaluation(generator, *this, m_lhs, body(), head_result, label_set, loop_end, loop_update); } -Bytecode::CodeGenerationErrorOr ForAwaitOfStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ForAwaitOfStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); return generate_labelled_evaluation(generator, {}); } -Bytecode::CodeGenerationErrorOr ForAwaitOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set) const +Bytecode::CodeGenerationErrorOr> ForAwaitOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector const& label_set, [[maybe_unused]] Optional preferred_dst) const { auto& loop_end = generator.make_block(); auto& loop_update = generator.make_block(); @@ -3055,44 +3057,44 @@ Bytecode::CodeGenerationErrorOr ForAwaitOfStatement::generate_labelled_eva } // 13.3.12.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-meta-properties-runtime-semantics-evaluation -Bytecode::CodeGenerationErrorOr MetaProperty::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> MetaProperty::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); // NewTarget : new . target if (m_type == MetaProperty::Type::NewTarget) { // 1. Return GetNewTarget(). generator.emit(); - return {}; + return Optional {}; } // ImportMeta : import . meta if (m_type == MetaProperty::Type::ImportMeta) { generator.emit(); - return {}; + return Optional {}; } VERIFY_NOT_REACHED(); } -Bytecode::CodeGenerationErrorOr ClassFieldInitializerStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ClassFieldInitializerStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); TRY(generator.emit_named_evaluation_if_anonymous_function(*m_expression, generator.intern_identifier(m_class_field_identifier_name))); generator.perform_needed_unwinds(); generator.emit(); - return {}; + return Optional {}; } -static Bytecode::CodeGenerationErrorOr generate_optional_chain(Bytecode::Generator& generator, OptionalChain const& optional_chain, Bytecode::Register current_value_register, Bytecode::Register current_base_register) +static Bytecode::CodeGenerationErrorOr> generate_optional_chain(Bytecode::Generator& generator, OptionalChain const& optional_chain, Bytecode::Register current_value_register, Bytecode::Register current_base_register, [[maybe_unused]] Optional preferred_dst) { if (is(optional_chain.base())) { auto& member_expression = static_cast(optional_chain.base()); - TRY(get_base_and_value_from_member_expression(generator, member_expression, current_base_register)); + FIXME_NEWBC TRY(get_base_and_value_from_member_expression(generator, member_expression, current_base_register)); } else if (is(optional_chain.base())) { auto& sub_optional_chain = static_cast(optional_chain.base()); - TRY(generate_optional_chain(generator, sub_optional_chain, current_value_register, current_base_register)); + FIXME_NEWBC TRY(generate_optional_chain(generator, sub_optional_chain, current_value_register, current_base_register)); } else { - TRY(optional_chain.base().generate_bytecode(generator)); + FIXME_NEWBC TRY(optional_chain.base().generate_bytecode(generator)); } generator.emit(current_value_register); @@ -3110,9 +3112,9 @@ static Bytecode::CodeGenerationErrorOr generate_optional_chain(Bytecode::G generator.switch_to_basic_block(not_nullish_block); } - TRY(reference.visit( - [&](OptionalChain::Call const& call) -> Bytecode::CodeGenerationErrorOr { - TRY(arguments_to_array_for_call(generator, call.arguments)); + FIXME_NEWBC TRY(reference.visit( + [&](OptionalChain::Call const& call) -> Bytecode::CodeGenerationErrorOr> { + FIXME_NEWBC TRY(arguments_to_array_for_call(generator, call.arguments)); generator.emit(Bytecode::Op::CallType::Call, current_value_register, current_base_register); generator.emit(current_value_register); @@ -3121,26 +3123,26 @@ static Bytecode::CodeGenerationErrorOr generate_optional_chain(Bytecode::G generator.emit(current_base_register); generator.emit(current_value_register); - return {}; + return Optional {}; }, - [&](OptionalChain::ComputedReference const& ref) -> Bytecode::CodeGenerationErrorOr { + [&](OptionalChain::ComputedReference const& ref) -> Bytecode::CodeGenerationErrorOr> { generator.emit(current_base_register); - TRY(ref.expression->generate_bytecode(generator)); + FIXME_NEWBC TRY(ref.expression->generate_bytecode(generator)); generator.emit(current_base_register); generator.emit(current_value_register); - return {}; + return Optional {}; }, - [&](OptionalChain::MemberReference const& ref) -> Bytecode::CodeGenerationErrorOr { + [&](OptionalChain::MemberReference const& ref) -> Bytecode::CodeGenerationErrorOr> { generator.emit(current_base_register); generator.emit_get_by_id(generator.intern_identifier(ref.identifier->string())); generator.emit(current_value_register); - return {}; + return Optional {}; }, - [&](OptionalChain::PrivateMemberReference const& ref) -> Bytecode::CodeGenerationErrorOr { + [&](OptionalChain::PrivateMemberReference const& ref) -> Bytecode::CodeGenerationErrorOr> { generator.emit(current_base_register); generator.emit(generator.intern_identifier(ref.private_identifier->string())); generator.emit(current_value_register); - return {}; + return Optional {}; })); } @@ -3151,10 +3153,10 @@ static Bytecode::CodeGenerationErrorOr generate_optional_chain(Bytecode::G generator.emit(Bytecode::Label { end_block }); generator.switch_to_basic_block(end_block); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr OptionalChain::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> OptionalChain::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); auto current_base_register = generator.allocate_register(); @@ -3164,15 +3166,15 @@ Bytecode::CodeGenerationErrorOr OptionalChain::generate_bytecode(Bytecode: return generate_optional_chain(generator, *this, current_value_register, current_base_register); } -Bytecode::CodeGenerationErrorOr ImportCall::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ImportCall::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); - TRY(m_specifier->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_specifier->generate_bytecode(generator)); auto specifier_reg = generator.allocate_register(); generator.emit(specifier_reg); if (m_options) { - TRY(m_options->generate_bytecode(generator)); + FIXME_NEWBC TRY(m_options->generate_bytecode(generator)); } else { generator.emit(js_undefined()); } @@ -3180,17 +3182,17 @@ Bytecode::CodeGenerationErrorOr ImportCall::generate_bytecode(Bytecode::Ge generator.emit(options_reg); generator.emit(specifier_reg, options_reg); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ExportStatement::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr> ExportStatement::generate_bytecode(Bytecode::Generator& generator, [[maybe_unused]] Optional preferred_dst) const { Bytecode::Generator::SourceLocationScope scope(generator, *this); if (!is_default_export()) { if (m_statement) { return m_statement->generate_bytecode(generator); } - return {}; + return Optional {}; } VERIFY(m_statement); @@ -3205,19 +3207,19 @@ Bytecode::CodeGenerationErrorOr ExportStatement::generate_bytecode(Bytecod if (!static_cast(*m_statement).has_name()) generator.emit(generator.intern_identifier(ExportStatement::local_name_for_default), generator.next_environment_variable_cache(), Bytecode::Op::SetVariable::InitializationMode::Initialize); - return {}; + return Optional {}; } // ExportDeclaration : export default AssignmentExpression ; VERIFY(is(*m_statement)); TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast(*m_statement), generator.intern_identifier("default"sv))); generator.emit(generator.intern_identifier(ExportStatement::local_name_for_default), generator.next_environment_variable_cache(), Bytecode::Op::SetVariable::InitializationMode::Initialize); - return {}; + return Optional {}; } -Bytecode::CodeGenerationErrorOr ImportStatement::generate_bytecode(Bytecode::Generator&) const +Bytecode::CodeGenerationErrorOr> ImportStatement::generate_bytecode(Bytecode::Generator&, [[maybe_unused]] Optional preferred_dst) const { - return {}; + return Optional {}; } } diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.cpp b/Userland/Libraries/LibJS/Bytecode/Generator.cpp index abeab0f26e..15ca38434c 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Generator.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#define FIXME_NEWBC (void) + #include #include #include @@ -36,7 +38,7 @@ CodeGenerationErrorOr> Generator::generate(VM& vm, ASTN // NOTE: This doesn't have to handle received throw/return completions, as GeneratorObject::resume_abrupt // will not enter the generator from the SuspendedStart state and immediately completes the generator. } - TRY(node.generate_bytecode(generator)); + FIXME_NEWBC TRY(node.generate_bytecode(generator)); if (generator.is_in_generator_or_async_function()) { // Terminate all unterminated blocks with yield return for (auto& block : generator.m_root_basic_blocks) { @@ -184,7 +186,7 @@ CodeGenerationErrorOr Generator::emit_super_refer // SuperProperty : super [ Expression ] // 3. Let propertyNameReference be ? Evaluation of Expression. // 4. Let propertyNameValue be ? GetValue(propertyNameReference). - TRY(expression.property().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.property().generate_bytecode(*this)); computed_property_value_register = allocate_register(); emit(*computed_property_value_register); } @@ -211,7 +213,7 @@ CodeGenerationErrorOr> Generator::emit_l { if (is(node)) { auto& identifier = static_cast(node); - TRY(identifier.generate_bytecode(*this)); + FIXME_NEWBC TRY(identifier.generate_bytecode(*this)); return Optional {}; } if (is(node)) { @@ -234,12 +236,12 @@ CodeGenerationErrorOr> Generator::emit_l return super_reference; } else { - TRY(expression.object().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.object().generate_bytecode(*this)); if (expression.is_computed()) { auto object_reg = allocate_register(); emit(object_reg); - TRY(expression.property().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.property().generate_bytecode(*this)); Optional property_reg {}; if (collect_registers == CollectRegisters::Yes) { property_reg = allocate_register(); @@ -275,12 +277,12 @@ CodeGenerationErrorOr> Generator::emit_l }; } -CodeGenerationErrorOr Generator::emit_store_to_reference(JS::ASTNode const& node) +CodeGenerationErrorOr> Generator::emit_store_to_reference(JS::ASTNode const& node) { if (is(node)) { auto& identifier = static_cast(node); emit_set_variable(identifier); - return {}; + return Optional {}; } if (is(node)) { // NOTE: The value is in the accumulator, so we have to store that away first. @@ -305,13 +307,13 @@ CodeGenerationErrorOr Generator::emit_store_to_reference(JS::ASTNode const emit(super_reference.base, super_reference.this_value, identifier_table_ref, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache()); } } else { - TRY(expression.object().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.object().generate_bytecode(*this)); auto object_reg = allocate_register(); emit(object_reg); if (expression.is_computed()) { - TRY(expression.property().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.property().generate_bytecode(*this)); auto property_reg = allocate_register(); emit(property_reg); emit(value_reg); @@ -332,7 +334,7 @@ CodeGenerationErrorOr Generator::emit_store_to_reference(JS::ASTNode const } } - return {}; + return Optional {}; } return CodeGenerationError { @@ -341,16 +343,16 @@ CodeGenerationErrorOr Generator::emit_store_to_reference(JS::ASTNode const }; } -CodeGenerationErrorOr Generator::emit_store_to_reference(ReferenceRegisters const& reference_registers) +CodeGenerationErrorOr> Generator::emit_store_to_reference(ReferenceRegisters const& reference_registers) { if (reference_registers.base == reference_registers.this_value) emit(reference_registers.base, reference_registers.referenced_name.value()); else emit(reference_registers.base, reference_registers.referenced_name.value(), reference_registers.this_value); - return {}; + return Optional {}; } -CodeGenerationErrorOr Generator::emit_delete_reference(JS::ASTNode const& node) +CodeGenerationErrorOr> Generator::emit_delete_reference(JS::ASTNode const& node) { if (is(node)) { auto& identifier = static_cast(node); @@ -358,7 +360,7 @@ CodeGenerationErrorOr Generator::emit_delete_reference(JS::ASTNode const& emit(Value(false)); else emit(intern_identifier(identifier.string())); - return {}; + return Optional {}; } if (is(node)) { @@ -375,16 +377,16 @@ CodeGenerationErrorOr Generator::emit_delete_reference(JS::ASTNode const& emit(super_reference.this_value, identifier_table_ref); } - return {}; + return Optional {}; } - TRY(expression.object().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.object().generate_bytecode(*this)); if (expression.is_computed()) { auto object_reg = allocate_register(); emit(object_reg); - TRY(expression.property().generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.property().generate_bytecode(*this)); emit(object_reg); } else if (expression.property().is_identifier()) { auto identifier_table_ref = intern_identifier(verify_cast(expression.property()).string()); @@ -396,7 +398,7 @@ CodeGenerationErrorOr Generator::emit_delete_reference(JS::ASTNode const& "Unimplemented non-computed member expression"sv }; } - return {}; + return Optional {}; } // Though this will have no deletion effect, we still have to evaluate the node as it can have side effects. @@ -405,13 +407,13 @@ CodeGenerationErrorOr Generator::emit_delete_reference(JS::ASTNode const& // 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation // 1. Let ref be the result of evaluating UnaryExpression. // 2. ReturnIfAbrupt(ref). - TRY(node.generate_bytecode(*this)); + FIXME_NEWBC TRY(node.generate_bytecode(*this)); // 3. If ref is not a Reference Record, return true. emit(Value(true)); // NOTE: The rest of the steps are handled by Delete{Variable,ByValue,Id}. - return {}; + return Optional {}; } void Generator::emit_set_variable(JS::Identifier const& identifier, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Op::EnvironmentMode mode) @@ -561,7 +563,7 @@ CodeGenerationErrorOr Generator::emit_named_evaluation_if_anonymous_functi if (is(expression)) { auto const& function_expression = static_cast(expression); if (!function_expression.has_name()) { - TRY(function_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); + FIXME_NEWBC TRY(function_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); return {}; } } @@ -569,12 +571,12 @@ CodeGenerationErrorOr Generator::emit_named_evaluation_if_anonymous_functi if (is(expression)) { auto const& class_expression = static_cast(expression); if (!class_expression.has_name()) { - TRY(class_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); + FIXME_NEWBC TRY(class_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); return {}; } } - TRY(expression.generate_bytecode(*this)); + FIXME_NEWBC TRY(expression.generate_bytecode(*this)); return {}; } diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.h b/Userland/Libraries/LibJS/Bytecode/Generator.h index c6a8966c81..235ae3d79f 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.h +++ b/Userland/Libraries/LibJS/Bytecode/Generator.h @@ -103,9 +103,9 @@ public: No }; CodeGenerationErrorOr> emit_load_from_reference(JS::ASTNode const&, CollectRegisters); - CodeGenerationErrorOr emit_store_to_reference(JS::ASTNode const&); - CodeGenerationErrorOr emit_store_to_reference(ReferenceRegisters const&); - CodeGenerationErrorOr emit_delete_reference(JS::ASTNode const&); + CodeGenerationErrorOr> emit_store_to_reference(JS::ASTNode const&); + CodeGenerationErrorOr> emit_store_to_reference(ReferenceRegisters const&); + CodeGenerationErrorOr> emit_delete_reference(JS::ASTNode const&); CodeGenerationErrorOr emit_super_reference(MemberExpression const&);