1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 11:55:08 +00: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:
davidot 2022-02-07 13:31:01 +01:00 committed by Linus Groh
parent cc7a117f0f
commit 4136cbdb09
6 changed files with 462 additions and 305 deletions

View file

@ -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;
});
});