LibJS+LibWeb: Pass function metadata collected in parsing using a struct

By using separate struct we can avoid updating AST node and
ECMAScriptFunctionObject constructors every time there is a need to
add or remove some additional information colllected during parsing.
This commit is contained in:
Aliaksandr Kalenik 2024-05-22 11:04:50 +01:00 committed by Andreas Kling
parent 99f6528009
commit e934132442
Notes: sideshowbarker 2024-07-17 09:49:48 +09:00
12 changed files with 75 additions and 73 deletions

View file

@ -237,7 +237,6 @@ static JS::ThrowCompletionOr<JS::Value> execute_a_function_body(Web::Page& page,
auto& realm = window->realm();
bool contains_direct_call_to_eval = false;
auto source_text = ByteString::formatted("function() {{ {} }}", body);
auto parser = JS::Parser { JS::Lexer { source_text } };
auto function_expression = parser.parse_function_node<JS::FunctionExpression>();
@ -266,8 +265,7 @@ static JS::ThrowCompletionOr<JS::Value> execute_a_function_body(Web::Page& page,
// The result of parsing global scope above.
// strict
// The result of parsing strict above.
auto function = JS::ECMAScriptFunctionObject::create(realm, "", move(source_text), function_expression->body(), function_expression->parameters(), function_expression->function_length(), function_expression->local_variables_names(), &global_scope, nullptr, function_expression->kind(), function_expression->is_strict_mode(),
function_expression->uses_this_from_environment(), function_expression->might_need_arguments_object(), contains_direct_call_to_eval);
auto function = JS::ECMAScriptFunctionObject::create(realm, "", move(source_text), function_expression->body(), function_expression->parameters(), function_expression->function_length(), function_expression->local_variables_names(), &global_scope, nullptr, function_expression->kind(), function_expression->is_strict_mode(), function_expression->parsing_insights());
// 9. Let completion be Function.[[Call]](window, parameters) with function as the this value.
// NOTE: This is not entirely clear, but I don't think they mean actually passing `function` as