Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-15571 QtScript: Deprecate APIs that reflect implementation of old ("classic") back-end
  3. QTBUG-15848

Deprecate QScriptEngine::newQObject() overload that takes existing script object as argument

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Invalid
    • P2: Important
    • 4.8.0
    • Qt Script
    • None

    Description

      Doc: http://doc.trolltech.com/4.7/qscriptengine.html#newQObject-2

      The use case for this overload is to "promote" an existing script object to a QObject wrapper object. For example, a factory method for QFoo could look like this:

      static QScriptValue constructFoo(QScriptContext *ctx, QScriptEngine *eng)
      {
          if (ctx->isCalledAsConstructor())
              return eng->newQObject(ctx->thisObject(), new QFoo());
          return ctx->throwError("Please use 'new' operator");
      }
      

      When the script "new QFoo" is executed, the VM constructs a standard JS object and passes it as the thisObject() to constructFoo. We then effectively change the type ([[Class]] in ECMA spec speak) to be a QObject wrapper. This avoids a wasted object allocation (calling the "normal" newQObject(), which returns a brand new object), and also means we don't have to worry about preserving the prototype relationship (the _proto_ of the thisObject() will be QFoo.prototype, as expected).

      The problem with this API is that this is not how JavaScriptCore or V8 implement objects. There is no mutable [[Class]] property like we had in the QtScript "classic" back-end. Once an object has been created, its class can't be changed.

      The way we solve this currently is by implementing a special QScriptObject class which has a delegate (corresponding to [[Class]]) which provides the necessary level of indirection. However, this is slow, and it only works for objects that are subclasses of QScriptObject (i.e. those we implement), not any JS object. We'd like to get rid of this, and have the same constraint as JavaScriptCore/V8; once an object has been constructed, its [[Class]] can't be changed.

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes