mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
LibJS: Support deleting local variables with operator delete
To make this cleaner i also moved the logic into Reference::delete_.
This commit is contained in:
parent
af58779def
commit
064ed8279e
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/IdanHo
Commit: 064ed8279e
Pull-request: https://github.com/SerenityOS/serenity/pull/7905
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/linusg
14 changed files with 82 additions and 10 deletions
|
@ -98,4 +98,32 @@ Value Reference::get(GlobalObject& global_object)
|
|||
return object->get(m_name).value_or(js_undefined());
|
||||
}
|
||||
|
||||
bool Reference::delete_(GlobalObject& global_object)
|
||||
{
|
||||
if (is_unresolvable())
|
||||
return true;
|
||||
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
if (is_local_variable() || is_global_variable()) {
|
||||
if (is_local_variable())
|
||||
return vm.delete_variable(m_name.to_string());
|
||||
else
|
||||
return global_object.delete_property(m_name);
|
||||
}
|
||||
|
||||
auto base = this->base();
|
||||
|
||||
if (base.is_nullish()) {
|
||||
// This will always fail the to_object() call below, let's throw the TypeError ourselves with a nice message instead.
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ReferenceNullishDeleteProperty, m_name.to_value(vm).to_string_without_side_effects(), base.to_string_without_side_effects());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* object = base.to_object(global_object);
|
||||
VERIFY(object);
|
||||
|
||||
return object->delete_property(m_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue