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

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

XMLWordPrintable

    • 07652bcbd (dev), d9655bd53 (6.8), e9e5e5ac7 (6.7), 9f51221dd (tqtc/lts-6.5)

      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

       

        1. bug.js
          0.4 kB
        2. bug.qml
          0.1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            diseraluca Luca Di Sera
            ptr Peter Fajdiga
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes