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

[Reg 6.5.1->6.5.3] QJSEngine no longer converts new'ed JS object to QVariantMap

    XMLWordPrintable

Details

    • 4d7ce35bd (dev), bc4e1d74e (6.7), 2b3997e29 (6.6), 301cae0a7 (tqtc/lts-6.5)

    Description

      It looks like the fix for QTBUG-115523 was incomplete. In the test below, only Jane's test produces the expected output - John's test does not.

       

      Code

      // test.js
      function Person(firstName, lastName) {
          this.firstName = firstName;
          this.lastName = lastName;
      }
      
      function greet(person) {
          console.log(`Hello, ${person.firstName} ${person.lastName}!`);
      }
      
      function testJohn() {
          let john = new Person("John", "Doe");
          greet(john);
          return john;
      }
      
      function testJane() {
          let jane = {
              firstName: "Jane",
              lastName: "Doe"
          };
          greet(jane);
          return jane;
      }
      
      // main.cpp
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          QFile script(":/test.js");
          script.open(QFile::ReadOnly|QFile::Text);
      
          QJSEngine engine;
          engine.installExtensions(QJSEngine::ConsoleExtension); // add console.log()
          engine.evaluate(script.readAll());
      
          qDebug() << engine.evaluate("testJane()").toVariant();
          qDebug() << engine.evaluate("testJohn()").toVariant();
      }
      

       

      Expected output (Qt 6.5.1 and older)

      js: Hello, Jane Doe!
      QVariant(QVariantMap, QMap(("firstName", QVariant(QString, "Jane"))("lastName", QVariant(QString, "Doe"))))
      js: Hello, John Doe!
      QVariant(QVariantMap, QMap(("firstName", QVariant(QString, "John"))("lastName", QVariant(QString, "Doe"))))
      

       

      Actual output (Qt 6.5.3 and newer)

      js: Hello, Jane Doe!
      QVariant(QVariantMap, QMap(("firstName", QVariant(QString, "Jane"))("lastName", QVariant(QString, "Doe"))))
      js: Hello, John Doe!
      QVariant(QJSValue, )
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-119963
          # Subject Branch Project Status CR V

          Activity

            People

              fabiankosmale Fabian Kosmale
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes