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 757 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on 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

    JonBJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      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++.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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....

      SPlattenS 2 Replies Last reply
      1
      • JonBJ JonB

        @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....

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on 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
        • JonBJ JonB

          @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....

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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

            SPlattenS 2 Replies Last reply
            1
            • SGaistS SGaist

              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.

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #6

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

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • SGaistS SGaist

                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.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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

                  • Login

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