LibJS: Don't allow the redeclaration of a var
variable using let/const
Previously, we were allowing the redeclaration of a variable with `let` or `const` if it was declared initially using `var`, we should not tolerate any form of variable redeclaration using let/const.
This commit is contained in:
parent
9f38f4dbfb
commit
83ea7bb9e7
Notes:
sideshowbarker
2024-07-19 08:19:53 +09:00
Author: https://github.com/0xtechnobabble Commit: https://github.com/SerenityOS/serenity/commit/83ea7bb9e73 Pull-request: https://github.com/SerenityOS/serenity/pull/1441
1 changed files with 1 additions and 1 deletions
|
@ -96,7 +96,7 @@ void Interpreter::declare_variable(String name, DeclarationType declaration_type
|
||||||
break;
|
break;
|
||||||
case DeclarationType::Let:
|
case DeclarationType::Let:
|
||||||
case DeclarationType::Const:
|
case DeclarationType::Const:
|
||||||
if (m_scope_stack.last().variables.get(name).has_value() && m_scope_stack.last().variables.get(name).value().declaration_type != DeclarationType::Var)
|
if (m_scope_stack.last().variables.get(name).has_value())
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
|
||||||
m_scope_stack.last().variables.set(move(name), { js_undefined(), declaration_type });
|
m_scope_stack.last().variables.set(move(name), { js_undefined(), declaration_type });
|
||||||
|
|
Loading…
Add table
Reference in a new issue