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

QScriptEngine does not return evaluated value when value is a function

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • 4.7.1
    • 4.6.0
    • Qt Script
    • None

    Description

      I have only tested this in the 4.6 beta for mac.

      in QT 4.5, in the following code:
      val=engine.evaluate("function()

      {return true}");
      val would equal a QScriptValue containing the function. This is not the case in qt 4.6 beta. Instead it now throws a syntax error. There does not seem to be a way to get a function returned from evaluate.

      test case:

      #include <QtCore/QCoreApplication>
      #include <QScriptEngine>
      #include <QDebug>
      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);
      QScriptEngine engine;
      QScriptValue val;
      val=engine.evaluate("return true;");
      qDebug() << val.toString();
      val=engine.evaluate("function(){return true}

      ");
      qDebug() << val.toString();
      val=engine.evaluate("var myfunc=function()

      {return true}");
      qDebug() << val.toString();
      val=engine.evaluate("var myfunc=function(){return true}

      ;return myfunc;");
      qDebug() << val.toString();
      val=engine.evaluate("2+2");
      qDebug() << val.toString();
      return a.exec();
      }

      The output I receive:

      "SyntaxError: Invalid return statement."
      "SyntaxError: Parse error"
      "undefined"
      "SyntaxError: Invalid return statement."
      "4"

      Attachments

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

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            jordanw Jordan Wambaugh
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes