diff options
author | davidot <davidot@serenityos.org> | 2021-12-30 14:13:20 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-12-30 15:29:33 +0100 |
commit | 676554d3f86d7c429f1969942190427666b5423e (patch) | |
tree | 6d598d4a12ab310167d7143d815962c0d299934c /Userland/Libraries/LibJS/AST.cpp | |
parent | dfaa6c910cda9fd49e681f10c7efbabed74ef0a6 (diff) | |
download | serenity-676554d3f86d7c429f1969942190427666b5423e.zip |
LibJS: Convert resolve_binding() to ThrowCompletionOr
The spec has a note stating that resolve binding will always return a
reference whose [[ReferencedName]] field is name. However this is not
correct as the underlying method GetIdentifierReference may throw on
env.HasBinding(name) thus it can throw. However, there are some
scenarios where it cannot throw because the reference is known to exist
in that case we use MUST with a comment.
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 997579d9fd..e0ee8d5346 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -705,7 +705,7 @@ struct ForInOfHeadState { if (!destructuring) { VERIFY(for_declaration.declarations().first().target().has<NonnullRefPtr<Identifier>>()); - lhs_reference = interpreter.vm().resolve_binding(for_declaration.declarations().first().target().get<NonnullRefPtr<Identifier>>()->string()); + lhs_reference = MUST(interpreter.vm().resolve_binding(for_declaration.declarations().first().target().get<NonnullRefPtr<Identifier>>()->string())); } } @@ -764,7 +764,7 @@ static ThrowCompletionOr<ForInOfHeadState> for_in_of_head_execute(Interpreter& i if (variable.init()) { VERIFY(variable.target().has<NonnullRefPtr<Identifier>>()); auto& binding_id = variable.target().get<NonnullRefPtr<Identifier>>()->string(); - auto reference = interpreter.vm().resolve_binding(binding_id); + auto reference = TRY(interpreter.vm().resolve_binding(binding_id)); if (auto* exception = interpreter.exception()) return throw_completion(exception->value()); @@ -1142,7 +1142,7 @@ Reference Identifier::to_reference(Interpreter& interpreter, GlobalObject&) cons m_cached_environment_coordinate = {}; } - auto reference = interpreter.vm().resolve_binding(string()); + auto reference = TRY_OR_DISCARD(interpreter.vm().resolve_binding(string())); if (reference.environment_coordinate().has_value()) m_cached_environment_coordinate = reference.environment_coordinate(); return reference; |