Skip to content

"For each" is not clear what happens if the list is modified while iterating #396

@domenic

Description

@domenic

Apparently I do this sometimes: https://wicg.github.io/app-history/#inform-app-history-about-canceling-traversals step 2 calls into https://wicg.github.io/app-history/#finalize-with-an-aborted-navigation-error which in step 10.2 will remove the item from the list.

Options:

  1. Disallow this and force the spec to make a copy of the list before iterating
  2. Create a copy automatically when the iteration starts
  3. Do something more complicated where deletions are handled transparently. I think this would look like:
    • If you delete something from the list before the currently-being-iterated value, that's OK. We ensure that it's you move on to the next value correctly (and don't e.g. skip forward 2 as an index-based approach would).
    • If you delete the currently-being-iterated value, that's OK. We ensure that you move on to the next value correctly (and don't e.g. skip forward 2 as an index-based approach would).
    • If you delete something after the currently-being-iterated value, that's OK. We ensure that it won't be seen in the rest of the iteration.

Thoughts welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions