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.