1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:37:36 +00:00

LibJS: Implement LabelledStatement & LabelledEvaluation semantics

Instead of slapping 0..N labels on a statement like the current
LabelableStatement does, we need the spec's LabelledStatement for a
proper implementation of control flow using only completions - it always
has one label and one labelled statement - what appears to be 'multiple
labels' on the same statement is actually nested LabelledStatements.

Note that this is unused yet and will fully replace LabelableStatement
in the next commit.
This commit is contained in:
Linus Groh 2022-01-05 18:54:25 +01:00
parent 558fd5b166
commit fc474966bc
2 changed files with 132 additions and 5 deletions

View file

@ -86,6 +86,29 @@ public:
}
};
// 14.13 Labelled Statements, https://tc39.es/ecma262/#sec-labelled-statements
class LabelledStatement : public Statement {
public:
LabelledStatement(SourceRange source_range, FlyString label, NonnullRefPtr<Statement> labelled_item)
: Statement(source_range)
, m_label(move(label))
, m_labelled_item(move(labelled_item))
{
}
virtual Completion execute(Interpreter&, GlobalObject&) const override;
virtual void dump(int indent) const override;
FlyString const& label() const { return m_label; }
FlyString& label() { return m_label; }
NonnullRefPtr<Statement> const& labelled_item() const { return m_labelled_item; }
NonnullRefPtr<Statement>& labelled_item() { return m_labelled_item; }
private:
FlyString m_label;
NonnullRefPtr<Statement> m_labelled_item;
};
class LabelableStatement : public Statement {
public:
using Statement::Statement;