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

Assertion error by accessing this from onSignal arrow function

    XMLWordPrintable

Details

    • 8cd7aabfb24b391143b3c358f49fb6a28765d5f3 (qt/qtdeclarative/dev) 4d391ad2968efccf0ec5f2840126f051b40a89f9 (qt/qtdeclarative/6.2)

    Description

      (Tested with the current dev branch)

      The following code crashes probably because local variable "this" doesn't exist.

      Item {
          Component.onCompleted: () => {
              console.log(this);
          }
      }
      

      I'm not sure what should this be bound to. Since this is the difference from normal function, it makes sense that "this" in arrow function is translated to a plain LoadLocal instruction.
      But what is this in the context where the arrow function is defined?

      (lldb) bt
      * thread #1, name = 'qml', stop reason = signal SIGABRT
        * frame #0: 0x00007ffff5416ce1 libc.so.6`__GI_raise(sig=<unavailable>) at raise.c:51:1
          frame #1: 0x00007ffff5400537 libc.so.6`__GI_abort at abort.c:79:7
          frame #2: 0x00007ffff5b6509d libQt6Core.so.6`::qt_message_fatal((null)=QtFatalMsg, context=0x00007fffffff7f90, message=0x00007fffffff7e70) at qlogging.cpp:1898:15
          frame #3: 0x00007ffff5b61318 libQt6Core.so.6`QMessageLogger::fatal(this=0x00007fffffff7f90, msg="ASSERT: \"%s\" in file %s, line %d") const at qlogging.cpp:890:21
          frame #4: 0x00007ffff5b566c2 libQt6Core.so.6`qt_assert(assertion="index < alloc", file="/home/yuya/work/qt/qt-dev/qtdeclarative/src/qml/jsruntime/qv4value_p.h", line=522) at qglobal.cpp:3281:46
          frame #5: 0x00007ffff7b99525 libQt6Qml.so.6`QV4::ValueArray<40ul>::operator[](this=0x00007fff7ec45468, index=0) const at qv4value_p.h:522:9
          frame #6: 0x00007ffff7cec523 libQt6Qml.so.6`QV4::Moth::VME::interpret(frame=0x00007fffffffa600, engine=0x00005555557dc5d0, code="\xc4\t\U00000018\n\xac\U00000001\a\U00000001\n\U0000000e\U00000002") at qv4vme_moth.cpp:628:31
          frame #7: 0x00007ffff7ceb9d9 libQt6Qml.so.6`QV4::Moth::VME::exec(frame=0x00007fffffffa600, engine=0x00005555557dc5d0) at qv4vme_moth.cpp:555:27
          frame #8: 0x00007ffff7c14c12 libQt6Qml.so.6`QV4::Function::call(this=0x0000555555806730, thisObject=0x00007fffa03ba4f0, argv=0x00007fffa03ba4f0, argc=0, context=0x00007ffff18e7040) at qv4function.cpp:98:43
          frame #9: 0x00007ffff7c148f6 libQt6Qml.so.6`operator(__closure=0x00007fffffffa7b0, thisObject=0x00007fffa03ba4f0, argv=0x00007fffa03ba4f0, argc=0) at qv4function.cpp:67:24
          frame #10: 0x00007ffff7c157dd libQt6Qml.so.6`QV4::convertAndCall<QV4::Function::call(QObject*, void**, const QMetaType*, int, QV4::ExecutionContext*)::<lambda(const QV4::Value*, const QV4::Value*, int)> >(engine=0x00005555557dc5d0, thisObject=0x00005555555c5f70, a=0x00007fffffffa9b0, types=0x00007fffffffa9a8, argc=0, call=(anonymous struct) @ 0x00007fffffffa7b0)) at qv4jscall_p.h:229:37
          frame #11: 0x00007ffff7c1497c libQt6Qml.so.6`QV4::Function::call(this=0x0000555555806730, thisObject=0x00005555555c5f70, a=0x00007fffffffa9b0, types=0x00007fffffffa9a8, argc=0, context=0x00007ffff18e7040) at qv4function.cpp:64:35
          frame #12: 0x00007ffff7dbccc6 libQt6Qml.so.6`QQmlJavaScriptExpression::evaluate(this=0x00007fff74005410, a=0x00007fffffffa9b0, types=0x00007fffffffa9a8, argc=0) at qqmljavascriptexpression.cpp:309:50
          frame #13: 0x00007ffff7d52f29 libQt6Qml.so.6`QQmlBoundSignalExpression::evaluate(this=0x00007fff74005410, a=0x0000000000000000) at qqmlboundsignal.cpp:218:43
          frame #14: 0x00007ffff7d533b9 libQt6Qml.so.6`QQmlBoundSignal_callback(e=0x000055555581b970, a=0x0000000000000000) at qqmlboundsignal.cpp:333:34
          frame #15: 0x00007ffff7df4c98 libQt6Qml.so.6`QQmlNotifier::emitNotify(endpoint=0x0000000000000000, a=0x0000000000000000) at qqmlnotifier.cpp:104:60
          frame #16: 0x00007ffff7d76138 libQt6Qml.so.6`QQmlData::signalEmitted((null)=0x0000555555809170, object=0x000055555582afc0, index=3, a=0x0000000000000000) at qqmlengine.cpp:633:41
          frame #17: 0x00007ffff5c74540 libQt6Core.so.6`void doActivate<false>(sender=0x000055555582afc0, signal_index=3, argv=0x0000000000000000) at qobject.cpp:3816:48
          frame #18: 0x00007ffff5c6d159 libQt6Core.so.6`QMetaObject::activate(sender=0x000055555582afc0, m=0x00007ffff7fa32e0, local_signal_index=0, argv=0x0000000000000000) at qobject.cpp:3984:26
          frame #19: 0x00007ffff7a537c7 libQt6Qml.so.6`QQmlComponentAttached::completed(this=0x000055555582afc0) at moc_qqmlcomponentattached_p.cpp:156:26
          frame #20: 0x00007ffff7dfe67b libQt6Qml.so.6`QQmlObjectCreator::finalize(this=0x00005555556a8af0, interrupt=0x00007fffffffc7b0) at qqmlobjectcreator.cpp:1479:30
          frame #21: 0x00007ffff7d56e82 libQt6Qml.so.6`QQmlComponentPrivate::complete(enginePriv=0x00005555557dbcb0, state=0x00005555555d4cf8) at qqmlcomponent.cpp:1010:33
          frame #22: 0x00007ffff7d572a5 libQt6Qml.so.6`QQmlComponentPrivate::completeCreate(this=0x00005555555d4c50) at qqmlcomponent.cpp:1102:17
          frame #23: 0x00007ffff7d57194 libQt6Qml.so.6`QQmlComponent::completeCreate(this=0x00005555558266c0) at qqmlcomponent.cpp:1089:22
          frame #24: 0x00007ffff7d563e7 libQt6Qml.so.6`QQmlComponent::create(this=0x00005555558266c0, context=0x0000000000000000) at qqmlcomponent.cpp:832:23
          frame #25: 0x00007ffff7d3907d libQt6Qml.so.6`QQmlApplicationEnginePrivate::finishLoad(this=0x00005555557dbcb0, c=0x00005555558266c0) at qqmlapplicationengine.cpp:154:60
          frame #26: 0x00007ffff7d38e53 libQt6Qml.so.6`QQmlApplicationEnginePrivate::startLoad(this=0x00005555557dbcb0, url=0x00007fffffffcb78, data=0x00007fffffffcb30, dataFlag=false) at qqmlapplicationengine.cpp:138:19
          frame #27: 0x00007ffff7d3946f libQt6Qml.so.6`QQmlApplicationEngine::load(this=0x00007fffffffcdb0, url=0x00007fffffffcb78) at qqmlapplicationengine.cpp:291:17
          frame #28: 0x0000555555570f63 qml`main(argc=2, argv=0x00007fffffffe1e8) at main.cpp:607:15
          frame #29: 0x00007ffff5401d0a libc.so.6`__libc_start_main(main=(qml`main at main.cpp:370:1), argc=2, argv=0x00007fffffffe1e8, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe1d8) at libc-start.c:308:16
          frame #30: 0x000055555556939a qml`_start + 42
      
      (lldb) f 6
      frame #6: 0x00007ffff7cec523 libQt6Qml.so.6`QV4::Moth::VME::interpret(frame=0x00007fffffffa600, engine=0x00005555557dc5d0, code="\xc4\t\U00000018\n\xac\U00000001\a\U00000001\n\U0000000e\U00000002") at qv4vme_moth.cpp:628:31
         625      MOTH_BEGIN_INSTR(LoadLocal)
         626          auto cc = static_cast<Heap::CallContext *>(STACK_VALUE(CallData::Context).m());
         627          Q_ASSERT(cc->type != QV4::Heap::CallContext::Type_GlobalContext);
      -> 628          acc = cc->locals[index].asReturnedValue();
         629      MOTH_END_INSTR(LoadLocal)
         630 
         631      MOTH_BEGIN_INSTR(StoreLocal)
      
      (lldb) p *cc
      (QV4::Heap::CallContext) $0 = {
        QV4::Heap::ExecutionContext = {
          QV4::Heap::Base = {
            internalClass = {
              ptr = 0x00007fff7ec00700
            }
          }
          QV4::Heap::ExecutionContextData = {
            outer = {
              ptr = 0x00007fff7ec115c0
            }
            activation = {
              ptr = 0x00007fff7ec453e0
            }
          }
          type = 3
          nArgs = 0
          padding_ = ""
        }
        QV4::Heap::CallContextData = {
          function = {
            ptr = 0x0000000000000000
          }
          locals = {
            size = 0
            alloc = 0
            values = {
              [0] = {
                QV4::StaticValue = (_val = 0)
              }
            }
          }
        }
      }
      

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            yuja Yuya Nishihara
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes