1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibJS: Convert has_binding() to ThrowCompletionOr

Also add spec step comments to it while we're here.
This commit is contained in:
Linus Groh 2021-10-09 17:07:32 +01:00
parent 617d3cd3d3
commit fbb176c926
11 changed files with 50 additions and 29 deletions

View file

@ -558,7 +558,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
while (this_environment != variable_environment) {
if (!is<ObjectEnvironment>(*this_environment)) {
program.for_each_var_declared_name([&](auto const& name) {
if (this_environment->has_binding(name)) {
if (MUST(this_environment->has_binding(name))) {
vm.throw_exception<SyntaxError>(global_object, ErrorType::FixmeAddAnErrorStringWithMessage, "Var already declared lexically");
return IterationDecision::Break;
}
@ -605,7 +605,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
auto* this_environment = lexical_environment;
while (this_environment != variable_environment) {
if (!is<ObjectEnvironment>(*this_environment) && this_environment->has_binding(function_name))
if (!is<ObjectEnvironment>(*this_environment) && MUST(this_environment->has_binding(function_name)))
return IterationDecision::Continue;
this_environment = this_environment->outer_environment();
@ -628,7 +628,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
if (vm.exception())
return IterationDecision::Break;
} else {
if (!variable_environment->has_binding(function_name)) {
if (!MUST(variable_environment->has_binding(function_name))) {
variable_environment->create_mutable_binding(global_object, function_name, true);
variable_environment->initialize_binding(global_object, function_name, js_undefined());
VERIFY(!vm.exception());
@ -700,7 +700,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
if (auto* exception = vm.exception())
return throw_completion(exception->value());
} else {
auto binding_exists = variable_environment->has_binding(declaration.name());
auto binding_exists = MUST(variable_environment->has_binding(declaration.name()));
if (!binding_exists) {
variable_environment->create_mutable_binding(global_object, declaration.name(), true);
@ -721,7 +721,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
if (auto* exception = vm.exception())
return throw_completion(exception->value());
} else {
auto binding_exists = variable_environment->has_binding(var_name);
auto binding_exists = MUST(variable_environment->has_binding(var_name));
if (!binding_exists) {
variable_environment->create_mutable_binding(global_object, var_name, true);