Jake said:
No.
Why should it work?
I think there is slight confusion as to what it means for a statement to
be 'enclosing' another.
No, but there was a misconception on my part as to the definition of a label
set:
| 12 Statements
|
| Semantics
|
| 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. A /LabelledStatement/ has no
| semantic meaning other than the introduction of a label to a /label set/.
| The label set of an /IterationStatement/ or a /SwitchStatement/ initially
| contains the single element empty. The label set of any other statement is
| initially empty.
|
| […]
| 12.12 Labelled Statements
|
| The production /Identifier/ : /Statement/ is evaluated by adding
| /Identifier/ to the label set of /Statement/ and then evaluating
| /Statement/. If the /LabelledStatement/ itself has a non-empty label set,
| these labels are also added to the label set of /Statement/ before
| evaluating it. If the result of evaluating Statement is (break, V, L)
| where L is equal to /Identifier/, the production results in (normal, V,
| empty).
|
| Prior to the evaluation of a /LabelledStatement/, the contained
| /Statement/ is regarded as possessing an empty label set, unless it is an
| /IterationStatement/ or a /SwitchStatement/, in which case it is regarded
| as possessing a label set consisting of the single element, empty.
That is, the label set of a statement consists of the labels used for *that*
statement, _not_ the labels used *within* it. Therefore, the following is
syntactically correct and compiles in the named implementation without
error:
function testGoto()
{
var counter = 0;
skipPoint:
{
window.alert(counter);
if (counter === 0)
{
++counter;
break skipPoint;
window.alert("This part is skipped");
}
}
}
However, this does _not_ "simulate goto", i. e. the counter is only shown
once. That is – unless I am overlooking something – intended by the
Specification: The `break' statement with /Identifier/ merely ends the
evaluation of the so labelled statement prematurely:
| A /BreakStatement/ with an /Identifier/ is evaluated as follows:
|
| 1. Return (break, empty, /Identifier/).
See section 12.12 quoted above on how that result affects the evaluation of
the enclosing statement labelled with /Identifier/.
PointedEars