Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123377

JS Set iteration does not follow spec

    XMLWordPrintable

Details

    Description

      It is supposed to be safe to insert / delete elements of a set during iteration however the following code is producing different output when run in QML vs Firefox

      let set = new Set([1,2,3]);
      set.forEach((v) => {
        console.log(v)
        set.delete(v)
      }) 

      Firefox output:

      1
      2
      3
      

      QML output:

      1
      3
      

      The spec seems to suggest that this should work:

      Each value is normally visited only once. However, a value will be revisited if it is deleted after it has been visited and then re-added before the forEach call completes. Values that are deleted after the call to forEach begins and before being visited are not visited unless the value is added again before the forEach call completes. New values added after the call to forEach begins are visited.

      https://tc39.es/ecma262/#sec-set.prototype.foreach

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            haiku Ollie Dawes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes