Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContainsUndefinedContinueTarget needs a BlockStatement implementation #2481

Closed
scole66 opened this issue Aug 5, 2021 · 1 comment · Fixed by #2482
Closed

ContainsUndefinedContinueTarget needs a BlockStatement implementation #2481

scole66 opened this issue Aug 5, 2021 · 1 comment · Fixed by #2482
Labels
normative change Affects behavior required to correctly evaluate some ECMAScript source text spec bug web reality

Comments

@scole66
Copy link

scole66 commented Aug 5, 2021

Description: The Static Semantics function ContainsUndefinedContinueTarget needs (at least) one more not-default implementation.

This function takes two arguments, an iteration_set, which contains labels a continue statement may use, and label_set, a list of labels which might get added to the iteration_set, if they apply to iteration statements.
Specified implementations except for LabelledStatement and BreakableStatement always reset the label_set parameter to the empty list (as it's clear their productions are not iteration statements).
The default implementation, however, does not clear the label set.

Consider: lbl : { for ( ;; ) continue lbl ; }

This is an undefined continue target. The BlockStatement labelled by lbl is not an iteration statement. Web reality produces a syntax error here.

The production tree looks like

    LabelledStatement : LabelIdentifier : LabelledItem
    └── LabelledItem : Statement
        └── Statement : BlockStatement
            └── BlockStatement : Block
                └── Block : { StatementList }
                    └── StatementList : StatementListItem
                        └── StatementListItem : Statement
                            └── Statement : BreakableStatement
                                └── BreakableStatement : IterationStatement

ContainsUndefinedContinueTarget for the first production adds lbl to the label set.
All the remaining productions prior to the BreakableStatement use the default implementation.
The BreakableStatement moves the label set (containing lbl) into the iteration set and thus makes this label seem like a valid target.

(If we actually tried to execute this code, the loop executor functions would actually treat that continue statement like a break statement, and the seemingly infinite loop would actually terminate at the first iteration.)

Fix:
The clearest fix would seem to be to add an implementation for the Statement : BlockStatement production:

  1. Return ContainsUndefinedContinueTarget of BlockStatement with arguments iterationSet and « ».

This error seems to have been in every ECMAScript spec since the static semantics system was added in ES 6. (In particular, this issue was not due to the recent refactoring of syntax directed operations.)

@bakkot bakkot added normative change Affects behavior required to correctly evaluate some ECMAScript source text spec bug web reality labels Aug 5, 2021
@bakkot
Copy link
Contributor

bakkot commented Aug 5, 2021

Huh, yup, looks like a bug. Since the current semantics are coherent, even though they don't match web reality, I think we'll need consensus to change this, but that should be easy to get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
normative change Affects behavior required to correctly evaluate some ECMAScript source text spec bug web reality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants