mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
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.
This commit is contained in:
parent
dfaa6c910c
commit
676554d3f8
8 changed files with 44 additions and 42 deletions
|
@ -252,7 +252,13 @@ void GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
|||
m_cached_environment_coordinate = {};
|
||||
}
|
||||
|
||||
auto reference = interpreter.vm().resolve_binding(string);
|
||||
auto reference_or_error = interpreter.vm().resolve_binding(string);
|
||||
if (reference_or_error.is_throw_completion()) {
|
||||
interpreter.vm().throw_exception(interpreter.global_object(), reference_or_error.release_error().value());
|
||||
return Reference {};
|
||||
}
|
||||
|
||||
auto reference = reference_or_error.release_value();
|
||||
if (reference.environment_coordinate().has_value())
|
||||
m_cached_environment_coordinate = reference.environment_coordinate();
|
||||
return reference;
|
||||
|
@ -270,10 +276,13 @@ void GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
|||
void SetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto reference = vm.resolve_binding(interpreter.current_executable().get_identifier(m_identifier));
|
||||
if (vm.exception())
|
||||
auto reference_or_error = vm.resolve_binding(interpreter.current_executable().get_identifier(m_identifier));
|
||||
if (reference_or_error.is_throw_completion()) {
|
||||
interpreter.vm().throw_exception(interpreter.global_object(), reference_or_error.release_error().value());
|
||||
return;
|
||||
}
|
||||
|
||||
auto reference = reference_or_error.release_value();
|
||||
// TODO: ThrowCompletionOr<void> return
|
||||
(void)reference.put_value(interpreter.global_object(), interpreter.accumulator());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue