mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
LibJS: Convert ScopeNode declaration functions to ThrowCompletionOr
This removes a number of vm.exception() checks which are now caught
directly by TRY. Make use of these checks in
{Global, Eval}DeclarationInstantiation and while we're here add spec
comments.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 19:38:25 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/4136cbdb091 Pull-request: https://github.com/SerenityOS/serenity/pull/12343 Reviewed-by: https://github.com/linusg
@@ -375,11 +375,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||
|
||||
if (!has_parameter_expressions && arguments_object_needed) {
|
||||
scope_body->for_each_lexically_declared_name([&](auto const& name) {
|
||||
if (name == arguments_name) {
|
||||
if (name == arguments_name)
|
||||
arguments_object_needed = false;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -485,7 +482,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||
if (scope_body) {
|
||||
scope_body->for_each_var_declared_name([&](auto const& name) {
|
||||
if (instantiated_var_names.set(name) != AK::HashSetResult::InsertedNewEntry)
|
||||
return IterationDecision::Continue;
|
||||
return;
|
||||
MUST(var_environment->create_mutable_binding(global_object(), name, false));
|
||||
|
||||
Value initial_value;
|
||||
@@ -495,8 +492,6 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||
initial_value = MUST(environment->get_binding_value(global_object(), name, false));
|
||||
|
||||
MUST(var_environment->initialize_binding(global_object(), name, initial_value));
|
||||
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -506,7 +501,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||
scope_body->for_each_function_hoistable_with_annexB_extension([&](FunctionDeclaration& function_declaration) {
|
||||
auto& function_name = function_declaration.name();
|
||||
if (parameter_names.contains(function_name))
|
||||
return IterationDecision::Continue;
|
||||
return;
|
||||
// The spec says 'initializedBindings' here but that does not exist and it then adds it to 'instantiatedVarNames' so it probably means 'instantiatedVarNames'.
|
||||
if (!instantiated_var_names.contains(function_name) && function_name != vm.names.arguments.as_string()) {
|
||||
MUST(var_environment->create_mutable_binding(global_object(), function_name, false));
|
||||
@@ -515,7 +510,6 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||
}
|
||||
|
||||
function_declaration.set_should_do_additional_annexB_steps();
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -554,7 +548,6 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||
MUST(lex_environment->create_immutable_binding(global_object(), name, true));
|
||||
else
|
||||
MUST(lex_environment->create_mutable_binding(global_object(), name, false));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user