14.13 Labelled Statements

Syntax

LabelledStatement[Yield, Await, Return] : LabelIdentifier[?Yield, ?Await] : LabelledItem[?Yield, ?Await, ?Return] LabelledItem[Yield, Await, Return] : Statement[?Yield, ?Await, ?Return] FunctionDeclaration[?Yield, ?Await, ~Default] Note

A Statement may be prefixed by a label. Labelled statements are only used in conjunction with labelled break and continue statements. ECMAScript has no goto statement. A Statement can be part of a LabelledStatement, which itself can be part of a LabelledStatement, and so on. The labels introduced this way are collectively referred to as the “current label set” when describing the semantics of individual statements.

14.13.1 Static Semantics: Early Errors

LabelledItem : FunctionDeclaration
  • It is a Syntax Error if any source text matches this rule.
Note

An alternative definition for this rule is provided in B.3.2.

14.13.2 Static Semantics: IsLabelledFunction ( stmt )

The abstract operation IsLabelledFunction takes argument stmt. It performs the following steps when called:

  1. If stmt is not a LabelledStatement, return false.
  2. Let item be the LabelledItem of stmt.
  3. If item is LabelledItem : FunctionDeclaration , return true.
  4. Let subStmt be the Statement of item.
  5. Return IsLabelledFunction(subStmt).

14.13.3 Runtime Semantics: Evaluation

LabelledStatement : LabelIdentifier : LabelledItem
  1. Let newLabelSet be a new empty List.
  2. Return LabelledEvaluation of this LabelledStatement with argument newLabelSet.

14.13.4 Runtime Semantics: LabelledEvaluation

With parameter labelSet.

BreakableStatement : IterationStatement
  1. Let stmtResult be LoopEvaluation of IterationStatement with argument labelSet.
  2. If stmtResult.[[Type]] is break, then
    1. If stmtResult.[[Target]] is empty, then
      1. If stmtResult.[[Value]] is empty, set stmtResult to NormalCompletion(undefined).
      2. Else, set stmtResult to NormalCompletion(stmtResult.[[Value]]).
  3. Return Completion(stmtResult).
BreakableStatement : SwitchStatement
  1. Let stmtResult be the result of evaluating SwitchStatement.
  2. If stmtResult.[[Type]] is break, then
    1. If stmtResult.[[Target]] is empty, then
      1. If stmtResult.[[Value]] is empty, set stmtResult to NormalCompletion(undefined).
      2. Else, set stmtResult to NormalCompletion(stmtResult.[[Value]]).
  3. Return Completion(stmtResult).
Note 1

A BreakableStatement is one that can be exited via an unlabelled BreakStatement.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Let label be the StringValue of LabelIdentifier.
  2. Append label as an element of labelSet.
  3. Let stmtResult be LabelledEvaluation of LabelledItem with argument labelSet.
  4. If stmtResult.[[Type]] is break and SameValue(stmtResult.[[Target]], label) is true, then
    1. Set stmtResult to NormalCompletion(stmtResult.[[Value]]).
  5. Return Completion(stmtResult).
LabelledItem : FunctionDeclaration
  1. Return the result of evaluating FunctionDeclaration.
Statement : BlockStatement VariableStatement EmptyStatement ExpressionStatement IfStatement ContinueStatement BreakStatement ReturnStatement WithStatement ThrowStatement TryStatement DebuggerStatement
  1. Return the result of evaluating Statement.
Note 2

The only two productions of Statement which have special semantics for LabelledEvaluation are BreakableStatement and LabelledStatement.