mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:08:11 +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:
parent
67b8e6fc5b
commit
3c4a9e421f
6 changed files with 54 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue