LibJS: Change NewFunction instruction to accept FunctionNode

Preparation for upcoming changes where NewFunction will have to be used
with FunctionDeclaration node.
This commit is contained in:
Aliaksandr Kalenik 2024-05-09 05:18:23 +00:00 committed by Andreas Kling
commit 89a007327a
Notes: sideshowbarker 2024-07-17 02:59:43 +09:00
3 changed files with 18 additions and 6 deletions

View file

@ -714,6 +714,11 @@ public:
FunctionKind kind() const { return m_kind; }
UsesThis uses_this() const { return m_uses_this; }
virtual bool has_name() const = 0;
virtual Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const = 0;
virtual ~FunctionNode() {};
protected:
FunctionNode(RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Vector<DeprecatedFlyString> local_variables_names, UsesThis uses_this)
: m_name(move(name))
@ -773,6 +778,11 @@ public:
void set_should_do_additional_annexB_steps() { m_is_hoisted = true; }
bool has_name() const override { return true; }
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString) const override { VERIFY_NOT_REACHED(); }
virtual ~FunctionDeclaration() {};
private:
bool m_is_hoisted { false };
};
@ -794,9 +804,11 @@ public:
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode_with_lhs_name(Bytecode::Generator&, Optional<Bytecode::IdentifierTableIndex> lhs_name, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
bool has_name() const { return !name().is_empty(); }
bool has_name() const override { return !name().is_empty(); }
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const;
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const override;
virtual ~FunctionExpression() {};
private:
virtual bool is_function_expression() const override { return true; }

View file

@ -420,7 +420,7 @@ inline ThrowCompletionOr<void> set_variable(
return {};
}
inline Value new_function(VM& vm, FunctionExpression const& function_node, Optional<IdentifierTableIndex> const& lhs_name, Optional<Operand> const& home_object)
inline Value new_function(VM& vm, FunctionNode const& function_node, Optional<IdentifierTableIndex> const& lhs_name, Optional<Operand> const& home_object)
{
Value value;

View file

@ -1399,7 +1399,7 @@ private:
class NewFunction final : public Instruction {
public:
explicit NewFunction(Operand dst, FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> home_object = {})
explicit NewFunction(Operand dst, FunctionNode const& function_node, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> home_object = {})
: Instruction(Type::NewFunction)
, m_dst(dst)
, m_function_node(function_node)
@ -1412,13 +1412,13 @@ public:
ByteString to_byte_string_impl(Bytecode::Executable const&) const;
Operand dst() const { return m_dst; }
FunctionExpression const& function_node() const { return m_function_node; }
FunctionNode const& function_node() const { return m_function_node; }
Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
Optional<Operand> const& home_object() const { return m_home_object; }
private:
Operand m_dst;
FunctionExpression const& m_function_node;
FunctionNode const& m_function_node;
Optional<IdentifierTableIndex> m_lhs_name;
Optional<Operand> m_home_object;
};