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

Javascript stack trace break with "return" statement

    XMLWordPrintable

Details

    • Windows
    • 8fd3cfe7d0f39a731c585334299f5160ad952df9

    Description

      I've upgrade my project from Qt 5.11.2 to Qt 5.12 and JS engine has changed the stack trace.

      Previously, with QJSEngine, the stack trace saved all function executed in stack, but since 5.12, the stack trace skip getter functions in trace.

      Code :

         StackTest.js

      function	getStack()
      {
      	return (new Error().stack.replace(/\n/g, "\n\t"));
      }
      function testStackRet()
      {
      	return (getStack());
      }
      function testStackTmp()
      {
      	let tmp = getStack();
      	return (tmp);
      }
      

          testing.js (loaded by init.js automatically)

      function	main()
      {
      	System.log("\n\t" + testStackRet()); // System.log is my own logging system, it works.
      	System.log("\n\t" + testStackTmp());
      }
      

      Result :

      LOG(testing.js:3) 
      	getStack@file:$/Lib/StackTest.js:4
      	main@file:testing.js:3
      	%entry@file:init.js:3
      LOG(testing.js:4) 
      	getStack@file:$/Lib/StackTest.js:4
      	testStackTmp@file:$/Lib/StackTest.js:13
      	main@file:testing.js:4
      	%entry@file:init.js:3
      

      testStackRet() forgets a step while in testStackTmp() doesn't. These are the same functions but in the second, the result of the function is saved in a variable before being returned.

      Result in 5.11.2 :

      LOG(testing.js:3) 
      	getStack@file:$/Lib/StackTest.js:4
      	testStackRet@file:$/Lib/StackTest.js:9
      	main@file:testing.js:3
      	%entry@file:init.js:3
      LOG(testing.js:4) 
      	getStack@file:$/Lib/StackTest.js:4
      	testStackTmp@file:$/Lib/StackTest.js:13
      	main@file:testing.js:4
      	%entry@file:init.js:3

      This is very disturbing because I use the stack trace a lot in my operations.

       

      Details :

      main.cpp

      #include <QCoreApplication>
      #include <QJSEngine>
      #include <QDebug>
      
      int						main(int argc, char *argv[])
      {
      	QCoreApplication	a(argc, argv);
      	QJSEngine			*engine;
      
      	engine = new QJSEngine();
      	engine->installExtensions(QJSEngine::Extension::ConsoleExtension);
      
      	qDebug() << qVersion();
      	engine->evaluate(
      				"function	getStack()\n"
      				"{\n"
      				"	return (new Error().stack.replace(/\\n/g, \"\\n\\t\"));\n"
      				"}\n"
      				"function testStackRet()\n"
      				"{\n"
      				"	return (getStack());\n"
      				"}\n"
      				"function testStackTmp()\n"
      				"{\n"
      				"	let tmp = getStack();\n"
      				"	return (tmp);\n"
      				"}\n"
      				"function	main()\n"
      				"{\n"
      				"	console.log(testStackRet());\n"
      				"	console.log(testStackTmp());\n"
      				"}\n"
      				"\n"
      				"main();\n"
      				, "test.js");
      	qDebug() << endl;
      	engine->evaluate(
      				"'use strict';\n"
      				"function	getStack()\n"
      				"{\n"
      				"	return (new Error().stack.replace(/\\n/g, \"\\n\\t\"));\n"
      				"}\n"
      				"function testStackRet()\n"
      				"{\n"
      				"	return (getStack());\n"
      				"}\n"
      				"function testStackTmp()\n"
      				"{\n"
      				"	let tmp = getStack();\n"
      				"	return (tmp);\n"
      				"}\n"
      				"function	main()\n"
      				"{\n"
      				"	console.log(testStackRet());\n"
      				"	console.log(testStackTmp());\n"
      				"}\n"
      				"\n"
      				"main();\n"
      				, "testStrict.js");
      	return (0);
      }
      

      JSEngine.pro

      QT      += core qml
      CONFIG  += console
      

      Attachments

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

        Activity

          People

            erikv Erik Verbruggen
            mondemen Coletta Alexandre
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes