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

Wrapper method that should create and return a Javascript Generator object returns undefined

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.7
    • 6.4.2
    • None
    • package qt6-declarative-6.4.2-1 from Arch Linux repository

    Description

      See the example Javascript code below. In the code, the method `generatorZero` should return a Generator object, but it instead returns `undefined`.

      If you first store the Generator in a variable before returning it, it works as expected. This is demonstrated with the method `generatorZeroWorkaround`.

      class Class {
          *generatorFrom(start) {
              while (true) {
                  yield start++;
              }
          }
      
          generatorZero() {
              return this.generatorFrom(0);
          }
      
          generatorZeroWorkaround() {
              const g = this.generatorFrom(0);
              return g;
          }
      }
      
      const c = new Class();
      print(c.generatorZero()); // undefined
      print(c.generatorZeroWorkaround()); // [object Generator]
      

      Steps to reproduce:

      1. Put the above code in a file named bug.js
      2. In the same directory create a file named bug.qml with the following contents:
        import QtQuick 6.0
        import "bug.js" as Logic
        
        Item {}
      1. Run `qml bug.qml` and observe the output of the command

       

      Attachments

        1. bug.js
          0.4 kB
          Peter Fajdiga
        2. bug.qml
          0.1 kB
          Peter Fajdiga

        Activity

          People

            qtqmlteam Qt Qml Team User
            ptr Peter Fajdiga
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: