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

Since 4.6, QScriptValue::isFunction() returns true for regular expression objects

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 4.6.0
    • Qt Script
    • None

      QScriptEngine eng;
      qDebug() << eng.newRegExp(QRegExp("foo")).isFunction(); // returned false prior to 4.6

      Similarly, the expression "typeof /foo/" returned "object" prior to 4.6, but now returns "function".

      JavaScriptCore, like SpiderMonkey (FireFox) and V8 (Chrome), allows regular expressions objects to be called as functions, whereas the old QtScript back-end did not.
      Technically, regular expression objects are callable, but they are not functions. Still, QScriptValue::isFunction() behaves like isCallable(), and that's really what it should have been called. (See also http://www.davidflanagan.com/2009/08/typeof-isfuncti.html)

      If you want to treat regular expressions unlike other callable objects, since 4.6 you have to write e.g. object.isFunction() && !object.isRegExp().

        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