aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
Commit message (Collapse)AuthorAgeFilesLines
* Replace std::variant with tagged union in QJSPrimitiveValueUlf Hermann2021-03-122-35/+176
| | | | | | | | | Fixes: QTBUG-91717 Change-Id: Id19e08589206253b96c76bc40a799ccd95b0e0bf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> (cherry picked from commit 9970ebb277db5f11c8a7e72099fdd056a6d8310c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QJSPrimitiveValue: Implement modulo operatorUlf Hermann2021-02-191-0/+28
| | | | | | | | | | | The modulo operator has special semantics in JavaScript. We need to mirror those. Task-number: QTBUG-84369 Change-Id: I5a4d63a01e232686832c83f2def0faf57e7359c2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 84cf29933cee44e09590fc89ae800dd453f664ca) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QJSEngine: Add a function to throw a pre-generated error objectUlf Hermann2021-01-222-0/+15
| | | | | | | | | | | | | | | It makes little sense that you can construct an error object but not throw it. The test was definitely meant to actually throw the error object, not return it. [ChangeLog][QtQml] QJSEngine has gained an additional overload to the throwError() method, with the effect that calling throwError() with a character literal as argument is now ambiguous. You should explicitly construct a QString instead. Change-Id: I90c6c9edf10509daa142a86581d6a3f7ff45af2c Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove the qmake project filesFabian Kosmale2021-01-151-16/+0
| | | | | | | | | 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>
* QJSManagedValue: Allow retrieving and instantiating JS metatypesUlf Hermann2021-01-122-1/+109
| | | | | | | | ... 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>
* QJSManagedValue: Allow array access to stringsUlf Hermann2021-01-121-0/+13
| | | | | | | | | 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>
* QJSManagedValue: Silence some static analysis warningsUlf Hermann2021-01-111-2/+7
| | | | | | | | The engine should really always be available if we have a d pointer. Change-Id: If620e69de07c6d365b45e714bae3ec0fb7eb86ef Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSManagedValue: Add JavaScript 'function' typeUlf Hermann2021-01-072-11/+13
| | | | | | | | | '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>
* Doc: Fix typos ECMA-26 and boolean value quotingNico Vertriest2021-01-071-3/+3
| | | | | | Pick-to: 6.0 Change-Id: I1bf34b68ecfa2d6eb8e687a0b12def5e7c96c318 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* QJSValue: Add a toPrimitive() methodUlf Hermann2020-12-192-0/+34
| | | | | | | We need a way to easily get a primitive from a QJSValue. Change-Id: I91a55d92ffa4ba6139b1e3f2e9308800b7047563 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSManagedValue: Throw an exception when trying to call a non-callableUlf Hermann2020-12-191-3/+18
| | | | | | | The JavaScript engine does this, so we should do the same here. Change-Id: I011a60bc2c013f19306c843da7a9c22dc80a39cb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSPrimitiveValue: Add a toVariant() method and ctor from QVariantUlf Hermann2020-12-181-0/+42
| | | | | | | | This is rather handy. Without it, we have to go through either QJSValue or QJSManagedValue, which causes much greater overhead. Change-Id: I40e2ecb6e2005f80c8f52b5e9a59028b3984eea4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add a QJSManagedValueUlf Hermann2020-12-189-4/+1283
| | | | | | | | | | | | | 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>
* Allow JavaScript primitive type transformations inline in C++Ulf Hermann2020-12-186-4/+893
| | | | | | | | | | We don't want to call into the engine just for adding two numbers. This implements the most common operators on primitive JavaScript values. More are to follow in the future. Change-Id: Id51a5af59a3af9fec78a2d8f293e59e6567e9204 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSValue: Add toVariant() overload with conversion behaviorUlf Hermann2020-12-072-12/+50
| | | | | | | | | | | | The QJSValue to QVariant conversion is traditionally messy. The recent addition of a special case for FunctionObject did not make that better. Rather, we now add a way of specifying that the conversion should be lossless, which avoids all conversions of JS objects and arrays. Amends commit 6b08c24297f39f3c67bc5c16f46198b33af66529. Change-Id: I6d4506b52d3175ed2f2984f8a26d560cf6311ab6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow checking for and catching errors from QJSEngineUlf Hermann2020-12-072-0/+29
| | | | | | | | | As you can manually throw an error, you should be able to catch it again, too. Change-Id: I82475df1969a1fd76f4cf5fc0a8d921dfafaef89 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Mark url as builtin typeUlf Hermann2020-12-021-0/+5
| | | | | | | | | Also, allow conversion from UrlObject and String. We allow the string conversion because we treat string and url as interchangeable in various places. Change-Id: Ib229c6d190e1c5d849ea18798925965b8dbeef7e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSValue: On toVariant() don't try to unwrap function objectsUlf Hermann2020-11-261-2/+4
| | | | | | | | We cannot retrieve anything sensible from those. Therefore, just wrap the QJSValue into a variant. Change-Id: I8acd9fb59a8859c8b2c389efb7934b597a2e479f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qtdeclarative: finish fixing compilation with explicit QChar(int)David Faure2020-11-071-1/+1
| | | | | Change-Id: Idb26e2df6d4fe8940db57066a30fa8c243f6d2c9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Doc:: Fix documentation warnings for Qt QMLTopi Reinio2020-11-051-3/+3
| | | | | | Task-number: QTBUG-88156 Change-Id: Ic6127c6128b4c7736cb4b5ab8ce51629388b59ca Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Replace old Q_DECL statements with modern C++Allan Sandfeld Jensen2020-10-311-1/+1
| | | | | | | Since we depend on C++17 now, all of these can go. Change-Id: I0484fd4bb99e4367ec211c29146c316453729959 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QJSEngine::evaluete: fix documentationFabian Kosmale2020-09-031-2/+2
| | | | | | Change-Id: Ie0e6d975079e4cbedad2dd4f17d3efe8aee553bc Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
* QJSEngine: provide a way to check if an exception was thrownFabian Kosmale2020-09-022-6/+28
| | | | | | | | | | | [ChangeLog][QML][QJSEngine] QJSEngine::evaluate gained an optional stackTrace parameter. It can be used to check if the returned QJSValue comes from an uncaught exception, and to retrieve the backtrace of the execution leading to the error. Fixes: QTBUG-54925 Change-Id: I2b5ada1f0c33c335b4b9d0d1268e70ca63a1fad1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Doc: Fix minor typosSze Howe Koh2020-08-301-1/+1
| | | | | | Pick-to: 5.15 Change-Id: I4c51c40697e410d56b6a2d2446ed9f8ae218576d Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
* Fix QtQml after QMetaType/QVariant changes in Qt CoreLars Knoll2020-08-282-0/+70
| | | | | Change-Id: I2a983cf8188e88d80d3b7726208d821427eb8f3c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove deprecated function QJSValue::engineFabian Kosmale2020-08-262-22/+0
| | | | | | | | | [ChangeLog][QJSValue] The deprecated function QJSValue::engine() has been removed. Change-Id: I2be35379e0a9e51f5371a2c98b955282955b7147 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Remove deprecated QJSEngine::installTranslatorFunctions functionFabian Kosmale2020-08-252-38/+0
| | | | | | | | | [ChangeLog][QJSEngine] The deprecated installTranslatorFunctions() has been removed. Use installExtensions() with TranslationExtension instead. Change-Id: I58345793ea154ec37d0c64f13c958193e6fa461b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Adapt to qtbase changesFabian Kosmale2020-08-231-1/+1
| | | | | | | | | | | The internal QVariant constructor taking a QMetaTypeId has been removed. Thus, construct QMetaTypes where necessary from the id, or avoid a QMetaType -> ID -> QMetaType roundtrip where we already have a metatype. Also fix a few missing includse that were previously transitively included. Change-Id: I56ce92281d616108a4ff80fe5052b919d1282357 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
* Fix race condition in QQmlData::createPropertyCacheFabian Kosmale2020-06-051-6/+6
| | | | | | | | | | | | | | As noted in QJSEnginePrivate::cache, there can be a race between calling addRef on the QQmlPropertyCache and another thread derefing and consequently deleting it. To avoid this, we introduce a doRef flag in QQmlMetaTypeData::propertyCache, which tells it to ref the the cache. This fixes the issue, as the QQmlMetaTypeDataPtr in propertyCache() acts as a mutex. Fixes: QTBUG-84692 Pick-to: 5.15 Change-Id: I962d28cfd22696aad89a660e41c55f63a8791b44 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QJSEngine: support char16_tFabian Kosmale2020-05-161-0/+3
| | | | | | | | Now that char16_t is used in Qt (for instance in QChar::unicode()), we need to support it. Change-Id: I527a70795524bfd883fc4d729aac714708b51181 Reviewed-by: Liang Qi <liang.qi@qt.io>
* Move object onwership functions from QQmlEngine to QJSEngineFabian Kosmale2020-04-242-0/+70
| | | | | | | | | | | | [ChangeLog][QML] The setObjectOwnership and objectOwnership functions have been moved from QQmlEngine to QJSEngine. This reflects the fact that they have an effect on objects passed not only to a QQmlEngine, but also to a QJSEngine. As QQmlEngine is a subclass of QJSEngine, existing code continues to work. Fixes: QTBUG-83657 Change-Id: Ib29cdb4a9884e1f1b68fcba64d32b1cb2e5a4297 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add support for translation bindings on QProperty based propertiesSimon Hausmann2020-04-021-1/+2
| | | | | Change-Id: I439653123cdc96df97a1801664655c9d28a8b9b5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Store a QV4::ReturnedValue in QJSValueUlf Hermann2020-03-186-514/+329
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Being careful, we can now save primitive values inline. We use the heap pointer of QV4::Value as either QString* or QV4::Value* for complex types. We cannot store persistent managed QV4::Value without the double indirection as those need to be allocated in a special place. The generic QVariant case is not supported anymore. The only place where it was actually needed were the stream operators for QJSValue. Those were fundamentally broken: * A managed QJSValue saved and loaded from a stream was converted to a QVariant-type QJSValue * QVariant-type QJSValues were not callable, could not be objects or arrays, or any of the special types. * Cyclic references were forcibly broken when saving to a data stream. In general the support for saving and loading of managed types to/from a data stream was so abysmally bad that we don't lose much by dropping it. [ChangeLog][QML][Important Behavior Changes] When saving a QJSValue to a QDataStream only primitive values or strings will be retained. Support for objects and arrays was incomplete and unreliable already before. It cannot work correctly as we don't necessarily have a JavaScript heap when loading a QJSValue from a stream. Therefore, we don't have a proper place to keep any managed values. Using QVariant to keep them instead is a bad idea because QVariant cannot represent everything a QJSValue can contain. Fixes: QTBUG-75174 Change-Id: I75697670639bca8d4b1668763d7020c4cf871bda Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSValue: Make call* const (Qt 6 TODO)Fabian Kosmale2020-03-132-6/+6
| | | | | Change-Id: I3a6c83ffc203bf27121f460ba23d31a39d1493ee Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Use QTypeRevision for all versions and revisionsUlf Hermann2020-02-031-6/+6
| | | | | | | | | | | | | | In many places we carry major and minor versions or revisions that are loosely coupled to minor versions. As the Qt minor version resets now, we need to handle these things more systematically. In particular, we need to add a "major" part to revisions. QTypeRevision can express the current major/minor pairs more efficiently and can also be used to add a major version to revisions. This change does not change the semantics, yet, but only replaces the types. Change-Id: Ie58ba8114d7e4c6427f0f28716deee71995c0d24 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add Qt.uiLanguage and QJSEngine::uiLanguage propertiesSimon Hausmann2020-01-233-8/+38
| | | | | | | | | | | | | | [ChangeLog][QtQml] Added Qt.uiLanguage and QJSEngine::uiLanguage properties These properties mirror the same value in QML and C++ and can be used freely. They also provide API symmetry to Qt for MCUs. QQmlApplicationEngine binds to this property and applies translations accordingly by constructing a QLocale with the value and using QTranslator::load(locale). Change-Id: Id87d6ee64679b07ff3cb47844594e8eeebd8c8b6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Christian Kamm <mail@ckamm.de>
* Replace QVariant::type with QVariant::userTypeOlivier Goffart2020-01-171-6/+6
| | | | | | | | | | | as type is going to be deprecated. This change was done automatically with the help of clazy. In addition, ColumnRoleMetadata was changed to take an int instead of a QVariant::Type Change-Id: Ibc02d7b52e7d931a56c19fdebc4788b5e6df2a39 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.13' into 5.14Liang Qi2019-09-121-1/+3
|\ | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/qml/jsruntime/qv4engine.cpp src/quick/handlers/qquicktaphandler.cpp src/quick/items/qquicktableview.cpp Done-With: Richard Moe Gustavsen <richard.gustavsen@qt.io> Done-With: Ulf Hermann <ulf.hermann@qt.io> Done-With: Shawn Rutledge <shawn.rutledge@qt.io> Change-Id: If9558a33f01693ce96420c094e0b57dfff0626cd
| * Doc: Fix documentation warnings for qtdeclarativeTopi Reinio2019-08-291-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After recent changes to QDoc, it now correctly warns about missing documentation for QML method parameters - fix all of these and also do some minor language editing. Remove duplicated entries for - \qmlmodule Qt.labs.qmlmodels - \group qtjavascript as they were causing issues. Change-Id: I55cd670cc8a0cc6427cdb7945dbd7c28ea94f796 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* | Port from QMutex::Recursive to QRecursiveMutexMarc Mutz2019-07-311-2/+2
| | | | | | | | | | | | Change-Id: I5bf128b4479971e87d377707f2ebf267ccba1f1d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Port from implicit to explicit atomic operationsMarc Mutz2019-07-022-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | The old code used the implicit conversions from QAtomicPointer<T> to T*, and QAtomicInteger<T> to T, and vice versa. The semantics of these differ from the ones std::atomic uses, so we're going to deprecate these, like we did for load() and store(), too. This patch fixes some users of these APIs before we deprecate them. Change-Id: I892d705c22280f1c6fdc62c1777248b44e9c4329 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Merge remote-tracking branch 'origin/5.13' into devQt Forward Merge Bot2019-06-141-2/+19
|\| | | | | | | | | | | | | Conflicts: tests/auto/qml/qjsengine/tst_qjsengine.cpp Change-Id: I34df194046a91ee8a076ce28022eb99d68e7f362
| * Allow destroying QJSValues from other threadsUlf Hermann2019-06-111-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | QVariants are commonly passed around between threads and QVariants can wrap QJSValues. Therefore we need to allow this. The persistent value is freed immediately if we're still in the same thread. Otherwise a message is passed to the QJSEngine that owns it. If there is no QJSEngine we assume that we can free the value immediately. As such a thing can only happen via private API we can make sure this assumption holds. Fixes: QTBUG-75939 Change-Id: I14c09fd5d6ef7ba689f66656f2bcbb5c88bacf89 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Remove last traces of QV8EngineUlf Hermann2019-05-081-4/+0
| | | | | | | | | | Change-Id: I59f738402d51e39188bbbca2ef1fbc8a61612372 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Make JavaScript execution interruptibleUlf Hermann2019-04-303-1/+44
| | | | | | | | | | | | | | | | | | | | | | Add an atomic isInterrupted flag to BaseEngine and check that in addition to the hasException flag on checkException(). Add some more exception checks to cover all possible infinite loops. Also, remove the writeBarrierActive member from QV4::EngineBase. It isn't used. Fixes: QTBUG-49080 Change-Id: I86b3114e3e61aff3e5eb9b020749a908ed801c2b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Merge remote-tracking branch 'origin/5.13' into devQt Forward Merge Bot2019-04-101-1/+1
|\| | | | | | | | | | | | | | | Conflicts: src/qml/qml/qqmlmetatype.cpp src/qml/types/qqmlmodelsmodule.cpp Change-Id: Idc63689ba98d83a455283674f4b5cf3014473605
| * Doc: Use the \nullptr macro instead of 0Venugopal Shivashankar2019-03-291-1/+1
| | | | | | | | | | | | | | | | This enables overriding the macro so that it translates to 'None' in the Qt for Python context. Change-Id: Ied1ddcb0f9e6e2299d9042e4cc4c2bb6d11a491b Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* | Remove unused includes of qv8engine_p.hUlf Hermann2019-04-091-1/+0
| | | | | | | | | | Change-Id: Ic135a863581d29a3afb9c6c7f070d2630b3913b4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Merge remote-tracking branch 'origin/5.13' into devQt Forward Merge Bot2019-02-251-6/+6
|\| | | | | | | | | | | | | Conflicts: src/qml/qml/qqmlmetatype.cpp Change-Id: I517c001ea4eb0fdd8e469f9fffe5b7559a5b0795
| * QML: Pass type minor version when creating property dataUlf Hermann2019-02-211-6/+6
| | | | | | | | | | | | | | | | | | Depending on the type minor version recursive properties should be available or not. Check for that when resolving grouped properties. Fixes: QTBUG-33179 Change-Id: Id8f62befdc4a29d879710499e19d3d289bd18775 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>