mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00
LibJS: Convert delete_binding() to ThrowCompletionOr
Also add spec step comments to it while we're here.
This commit is contained in:
parent
f35e268024
commit
01370136ee
8 changed files with 41 additions and 12 deletions
|
@ -175,16 +175,24 @@ ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value_direct(Global
|
|||
}
|
||||
|
||||
// 9.1.1.1.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-deletebinding-n
|
||||
bool DeclarativeEnvironment::delete_binding(GlobalObject&, FlyString const& name)
|
||||
ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(GlobalObject&, FlyString const& name)
|
||||
{
|
||||
// 1. Assert: envRec has a binding for the name that is the value of N.
|
||||
auto it = m_names.find(name);
|
||||
VERIFY(it != m_names.end());
|
||||
|
||||
auto& binding = m_bindings[it->value];
|
||||
|
||||
// 2. If the binding for N in envRec cannot be deleted, return false.
|
||||
if (!binding.can_be_deleted)
|
||||
return false;
|
||||
|
||||
// 3. Remove the binding for N from envRec.
|
||||
// NOTE: We keep the entry in m_bindings to avoid disturbing indices.
|
||||
binding = {};
|
||||
m_names.remove(it);
|
||||
|
||||
// 4. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue