1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

LibJS: Allow multiple labels on the same statement

Since there are only a number of statements where labels can actually be
used we now also only store labels when necessary.
Also now tracks the first continue usage of a label since this might not
be valid but that can only be determined after we have parsed the
statement.
Also ensures the correct error does not get wiped by load_state.
This commit is contained in:
davidot 2021-09-18 23:01:54 +02:00 committed by Linus Groh
parent bfc1b4ba61
commit 79caca8ca2
7 changed files with 194 additions and 47 deletions

View file

@ -187,6 +187,14 @@ Value Interpreter::execute_statement(GlobalObject& global_object, const Statemen
return statement.execute(*this, global_object);
auto& block = static_cast<const ScopeNode&>(statement);
Vector<FlyString> const& labels = [&] {
if (is<BlockStatement>(block)) {
return static_cast<BlockStatement const&>(block).labels();
} else {
return Vector<FlyString>();
}
}();
enter_scope(block, scope_type, global_object);
Value last_value;
@ -195,7 +203,7 @@ Value Interpreter::execute_statement(GlobalObject& global_object, const Statemen
if (!value.is_empty())
last_value = value;
if (vm().should_unwind()) {
if (!block.labels().is_empty() && vm().should_unwind_until(ScopeType::Breakable, block.labels()))
if (!labels.is_empty() && vm().should_unwind_until(ScopeType::Breakable, labels))
vm().stop_unwind();
break;
}