Hi Valery,

On 2 Aug 2018, at 15:44, Valery Kotov 
<kotov.val...@gmail.com<mailto:kotov.val...@gmail.com>> wrote:

Hello all,

I have a question about recent introduction of "virtual" functions in 
JavaScript engine.

Now objects have both virtualCallAsConstructor function and callAsConstructor 
functions.
Unfortunately, distinction between those is a little bit unclear to me. Is 
virtualCallAsConstructor is actually what is called when object is created on 
JS side (via new call)? Shall virtuallCallAsConstructor now be used when an JS 
Object is needed to be created from C++ side?

As you know, we have some hand rolled vtables for QV4::Object and friends. The 
declarations of those can now be found in qv4vtable_p.h.

Before, the ‘virtual’ and non regular methods where simply called the same, but 
had different signatures. That gave some conflicts, so I know renamed the ones 
that will be used by the vtable to have a ‘virtual’ prefix.

So if you add your own re-implementation of callAsConstructor you’ll have to 
name it ‘virtualCallAsConstructor’. Like that it’ll end up in the vtable.

If you call a constructor from C++, you can simply do 
functionObject->callAsConstructor() and it’ll forward it to the correct vtable 
method. If you ‘reimplement’ one of those methods (ie. implement a 
virtualCallAsConstructor) and need to call the base implementation, you’ll need 
to call the specific BaseClass::virtualCallAsConstructor method.


I'm also a little bit puzzled about signature:
static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const 
Value *argv, int argc, const Value *);

What is the last const Value*? Shall I pass args as last the last arguments?

The last value is the newTarget (see 
https://www.ecma-international.org/ecma-262/8.0/#sec-construct). It’s required 
for class constructors. In most cases it’ll be the same as the function object 
that is the constructor.

Cheers,
Lars

_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to