diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-05 00:24:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-05 00:24:32 +0200 |
commit | 3c99c27db4b1bdf7000a8d044efe9d5fdf18dba5 (patch) | |
tree | b32d6184e6a19541674b8e001c1edcc0d6763e6b /Libraries | |
parent | 9ebd066ac84d6a4b132299c4a927e2c4049a2f42 (diff) | |
download | serenity-3c99c27db4b1bdf7000a8d044efe9d5fdf18dba5.zip |
LibJS: Clean up the anonymous wrapper block in "for" using ScopeGuard
This ensures that we don't forget to pop the wrapper off of the scope
stack when returning early due to an exception or some such. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 52d8e007ff..5305ae7bf1 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -26,6 +26,7 @@ #include <AK/Function.h> #include <AK/HashMap.h> +#include <AK/ScopeGuard.h> #include <AK/StringBuilder.h> #include <LibJS/AST.h> #include <LibJS/Interpreter.h> @@ -200,6 +201,11 @@ Value ForStatement::execute(Interpreter& interpreter) const interpreter.enter_scope(*wrapper, {}, ScopeType::Block); } + auto wrapper_cleanup = ScopeGuard([&] { + if (wrapper) + interpreter.exit_scope(*wrapper); + }); + Value last_value = js_undefined(); if (m_init) { @@ -254,9 +260,6 @@ Value ForStatement::execute(Interpreter& interpreter) const } } - if (wrapper) - interpreter.exit_scope(*wrapper); - return last_value; } |