mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-28 12:18:25 +00:00
LibJS: Allow "delete someGlobalVariable"
This is solved by allowing Identifier nodes to produce a Reference with the global object as base.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <LibJS/Runtime/MarkedValueList.h>
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Reference.h>
|
||||
#include <LibJS/Runtime/Shape.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
@@ -163,6 +164,18 @@ Value Interpreter::get_variable(const FlyString& name)
|
||||
return global_object().get(name);
|
||||
}
|
||||
|
||||
Reference Interpreter::get_reference(const FlyString& name)
|
||||
{
|
||||
if (m_call_stack.size()) {
|
||||
for (auto* environment = current_environment(); environment; environment = environment->parent()) {
|
||||
auto possible_match = environment->get(name);
|
||||
if (possible_match.has_value())
|
||||
return { Reference::LocalVariable, name };
|
||||
}
|
||||
}
|
||||
return { &global_object(), PropertyName(name) };
|
||||
}
|
||||
|
||||
void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots)
|
||||
{
|
||||
roots.set(m_global_object);
|
||||
|
||||
Reference in New Issue
Block a user