Commit Graph

17 Commits

Author SHA1 Message Date
Fabian Kosmale 8effdd97d9 Expose XMLHttpRequest to qmltypes
In QML, one can use XMLHttpRequest. Not so with a plain JS engine. The
reason for that lies in the fact that a JS engine did not have any
network access, because all network functionality was in the type
loader, and the type loader was coupled to the QV4::Engine.
This has changed in d2bc4a4330, but we
stil don't expose XMLHttpRequest to a plain QJSEngine.

Nevertheless, it conceptually lives in the global object, and we need to
collect information about it to enable code completion and linting.

Consequently, expose a function in QV4::Engine, which allows us to
manually trigger the registration, and call it in qmljsrootgen.

Going forward, we should arguably have a QJSEngine::Extension for
XMLHttpReuqest, after which we could remove the hack.

Note that as before, qmljsrootgen prints a few warnings, because we call
functions in contexts in which they must not be called. As before, we
ignore this for now.

As a side-effect, this adds a few more entries to the qmltypes file for
new entries on the global Qt object.

Task-number: QTBUG-137075
Pick-to: 6.10
Change-Id: I21e9d62bf075e8d4356db8f357502feb927717e7
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2025-07-22 10:18:31 +02:00
Vladimir Belyavsky 2f727c892b Tooling: Use QHash/QMap's constFind() to avoid unnecessary detaches
Use QHash/QMap's constFind() instead of non-const find() where
applicable to avoid unnecessary detaches.

Change-Id: I3906c7ff0601b2b4c336c6e4312319b76fa0c183
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2024-04-23 21:33:39 +03:00
Amanda Hamblin-Trué 74232a8b31 qmljsrootgen: port to QCommandLineParser
Additionally, improved the error message for missing output path.

Change-Id: I3885a06157100399c160853b3137dd28aa965c72
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-07-05 09:14:20 +02:00
Marc Mutz 534241f723 Port to new Q_UNREACHABLE_RETURN()
This is a semantic patch using ClangTidyTransformator to convert
sequences of Q_UNREACHABLE() + return into Q_UNREACHABLE_RETURN(),
newly added to qtbase.

    const std::string unr = "unr", val = "val", ret = "ret";
    auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(",
                                    ifBound(val, cat(node(val)), cat("")),
                                    ")");
    auto ignoringSwitchCases = [](auto stmt) {
        return anyOf(stmt, switchCase(subStmt(stmt)));
    };

    makeRule(stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)),
                  nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))),
             {changeTo(node(unr), cat(makeUnreachableReturn,
                                      ";")), // TODO: why is the ; lost w/o this?
              changeTo(node(ret), cat(""))},
             cat("use ", makeUnreachableReturn));

a.k.a qt-use-unreachable-return.

subStmt() and nextStmt() are non-standard matchers.

There was one false positive, suppressed it with NOLINTNEXTLINE.

It's not really a false positiive, it's just that Clang sees the world
in one way and if conditonal compilation (#if) differs for other
compilers, Clang doesn't know better. This is an artifact of matching
two consecutive statements.

Change-Id: I3855b2dc8523db1ea860f72ad9818738162495c6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-20 23:59:33 +02:00
Marc Mutz 958cd3ee10 Port from container::count() and length() to size()
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:

  auto QtContainerClass = anyOf(
      expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
      expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.

Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-07 23:38:48 +02:00
Lucie Gérard 1b9808737a Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: Id89ed14990804a5024183e75382cc539d4293da1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-09-07 17:01:30 +02:00
Alexandru Croitor eed7b3f4e7 CMake: Don't use PUBLIC_LIBRARIES for executables
Change-Id: I346ea4eac1dfbfb7fb81609307f5f7c4716bb8d1
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-21 13:19:04 +02:00
Lucie Gérard 5a7b716474 Add license headers to cmake files
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.

Existing copyright statements remain intact

Task-number: QTBUG-88621
Change-Id: I72c89a98c42bbc9234d8495e9e503bec81d11037
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-07-08 10:41:06 +02:00
Ulf Hermann d70049d4d4 Drop the typed variants of Math methods from jsroot.qmltypes
They're not needed for the inlining of Math methods in qmlcachegen.
qmlcachegen itself detects the Math object and its methods and assumes
they shall always deal with numbers.

Furthermore, the types in jsroot.qmltypes are actually wrong. Using JS
"number" does not help here because we need C++ types.

Change-Id: Ibba5c91e8d7ed728c7fe814e43d36b24bb22fcc3
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-11 16:00:28 +02:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00
Maximilian Goldstein d8e73b588a qmllint: Properly handle JavaScript functions with variable arguments
Previously calling a JavaScript function with variable arguments could
cause the linting process to error out because of a lack of matching
function arguments.

This is now handled by defaulting to a JavaScript method if no matching
function signature can be found.

Fixes: QTBUG-98299
Change-Id: I748a60839106243a12bffd8d715b48cbc53d7f57
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-11-26 21:23:08 +01:00
Joerg Bornemann 0d6d3c7bc5 Skip unnecessary commands when cross-building tools
Call qt_internal_return_unless_building_tools() directly after
qt_internal_add_tool() to avoid having to special-case code for when
this function only creates imported targets in cross-builds.

Task-number: QTBUG-85084
Change-Id: I5c8f2ecdf4936cfd15cb530e896bc4e5b5531620
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-10-08 10:37:35 +02:00
Ulf Hermann d98bc001f9 qmljsrootgen: Try properties on instances if not available on prototypes
This gives us type information for a few extra properties, among which
is ArrayBuffer. We also declare ArrayBuffer as extension to QByteArray,
which we can now test with qmllint.

Change-Id: Ibb3da5e8b8a9e839dc6365fbeabe8418022d1346
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-05 12:53:14 +02:00
Ulf Hermann 478d0d5d33 Amend JS root with more precise type information
Methods on the "Math" object preferably deal with numbers, and if we
pass them numbers, they also return numbers. Model this as overrides of
the generic methods.

Change-Id: I419093630577c371846e5c8ac153f90ed6ffa87e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-05 12:53:14 +02:00
Kai Köhne c442542627 Move tools to libexec
Move qmlimportscanner, qmltyperegistrar, qmljsrootgen, qmlcachegen to libexec
These are internal tools that is not supposed to be run by the user directly.

[ChangeLog][Linux] qmlimportscanner, qmltyperegistrar, qmljsrootgen,
qmlcachegen tools got moved from QTDIR/bin into QTDIR/libexec
directory.

Task-number: QTBUG-88791
Change-Id: I2739044e872ec83ef7da7dd857c26395ecfd407d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2021-05-11 08:48:11 +02:00
Ulf Hermann 16b30313ad Rework qmljsrootgen
This way it actually generates interesting data about the JavaScript
types, for example the functions of the String prototype. Add a helper
method to create a symbol to QJSEngine. This should be generally useful.

Change-Id: I6c7b253b9d6cdb61602ceeae0955aed8d942c139
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-16 14:29:55 +02:00
Maximilian Goldstein 5851195c4f Add qmltypes for JavaScript root object
This change adds jsroot.qmltypes which represents QJSEngine's global / root object and a tool to generate it (qmlsjrootgen).

If you wish to regenerate jsroot.qmltypes run the following commands:

qmljsrootgen jsroot.json
qmltyperegistrar jsroot.json --generate-qmltypes src/imports/builtins/jsroot.qmltypes --import-name QJSEngine --major-version 1 --minor-version 0

Fixes: QTBUG-90807
Change-Id: I5ba0a048586d2dd945009d65c2b51be8ead85feb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-19 14:57:46 +01:00