Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16571 Resolve QtScript behavior that reflects implementation of old ("classic") back-end
  3. QTBUG-16573

"arguments" variable when calling QScriptEngine::evaluate() from a native function

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Invalid
    • Icon: P4: Low P4: Low
    • None
    • Qt Script
    • None

      This behavior is tested by tst_QScriptContext::argumentsObjectInNative().

      static QScriptValue fun(QScriptContext *ctx, QScriptEngine *eng)
      {
          return eng->evaluate("arguments[0]");
      }
      ...
      QScriptEngine eng;
      eng.globalObject().setProperty("fun", eng.newFunction(fun));
      qDebug() << eng.evaluate("fun(123)").toString(); // should print "123"
      

      Rationale:
      The QtScript doc says (http://doc.trolltech.com/4.7/qscriptengine.html): "[QScriptEngine::evaluate()] is the C++ equivalent of the built-in script function eval()".

      Compare to this JS program:

      function fun() { return eval("arguments[0]"); }
      fun(123); // returns 123
      

      Hence, the native behavior is consistent.
      So long as QScriptEngine::evaluate() evaluates the script in the current context (as opposed to in the global context), this behavior should be unsurprising.
      However, this behavior isn't supported by neither JavaScriptCore nor V8 "out of the box".

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

            kenthans Kent Hansen (Inactive)
            kenthans Kent Hansen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes