Details

    • Sub-task
    • Resolution: Invalid
    • P3: Somewhat important
    • 4.8.0
    • Qt Script
    • None

    Description

      Being able to arbitrarily change the class of an object after it has been constructed isn't good.

      The use case for setScriptClass() is when implementing a constructor function for a custom QScriptClass object. The constructor can be called from the "new" operator in JS, in which case the VM will provide a default-constructed (plain) script object. You can then use setScriptClass() to "promote" the plain object to an instance of your class:

      if (ctx->isCalledAsConstructor())
          ctx->thisObject().setScriptClass(myClass);
      

      This pattern was inspired by the ECMA standard terminology; e.g. section 15.4.2 "The Array Constructor": "The [[Class]] internal property of the newly constructed object is set to "Array"."

      A better solution would be to have the VM construct an object of the correct type in the first place, which is what JSC (by delegating the entire object creation to the constructor function) and V8 (by using instance templates) does already. This eliminates the level of indirection introduced by the setScriptClass() approach.

      Attachments

        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:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes