[Development] JS Engine: callAsConstructor vs. virtualCallAsConstructor

Valery Kotov kotov.valery at gmail.com
Sat Aug 4 11:39:23 CEST 2018


Hello Lars,

Got it. Thank you for the explanation!

Just a small question to see that I got it correctly. Then virtuallCall
means the same but for JavaScript function invocation, does not it? And if
I would like to call a JS function from C++ I simply do
functionObject->call (as before) and it will automatically redirect to the
appropriate virtualCall (re)implementation. Is that right?

BR,
Valery


Sincerely yours,
Valery Kotov

On 3 August 2018 at 08:04, Lars Knoll <lars.knoll at qt.io> wrote:

> Hi Valery,
>
> On 2 Aug 2018, at 15:44, Valery Kotov <kotov.valery at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180804/0ed9404b/attachment.html>


More information about the Development mailing list