LibJS: Make it possible to reference the "this" value in JavaScript

This commit is contained in:
Andreas Kling 2020-03-28 16:32:46 +01:00
parent 401becb922
commit fecbef4ffe
Notes: sideshowbarker 2024-07-19 08:05:49 +09:00

View file

@ -144,6 +144,9 @@ void Interpreter::set_variable(const FlyString& name, Value value, bool first_as
Optional<Value> Interpreter::get_variable(const FlyString& name)
{
if (name == "this")
return this_value();
for (ssize_t i = m_scope_stack.size() - 1; i >= 0; --i) {
auto& scope = m_scope_stack.at(i);
auto value = scope.variables.get(name);