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

Javascript: function.toString() not working

    XMLWordPrintable

Details

    Description

      Using Javascript in an QML application and retrieving the function code as string stopped working:

      function test(parameter) {
          console.log("Something to do!");
      }
      ...
      function otherFunction(otherParam) {
          console.log("Output: "+test.toString());
      }
      

      All this does is to print the following:

      "Output: function() { [code] }"
      

      instead of the desired string:

      "Output: function() { console.log("Something to do!"); }"
      

      According to 5th edition of ECMA-262 , section 15.3.4.2, Function.prototype.toString() should return an implementation-defined rendition having a syntax of FunctionDeclaration. So perhaps Qt's JS engine here exhibits nonstandard behavior (c.f. Stack Overflow answer ).

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ulherman Ulf Hermann
              PhilLab Philipp Hasper
              Votes:
              5 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes