Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting JavaScript stack trace in C++ function ?
Forum Updated to NodeBB v4.3 + New Features

Getting JavaScript stack trace in C++ function ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 755 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SPlatten
    wrote on 20 Mar 2021, 08:46 last edited by
    #1

    I am making C++ calls from JavaScript which is all working fine, what I want to explore and add is a way to identify the JavaScript call stack when the C++ call is made.

    I know I can do this in JavaScript, but I if possible I want to add this functionality to specific C++ function calls so the caller doesn't have to do it.

    This is for logging purposes, I want if possible to get the JavaScript file name, function name (if called from a function) and line number in the file.

    I know I can do this from JavaScript, but if possible I want to do it in the C++.

    Kind Regards,
    Sy

    J 1 Reply Last reply 20 Mar 2021, 09:50
    0
    • S SPlatten
      20 Mar 2021, 08:46

      I am making C++ calls from JavaScript which is all working fine, what I want to explore and add is a way to identify the JavaScript call stack when the C++ call is made.

      I know I can do this in JavaScript, but I if possible I want to add this functionality to specific C++ function calls so the caller doesn't have to do it.

      This is for logging purposes, I want if possible to get the JavaScript file name, function name (if called from a function) and line number in the file.

      I know I can do this from JavaScript, but if possible I want to do it in the C++.

      J Offline
      J Offline
      JonB
      wrote on 20 Mar 2021, 09:50 last edited by
      #2

      @SPlatten said in Getting JavaScript stack trace in C++ function ?:

      JavaScript call stack when the C++ call is made

      Based on nothing but intuition, so take with a pinch of salt, I would have said this is "not possible", or at least difficult and I don't know how you would do it. Till someone else tells you otherwise....

      S 2 Replies Last reply 20 Mar 2021, 12:11
      1
      • J JonB
        20 Mar 2021, 09:50

        @SPlatten said in Getting JavaScript stack trace in C++ function ?:

        JavaScript call stack when the C++ call is made

        Based on nothing but intuition, so take with a pinch of salt, I would have said this is "not possible", or at least difficult and I don't know how you would do it. Till someone else tells you otherwise....

        S Offline
        S Offline
        SPlatten
        wrote on 20 Mar 2021, 12:11 last edited by SPlatten
        #3

        @JonB, that was exactly my thoughts, no harm in asking tho as I'm never surprised to learn something new. From another post is sounds like its possible using the Google V8 API which provides this kind of functionality for Node modules written in C/C++. However this isn't a node module.

        I have written node modules before.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • J JonB
          20 Mar 2021, 09:50

          @SPlatten said in Getting JavaScript stack trace in C++ function ?:

          JavaScript call stack when the C++ call is made

          Based on nothing but intuition, so take with a pinch of salt, I would have said this is "not possible", or at least difficult and I don't know how you would do it. Till someone else tells you otherwise....

          S Offline
          S Offline
          SPlatten
          wrote on 20 Mar 2021, 15:19 last edited by SPlatten
          #4

          @JonB It looks like what I am asking is possible through the QScriptContext Class and the backtrace function.

          I will investigate this now.

          mmm...According to the documentation:
          https://doc.qt.io/qt-5/qscriptcontext.html

          It should be available, I've added script to my pro file, but after including the header QScriptContext, its underlined with 'QScriptContext ' file not found to the right of it.

          What am I missing? I'm using Qt 5.15.2

          Kind Regards,
          Sy

          1 Reply Last reply
          1
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 20 Mar 2021, 20:04 last edited by
            #5

            Hi,

            You missed that it's part of the deprecated and already removed QtScript module. It's still available as sources IIRC but you'll have to build it yourself.

            If you are using QJSEngine, the error retrieval is described in the class documentation.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 2 Replies Last reply 21 Mar 2021, 07:50
            1
            • S SGaist
              20 Mar 2021, 20:04

              Hi,

              You missed that it's part of the deprecated and already removed QtScript module. It's still available as sources IIRC but you'll have to build it yourself.

              If you are using QJSEngine, the error retrieval is described in the class documentation.

              S Offline
              S Offline
              SPlatten
              wrote on 21 Mar 2021, 07:50 last edited by SPlatten
              #6

              @SGaist , thank you, this is such a useful feature.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • S SGaist
                20 Mar 2021, 20:04

                Hi,

                You missed that it's part of the deprecated and already removed QtScript module. It's still available as sources IIRC but you'll have to build it yourself.

                If you are using QJSEngine, the error retrieval is described in the class documentation.

                S Offline
                S Offline
                SPlatten
                wrote on 21 Mar 2021, 10:22 last edited by
                #7

                @SGaist , it would appear that I can only get the properties if an exception is thrown. Is there another way to get the call stack information, such as File name, function if relevant and line number inside a C++ call that has been called from JavaScript ?

                Kind Regards,
                Sy

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 21 Mar 2021, 13:54 last edited by
                  #8

                  That I do not know, sorry.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  3/8

                  20 Mar 2021, 12:11

                  5 unread
                  • Login

                  • Login or register to search.
                  3 out of 8
                  • First post
                    3/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved