Commit Graph

19 Commits

Author SHA1 Message Date
Ulf Hermann 1fc939a870 QML: Faithfully convert undefined and null to string
If you do that in JS you get "undefined" and "null", respectively. Our
C++-based conversion methods should do the same. The documentation for
QJSValue also suggests that QJSValue::toFoo() should behave like
qjsvalue_cast<Foo>(x). So far QJSValue::toString() produced "undefined"
and "null" while qjsvalue_cast<String>(x) produced an empty string.

[ChangeLog][QtQml][Important Behavior Changes] qjsvalue_cast<QString>(x)
now returns "undefined" for undefined JS values, and "null" for null JS
values. This is in line with what QJSValue::toString() does, and also
what JavaScript itself would produce when stringifying such values.
Previously, qjsvalue_cast would return an empty string for both,
undefined and null JS values.

Change-Id: Ib93f4157f092ed769dca946541ffbcfbd7317d4c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-11-15 08:33:19 +01: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 a8431a4067 CMake: Don't use PUBLIC_LIBRARIES for tests and test helpers
Change-Id: I1cd769f85d5f82c43639d6787d98e536619249e6
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-28 14:58:42 +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
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
Assam Boudjelthia 841217b988 Rename android_dummy_imports.qml to dummy_imports.qml
Amends 16f0d38d56.
From 0fc8a511ba, it seems that
not only Android is relying on these imports to satify
qmlimportscanner, but also Integrity. So rename the imports
to something generic and remove the explicit mention for Android.

Pick-to: 6.2 6.3
Task-number: QTBUG-97056
Change-Id: I9273fd0f9201a805cad4d588847796f7daecb686
Reviewed-by: Kimmo Ollila <kimmo.ollila@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-03-05 15:23:48 +00:00
Kimmo Ollila 0fc8a511ba INTEGRITY: Fix some test cases from core/qml folders
-Add dummy_imports.qml to TESTDATA
-Let qmlimportscanner handle plugin import
-Skip cases that depend on mounted filesystem

Task-number: QTBUG-99123
Pick-to: 6.3 6.2
Change-Id: I99e21e423f2114c4c4ee1e24bdf9bb85af51baf7
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-03-03 08:26:06 +02:00
Assam Boudjelthia 16f0d38d56 Android: unify the android tests dummy import files
This renames all qml files added before to allow qmlimportsanner to
include the necessary modules into Android packages, into
android_dummy_imports.qml, and also adds a comment in each one
describing why it's needed.

Pick-to: 6.2 6.3
Task-number: QTBUG-97056
Change-Id: I7fc0514dd9e5bc10849fdd0503547e1a75242414
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-03-02 15:21:09 +02:00
Assam Boudjelthia 91930dd3d7 Add dummy_imports for qmlimportscanner to find the correct dependencies
Otherwise, some dependencies won't be fulfilled and the following will
fail:
 component.setData("import QtQml\nQtObject{}", QUrl())

Pick-to: 6.2 6.3
Task-number: QTBUG-97056
Change-Id: If53c77b992a01051d7e83378723000615be9dfe8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-12-17 13:43:13 +02:00
Craig Scott 63a601dc29 CMake: Remove unneeded *.pro and .prev_CMakeLists.txt files
The .pro files corresponding to the .prev_CMakeLists.txt files
have already been removed.

Change-Id: I254eafe4c7de1a516e33bd9cb3d9879e73fa83b4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-19 10:46:06 +10:00
Ulf Hermann 3c9339f3c8 Support native transformation between UrlObject and QVariant/QUrl
URL has become a builtin type. We should support it on the same level as
QString/String and QDateTime/Date.

In order to continue support for comparing URL properties with the
JavaScript equality operators, we still pass URLs as variants when
using them in JavaScript. However, we now create proper URL objects for
QJSValue and QJSManagedValue, and we allow transforming the URL-carrying
variant objects back into QUrls.

Change-Id: I78cb2d7d51ac720877217d2d4b4d0ab17cdd2a4b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-22 22:15:36 +02:00
Ulf Hermann 2e4561d4e7 QJSManagedValue: Throw TypeErrors when accessing null or undefined
Accessing properties of null or undefined is supposed to throw
TypeErrors in ECMAScript.

Change-Id: I4f05d56fa2f4d6767e582795bf39769a12df8019
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-25 18:46:43 +01:00
Fabian Kosmale 78ab4b8d8b Remove the qmake project files
Remove all qmake project files, except for examples which are used to
test that qmake continues to work.

Change-Id: Ic4abb72dc2dcd75df7a797c56056b6b3c5fe62ac
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-01-15 15:34:22 +01:00
Ulf Hermann 1390891709 QJSManagedValue: Allow retrieving and instantiating JS metatypes
... a.k.a InternalClass. This is a faster way of creating multiple
similar objects, compared to a sequence of setProperty() calls.

Change-Id: Iecc8c581e50b9062895dae9500ffe2482d88028e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-12 14:12:39 +01:00
Ulf Hermann 830eba61b7 QJSManagedValue: Allow array access to strings
If you access a string as an array you get a one-character string of the
index you are asking for.

Change-Id: Ie2ac3243c9e23f37b8904c54d824946646a596eb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-01-12 11:44:07 +01:00
Ulf Hermann 1cd696cf9e QJSManagedValue: Add JavaScript 'function' type
'function' is a separate type in JavaScript and should be treated that
way. Replace the isCallable() method with a new isFunction() to reflect
that, and add an entry to the Type enum.

Change-Id: I09cc28a9edf8aa0380eb9caeb738dfc298a02567
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2021-01-07 12:51:48 +01:00
Ulf Hermann bf89ec1734 QJSManagedValue: Throw an exception when trying to call a non-callable
The JavaScript engine does this, so we should do the same here.

Change-Id: I011a60bc2c013f19306c843da7a9c22dc80a39cb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-12-19 19:53:44 +01:00
Ulf Hermann 6f181768a3 Add a QJSManagedValue
A QJSManagedValue is a view on a QJSValue which always knows the engine
the value belongs to. This allows us to implement the JavaScript
semantics of the various QJSValue methods in a much more rigorous way.

[ChangeLog][QtQml] The new QJSManagedValue should be used instead of
QJSValue for manipulating properties and prototypes of JavaScript
values, as well as for calling JavaScript functions.

Change-Id: I9d445ffcf68dfa72dba9bae0818e83c80665ad66
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-12-18 17:26:51 +01:00