[Development] Question about QtDeclarative Internals

Fabian Kosmale fabian.kosmale at qt.io
Wed Apr 21 19:40:19 CEST 2021


Hi,

there is certainly no straightforward way from QV4::Value to ExecutableCompilationUnit, especially considering that the Value can be anything, from a primitive like bool or undefined to basically arbitrary objects managed on the engine's heap.

Could you expand a bit more how exactly you envision registerModule to work? What is your QJSValue supposed to contain:
- A string with the JS code of the module?
- An URL?
- A C++ object which ought to provide methods that can then be used in the JS engine?

Regards,
Fabian
--
Fabian Kosmale
Software Engineer

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin
fabian.kosmale at qt.io
+49 1638686070
http://qt.io


Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

--

________________________________________
Von: Development <development-bounces at qt-project.org> im Auftrag von Alex Shaw <alex.shaw.as at gmail.com>
Gesendet: Mittwoch, 21. April 2021 16:18
An: development at qt-project.org
Betreff: [Development] Question about QtDeclarative Internals

Hello,

In QtDeclarative, can a QV4::ReturnedValue or a QV4::Value be converted into an ExecutableCompilationUnit?

I'm trying to work on a patch for QJSEngine to allow importing modules from C++ (similar to Node.js: import fs from "fs")
The planned method is something along the lines of:
void QJSEngine::registerModule(const QString &moduleName, const QJSValue &value)

I can see that behind the scenes, loadModule compiles a URL to an ExecutableCompilationUnit, then saves it to a list of modules for future lookup.
I thought the easiest way to do what I need is to convert a QJSValue to an internal QV4::Value, and from there into an ExecutableCompilationUnit.
Is there any way of doing that?

Thanks.


More information about the Development mailing list