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

Issues calling JSON.stringify() on objects

    XMLWordPrintable

Details

    • af1ef35fa0 (qt/qtdeclarative/dev) af1ef35fa0 (qt/tqtc-qtdeclarative/dev) 13a617610a (qt/qtdeclarative/6.3) 13a617610a (qt/tqtc-qtdeclarative/6.3) 13a617610a (qt/qtdeclarative/6.3.2) 13a617610a (qt/tqtc-qtdeclarative/6.3.2)

    Description

      I've been playing around with stuff while trying to figure out if there's a way to control what gets printed when passing a QObject subclass to print()/console.log(). By the way, from reading https://lists.qt-project.org/pipermail/development/2015-November/023713.html, I assume there is no way to do this, but would appreciate confirmation of that.

      #1

      import QtQuick
      import QtQuick.Window
      
      Window {
          id: root
          width: 300
          height: 300
          visible: true
      
          Component.onCompleted: print(JSON.stringify(item))
      
          Item {
              id: item
          }
      }
      

      prints a very descriptive message:

      qrc:/main.qml:10: TypeError: Type error
      

      This should probably not be a type error, but if I'm wrong, it should at least say why it is.

      #2

      import QtQuick
      import QtQuick.Controls
      
      ApplicationWindow {
          id: root
          width: 300
          height: 300
          visible: true
      
          Component.onCompleted: print(JSON.stringify(button))
      
          Button {
              id: button
              text: "Toggle"
              onClicked: fileDialog.visible = !fileDialog.visible
          }
      }
      

      prints a huge string, as is probably expected.

      #3

      This is the interesting one. If I have https://codereview.qt-project.org/c/qt/qtquickcontrols2/+/318565 checked out and run this code

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Dialogs
      import QtQuick.Layouts
      
      ApplicationWindow {
          id: root
          width: 800
          height: 600
          visible: true
      //    title: fileDialog.currentFile
          title: "activeFocusItem: " + activeFocusItem
      
          Component.onCompleted: print(JSON.stringify(button))
      
          Button {
              id: button
              text: "Toggle"
              onClicked: fileDialog.visible = !fileDialog.visible
          }
      
          FileDialog {
              id: fileDialog
              title: "Open File"
              currentFolder: "file:///Users/mitch/dev/qt-dev/qtbase/src/corelib"
              nameFilters: ["All files (*)", "Text files (*.txt)", "HTML files (*.html *.htm)"]
              visible: true
          }
      }
      

      I get:

      15:26:02: Starting /Users/mitch/dev/temp/quick-qt_dev_debug_non_fw-Debug/quick.app/Contents/MacOS/quick ...
      QML debugging is enabled. Only use this in a safe environment.
      AddressSanitizer:DEADLYSIGNAL
      =================================================================
      ==5738==ERROR: AddressSanitizer: stack-overflow on address 0x7ffeecd25e48 (pc 0x0001101dd27f bp 0x7ffeecd26690 sp 0x7ffeecd25e50 T0)
          #0 0x1101dd27f in __asan_memcpy+0x18f (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4727f)
          #1 0x10e5dc9c9 in int (anonymous namespace)::UnrollTailLoop<2u>::exec<int, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, unsigned long>(unsigned long, int, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, unsigned long) qstring.cpp:244
          #2 0x10e5dc555 in int (anonymous namespace)::UnrollTailLoop<3u>::exec<int, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, unsigned long>(unsigned long, int, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, ucstrncmp(QChar const*, QChar const*, unsigned long)::$_9, unsigned long) qstring.cpp:244
          #3 0x10e5dbe0d in ucstrncmp(QChar const*, QChar const*, unsigned long) qstring.cpp:1005
          #4 0x10e57d4f7 in ucstrcmp(QChar const*, unsigned long, QChar const*, unsigned long) qstring.cpp:1202
          #5 0x10e5804fc in QtPrivate::compareStrings(QStringView, QStringView, Qt::CaseSensitivity) qstring.cpp:1328
          #6 0x109e83a21 in operator==(QString const&, QString const&) qstring.h:847
          #7 0x10a534cb5 in QV4::IdentifierTable::asPropertyKeyImpl(QV4::Heap::String const*) qv4identifiertable.cpp:196
          #8 0x10a4969bd in QV4::IdentifierTable::asPropertyKey(QV4::Heap::String const*) qv4identifiertable_p.h:88
          #9 0x10a530cc5 in QV4::IdentifierTable::asPropertyKey(QV4::String const*) qv4identifiertable_p.h:91
          #10 0x10a7bda02 in QV4::String::createPropertyKeyImpl() const qv4string.cpp:166
          #11 0x10a2b877a in QV4::StringOrSymbol::createPropertyKey() const qv4string_p.h:282
          #12 0x10a2acba0 in QV4::StringOrSymbol::toPropertyKey() const qv4string_p.h:287
          #13 0x10b0a7819 in QQmlValueTypeWrapperOwnPropertyKeyIterator::next(QV4::Object const*, QV4::Property*, QV4::PropertyAttributes*) qqmlvaluetypewrapper.cpp:340
          #14 0x10a5d2c4a in QV4::ObjectIterator::next(QV4::Property*, QV4::PropertyAttributes*) qv4objectiterator.cpp:64
          #15 0x10a5d37c4 in QV4::ObjectIterator::nextPropertyNameAsString(QV4::Value*) qv4objectiterator.cpp:103
          #16 0x10a568a80 in Stringify::JO(QV4::Object*) qv4jsonobject.cpp:798
          #17 0x10a565893 in Stringify::Str(QString const&, QV4::Value const&) qv4jsonobject.cpp:756
          #18 0x10a569db4 in Stringify::makeMember(QString const&, QV4::Value const&) qv4jsonobject.cpp:766
          #19 0x10a568b74 in Stringify::JO(QV4::Object*) qv4jsonobject.cpp:802
          #20 0x10a565893 in Stringify::Str(QString const&, QV4::Value const&) qv4jsonobject.cpp:756
          #21 0x10a569db4 in Stringify::makeMember(QString const&, QV4::Value const&) qv4jsonobject.cpp:766
          #22 0x10a568b74 in Stringify::JO(QV4::Object*) qv4jsonobject.cpp:802
          #23 0x10a565893 in Stringify::Str(QString const&, QV4::Value const&) qv4jsonobject.cpp:756
          #24 0x10a569db4 in Stringify::makeMember(QString const&, QV4::Value const&) qv4jsonobject.cpp:766
          #25 0x10a568b74 in Stringify::JO(QV4::Object*) qv4jsonobject.cpp:802
          #26 0x10a565893 in Stringify::Str(QString const&, QV4::Value const&) qv4jsonobject.cpp:756
          #27 0x10a569db4 in Stringify::makeMember(QString const&, QV4::Value const&) qv4jsonobject.cpp:766
          #28 0x10a568b74 in Stringify::JO(QV4::Object*) qv4jsonobject.cpp:802
          #29 0x10a565893 in Stringify::Str(QString const&, QV4::Value const&) qv4jsonobject.cpp:756
          #30 0x10a569db4 in Stringify::makeMember(QString const&, QV4::Value const&) qv4jsonobject.cpp:766
      

      I would not expect this to crash. If it's due to recursion, perhaps it should have some limit and just print a warning before hitting it.

      Attachments

        Issue Links

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

          Activity

            People

              ulherman Ulf Hermann
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes