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

Implement QJSEngine::setDefaultPrototype()

    XMLWordPrintable

Details

    Description

      QScriptEngine provides a convenient way of adding functionality to C++ objects mapped to JS using setDefaultPrototype(). I'd like to see this functionality in QJSEngine as well.

      There are a number of use cases where this feature is needed. For example, it is currently not safe to call C++ functions that can throw exceptions from JS side. Another need is to create functions with a variable number of parameters, because moc doesn't support varargs. (This feature would require QJSEngine::newFunction() and some other additions as well.)

      In short, QJSEngine::setDefaultPrototype() would make it possible to design C++ classes for C++ use and selectively add features that are needed on the JS side only.

      Currently, QML objects on the JS side have an empty prototype object. Thus, adding this feature wouldn't break anything that relies on prototypes. Furthermore, I believe the implementation would be quite easy. QQmlPropertyCache::newQObject() already creates a v8 constructor object using FunctionTemplate, and adding the prototype there is trivial. There may be other affected places, if everything doesn't go through the cache, but you should know better than me.

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            topiolli Topi Mäenpää
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes