1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:37:46 +00:00

LibJS: Convert bind_this_value() to ThrowCompletionOr

Also add spec step comments to it while we're here.
This commit is contained in:
Linus Groh 2021-10-09 16:55:33 +01:00
parent 0aa24f4ce5
commit 617d3cd3d3
4 changed files with 16 additions and 11 deletions

View file

@ -79,15 +79,22 @@ ThrowCompletionOr<Value> FunctionEnvironment::get_this_binding(GlobalObject& glo
}
// 9.1.1.3.1 BindThisValue ( V ), https://tc39.es/ecma262/#sec-bindthisvalue
Value FunctionEnvironment::bind_this_value(GlobalObject& global_object, Value this_value)
ThrowCompletionOr<Value> FunctionEnvironment::bind_this_value(GlobalObject& global_object, Value this_value)
{
VERIFY(this_binding_status() != ThisBindingStatus::Lexical);
if (this_binding_status() == ThisBindingStatus::Initialized) {
vm().throw_exception<ReferenceError>(global_object, ErrorType::ThisIsAlreadyInitialized);
return {};
}
// 1. Assert: envRec.[[ThisBindingStatus]] is not lexical.
VERIFY(m_this_binding_status != ThisBindingStatus::Lexical);
// 2. If envRec.[[ThisBindingStatus]] is initialized, throw a ReferenceError exception.
if (m_this_binding_status == ThisBindingStatus::Initialized)
return vm().throw_completion<ReferenceError>(global_object, ErrorType::ThisIsAlreadyInitialized);
// 3. Set envRec.[[ThisValue]] to V.
m_this_value = this_value;
// 4. Set envRec.[[ThisBindingStatus]] to initialized.
m_this_binding_status = ThisBindingStatus::Initialized;
// 5. Return V.
return this_value;
}