@@ -670,11 +670,13 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
670
670
m_state.labels_in_scope = move (old_labels_in_scope);
671
671
});
672
672
673
+ bool contains_direct_call_to_eval = false ;
674
+
673
675
auto function_body_result = [&]() -> RefPtr<FunctionBody> {
674
676
TemporaryChange change (m_state.in_arrow_function_context , true );
675
677
if (match (TokenType::CurlyOpen)) {
676
678
// Parse a function body with statements
677
- return parse_function_body (parameters, FunctionKind::Regular);
679
+ return parse_function_body (parameters, FunctionKind::Regular, contains_direct_call_to_eval );
678
680
}
679
681
if (match_expression ()) {
680
682
// Parse a function body which returns a single expression
@@ -689,6 +691,7 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
689
691
return_block->append <ReturnStatement>({ m_filename, rule_start.position (), position () }, move (return_expression));
690
692
if (m_state.strict_mode )
691
693
return_block->set_strict_mode ();
694
+ contains_direct_call_to_eval = function_scope.contains_direct_call_to_eval ();
692
695
return return_block;
693
696
}
694
697
// Invalid arrow function body
@@ -715,7 +718,7 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
715
718
return create_ast_node<FunctionExpression>(
716
719
{ m_state.current_token .filename (), rule_start.position (), position () }, " " , move (body),
717
720
move (parameters), function_length, FunctionKind::Regular, body->in_strict_mode (),
718
- /* might_need_arguments_object */ false , /* is_arrow_function */ true );
721
+ /* might_need_arguments_object */ false , contains_direct_call_to_eval, /* is_arrow_function */ true );
719
722
}
720
723
721
724
RefPtr<Statement> Parser::try_parse_labelled_statement (AllowLabelledFunction allow_function)
@@ -1034,12 +1037,12 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
1034
1037
constructor = create_ast_node<FunctionExpression>(
1035
1038
{ m_state.current_token .filename (), rule_start.position (), position () }, class_name, move (constructor_body),
1036
1039
Vector { FunctionNode::Parameter { FlyString { " args" }, nullptr , true } }, 0 , FunctionKind::Regular,
1037
- /* is_strict_mode */ true , /* might_need_arguments_object */ false );
1040
+ /* is_strict_mode */ true , /* might_need_arguments_object */ false , /* contains_direct_call_to_eval */ false );
1038
1041
} else {
1039
1042
constructor = create_ast_node<FunctionExpression>(
1040
1043
{ m_state.current_token .filename (), rule_start.position (), position () }, class_name, move (constructor_body),
1041
1044
Vector<FunctionNode::Parameter> {}, 0 , FunctionKind::Regular,
1042
- /* is_strict_mode */ true , /* might_need_arguments_object */ false );
1045
+ /* is_strict_mode */ true , /* might_need_arguments_object */ false , /* contains_direct_call_to_eval */ false );
1043
1046
}
1044
1047
}
1045
1048
@@ -1996,7 +1999,7 @@ void Parser::parse_statement_list(ScopeNode& output_node, AllowLabelledFunction
1996
1999
}
1997
2000
1998
2001
// FunctionBody, https://tc39.es/ecma262/#prod-FunctionBody
1999
- NonnullRefPtr<FunctionBody> Parser::parse_function_body (Vector<FunctionDeclaration::Parameter> const & parameters, FunctionKind function_kind)
2002
+ NonnullRefPtr<FunctionBody> Parser::parse_function_body (Vector<FunctionDeclaration::Parameter> const & parameters, FunctionKind function_kind, bool & contains_direct_call_to_eval )
2000
2003
{
2001
2004
auto rule_start = push_start ();
2002
2005
auto function_body = create_ast_node<FunctionBody>({ m_state.current_token .filename (), rule_start.position (), position () });
@@ -2052,6 +2055,7 @@ NonnullRefPtr<FunctionBody> Parser::parse_function_body(Vector<FunctionDeclarati
2052
2055
2053
2056
consume (TokenType::CurlyClose);
2054
2057
m_state.strict_mode = previous_strict_mode;
2058
+ contains_direct_call_to_eval = function_scope.contains_direct_call_to_eval ();
2055
2059
return function_body;
2056
2060
}
2057
2061
@@ -2117,7 +2121,8 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
2117
2121
m_state.labels_in_scope = move (old_labels_in_scope);
2118
2122
});
2119
2123
2120
- auto body = parse_function_body (parameters, function_kind);
2124
+ bool contains_direct_call_to_eval = false ;
2125
+ auto body = parse_function_body (parameters, function_kind, contains_direct_call_to_eval);
2121
2126
2122
2127
auto has_strict_directive = body->in_strict_mode ();
2123
2128
@@ -2127,7 +2132,8 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
2127
2132
return create_ast_node<FunctionNodeType>(
2128
2133
{ m_state.current_token .filename (), rule_start.position (), position () },
2129
2134
name, move (body), move (parameters), function_length,
2130
- function_kind, has_strict_directive, m_state.function_might_need_arguments_object );
2135
+ function_kind, has_strict_directive, m_state.function_might_need_arguments_object ,
2136
+ contains_direct_call_to_eval);
2131
2137
}
2132
2138
2133
2139
Vector<FunctionNode::Parameter> Parser::parse_formal_parameters (int & function_length, u8 parse_options)
0 commit comments