aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi/qjsengine.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Tooling: Add test for integrating event replay with qmlpreviewUlf Hermann2025-11-211-0/+4
| | | | | | | | | | | | This makes sure that the relevant debug services can coexist. In order for this to actually be true, we need to initialize the type loader before we initialize the various services. Otherwise the profiler service will initialize the type loader which will query the preview service for some directories, leading to a deadlock. Task-number: QTBUG-141569 Change-Id: Ia0873802b94b885654c693bdb9a96100cad492bf Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Move ExecutionEngine in to QJSEnginePrivateUlf Hermann2025-06-241-6/+4
| | | | | | | | | | | | | | The ExecutionEngine can live without a QQmlEngine or a QJSEngine, but not vice versa. Therefore, the ExecutionEngine has to outlive QQmlEngine and QJSEngine on shutdown. Since the ExecutionEngine lives longer now, we also need to postpone the pruning of the type registry. The engine might still hold on to types after all. Task-number: QTBUG-137848 Change-Id: Ib574cac84b5f2d974cbc24ed79550a58b69a7a1c Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QJSEngine: Use QQmlScriptBlob instead of loadModuleUlf Hermann2025-06-181-27/+58
| | | | | | | | We need to get rid of the local file loading. Also, sort the includes of qjsengine.cpp. Change-Id: I62629e21ababb9aadc2b146a75cda712d26cffa3 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Better encapsulate QV4::ScriptUlf Hermann2025-06-051-6/+6
| | | | | | | Make members private, add accessors, add m_ to member names, etc. Change-Id: I497db10b62bbfb32f55dca227af9a518da6eaa70 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QJSEngine: Allow strings as arguments to throwError()Ulf Hermann2025-05-151-1/+3
| | | | | | | | We need to store them on the JS heap. Fixes: QTBUG-136797 Change-Id: I8b675a2a5bafcfa49f4bdf38407e8d81b39bc902 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QJSEngine: Trim compilation units after evaluating a programOlivier De Cannière2025-03-121-0/+2
| | | | | | | | | | | | | | | Not doing so might lead them to accumulate until the js engine is destroyed. We only trim compilation units with the final url that was passed in to evaluate. This way, we prevent accumulation while also preserving compilation units from actual files. Fixes: QTBUG-132931 Pick-to: 6.9 6.8 Change-Id: Ie4f09287e293075de4940ced6146a862c4da3b5b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine::collectGarbage: Align behavior with QML's gc methodFabian Kosmale2025-01-221-1/+1
| | | | | | | | | | | Notably, make it also non-incremental. It is confusing if the two user-facing methods to start the gc behave differently. Task-number: QTBUG-132931 Pick-to: 6.9 6.8 Change-Id: Ia893f1ad2ffb7f861bee09f620910e317a79b1f4 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Avoid potential gc issuesFabian Kosmale2024-12-181-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implicitly constructing a value from a ReturnedValue muddies the responsibility for ensuring that the gc can find the object. With this change, we disable the implicit conversion. The expectation for lifetime management is now: - If a ReturnedValue is stored on the C++ stack, it must be put into a QV4::Scoped class (or there should be a comment why not doing so is safe). Passing a ReturnedValue to a function should no longer be possible, unless the function takes a ReturnedValue, in which case the expectation is that it stores the value in a place where it can be seen by the gc, before doing anything that could trigger a gc run. Using Value::fromReturnedValue can still be used to pass a Value on, but in that case, the expectation is that there is a comment which explains why this is safe. - If a QV4::Value is obtained from a function call, it ought to be stored in a ScopedValue, too. We currently can't enforce this easily, so this should be checked during code review. A possible way forward would be to disallow returning Values, but that would be a larger change, and is deferred to the future. - If a functions has a QV4::Value parameter, it's the callers' responsibilty to ensure that the gc can find it. Pick-to: 6.9 6.8 6.5 Fixes: QTBUG-131961 Change-Id: Iea055589d35a5f1ac36fe376d4389eb81de87961 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Model native modules as compilation unitsUlf Hermann2024-12-061-12/+15
| | | | | | | | | | | | | | | | | | | | | | | QQmlTypeLoader::injectedScript() was unsafe and impossible to fix because it had to query the engine from the type loader thread in order to find out whether to load a script from an actual file. By removing the whole special-casing of native modules, we can make the script loading thread safe. A native module is now also a compilation unit, with a regular QV4::Module as value. This means we can remove a lot of code that deals with the native modules in the engine. The downside is that native modules are now a lot larger than before. However, given that they don't appear in any examples and hardly any bugs have been filed about native modules since their introduction, we can assume that they are not a very popular feature. The reduction in complexity and the removal of the native modules map in the engine is expected to outweigh the extra memory overhead for native modules. Task-number: QTBUG-131721 Pick-to: 6.8 Change-Id: Ia7388d7ba8d71637559a791d874257fba4646330 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Move QMetaObjectWrapper into separate header/impl filesUlf Hermann2024-04-281-0/+1
| | | | | | | | | We want to use it from QQmlTypeWrapper and avoid circular includes. Task-number: QTBUG-124662 Change-Id: I4c78a17eb262a303b7239bbdd853ec02d609c330 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add doc for gc()Tasuku Suzuki2024-01-111-1/+5
| | | | | Change-Id: I920acf76846bece462b518239fc4c068a0fad8c1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Always link executable CU on creationUlf Hermann2024-01-101-1/+1
| | | | | | | | | | | | | | | We don't want floating unlinked executable CUs. They should always be tied to an engine, and the engine should not change. This gives us one definite point where to register them with the engine (to be done in subsequent change). Unfortunately, due to the refcounting, we need to remove the engine from any still-referenced CUs when the engine itself is destructed. We will be able to drop the refcounting and make the engine fully own its executable CUs once we can hold base CUs in most places. Change-Id: I9a53e83d5c4746c2b2bca896b51baa4fe7fee757 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Long live incremental garbage collection in QML!Fabian Kosmale2023-12-201-0/+1
| | | | | | | | | | | | | | | | | The design of the garbage collector is described in src/qml/memory/design.md. The gc and gcdone test helpers are adjusted to drive the gc to completion, even when in incremental mode. Parts of tst_qv4mm and tst_qqmlqt need to run with the incremental gc disabled, as they call gc inside QML and assumes that the GC finishes before returning. Initial-patch-by: Rafal Chomentowski <rafal.chomentowski@ge.com> Task-number: QTBUG-119274 Change-Id: I1d94f41bc7a434fad67de0fd46454b6db285f2eb Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QJSEngine: use delegating ctorFabian Kosmale2023-11-221-4/+1
| | | | | Change-Id: Iebb3444a523a5b8bcd3066580968f9d0dccfea87 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qml: replace fromLatin with _L1Anton Kudryavtsev2023-09-151-1/+1
| | | | | | | to improve readability and reduce allocations Change-Id: I1ffe10d6a14fb9cc09dd438cca84f4a1d74b8cb8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Doc: Fix undocumented parameters and broken linksTopi Reinio2023-09-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/qml/jsapi/qjsengine.cpp: (qdoc) warning: Can't link to 'qvariant_cast()' * src/quick/items/qquickrhiitem.cpp: (qdoc) warning: Undocumented parameter 'item' in QQuickRhiItemRenderer::synchronize() (qdoc) warning: Can't link to 'msaaColorBuffer()' (qdoc) warning: Can't link to 'resolveTexture()' * src/quick/scenegraph/util/qsgtextnode.cpp: (qdoc) warning: No such enum item 'Text.NativeRendering' in QSGTextNode::RenderType (qdoc) warning: Undocumented parameter 'color' in QSGTextNode::setColor() (qdoc) warning: Undocumented parameter 'color' in QSGTextNode::setSelectionColor() (qdoc) warning: Undocumented parameter 'viewport' in QSGTextNode::setViewport() * examples/quick/rendercontrol/rendercontrol_rhi/doc/src/ rendercontrol_rhi.qdoc: (qdoc) warning: Can't link to 'QWidget-based' (qdoc) warning: Can't link to 'QAnimationDriver' Mark all documentation modules in qtdeclarative as free of warnings. Change-Id: I97cc059701c351b53cdeeb5fc2feff923c5a76a8 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* QmlCompiler: Allow coercing date values to numbersUlf Hermann2023-08-251-0/+5
| | | | | | | | | This is the equivalent of JavaScript's valueOf(). Change-Id: If850519d6dbc7354b447acb6aad8ac04211d059d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QJSEngine::evaluate: Cross-reference QQmlExpressionFabian Kosmale2023-08-151-0/+5
| | | | | | | | | QJSEngine::evaluate is meant for plain JavaScript; guide readers wanting to use it with QML to the correct place. Pick-to: 6.2 6.5 6.6 Change-Id: If8016a4cca2999d95bac47e83159b1e10eb5a0d5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Doc: Small improvements for ~QQmlEngine, ~QJSEngineKai Köhne2023-06-201-1/+1
| | | | | | Pick-to: 6.5 6.6 Change-Id: I31bfa44ee2a026c2ab0dbdbbd9c349937f2662b2 Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* QML: Encode "missing" line number as negated address of stack frameUlf Hermann2023-05-091-1/+1
| | | | | | | | | | | | | | | This way we can identify which entry in a stack frame to amend when processing an exception in generated code. However, negative line numbers are also used to signal the position of "Ret" instructions. Since you cannot throw an exception from a "Ret" instruction, those cannot collide, but we cannot qAbs() the line number anymore when saving it in the stack trace. We have to qAbs() it in all the places where it's read. Pick-to: 6.5 Fixes: QTBUG-112946 Change-Id: I24dc4008fb7eab38e4d24e70211c22e46f1b72a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine: scope the results of fromData() and fromVariant()Ulf Hermann2023-03-071-2/+7
| | | | | | | | Otherwise the gc might collect them while we're still operating on them. Pick-to: 6.2 6.5 Change-Id: I4644ff7b4b1221f3e58832a245d71215e77bd891 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Doc: Remove duplicate words (typos)Andreas Eliasson2023-03-071-2/+2
| | | | | | Pick-to: 6.5 6.4 6.2 Change-Id: Ibd29739b894598e5d7837ed5f9150e08ca07fa35 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* QML: Treat long and ulong like other numbersUlf Hermann2023-02-071-0/+6
| | | | | | | | | | | | They should either be the same size as int/uint or the same size as longlong/ulonglong, but for some reason we get them as separate types. Pick-to: 6.5 Fixes: QTBUG-110767 Change-Id: I4c5826cfe6108e6f9722e6b3443bde13b2141b04 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QJSEngine: Move old convertV2 to removed_api.cppUlf Hermann2023-01-311-7/+0
| | | | | | Pick-to: 6.5 Change-Id: I7f700d64694c8651769841a0109d32e8f9a839b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix minor API problemsUlf Hermann2023-01-181-8/+0
| | | | | | | | | | | Add explicit where appropriate, and use more elegant constructs in inline functions. Introduce removed_api.cpp for QJSEngine::create(int, const void *). Pick-to: 6.5 Change-Id: Ie54b0494fe3c5567f8a5ca361c3a583de3d97dd5 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QJSEngine: Add efficient conversions for QDateTime and friendsUlf Hermann2023-01-171-0/+11
| | | | | | | | | The JavaScript date and time conversions are different from Qt's. Add them to coerceValue. Task-number: QTBUG-109380 Change-Id: Ic0d7dd8ff51fb8e29d80d9084d4415becaa76259 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine: Document new conversion functionsUlf Hermann2023-01-031-6/+38
| | | | | | | | | ... and drop the notes about QMetaType<T>. You can get a metatype for any type these days. Pick-to: 6.5 Change-Id: Iaae53830dfb9cbe81975c3f73cf6cbe33494884a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine: Add QJSPrimitiveValue conversionsUlf Hermann2022-12-151-0/+27
| | | | | | | | | | | | We need those in order to get correct results when using the more generic conversions with QJSPrimitiveValue as source or target. Without those extra methods, we frequently get garbage where it would be possible to construct a QJSPrimitiveValue. Pick-to: 6.5 Task-number: QTBUG-109111 Change-Id: I6ceb2a4ed73dae228dd2e5690cd608c58537b95f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine: Optimize conversion from QObject* to QStringUlf Hermann2022-11-221-0/+6
| | | | | | | | | | | | | | | This is commonly done for logging. With this in place we can have the code generator use coerceType() for such constructs. [ChangeLog][QML][Important Behavior Changes] You can implement custom toString() methods for your QML objects in JavaScript or in C++. Those methods don't actually have to return a string. Previously, whatever return value the method generated was forwarded as-is. Now it is coerced to a string. Change-Id: I4a9721a6948be0c24a36b31d453a74bd747db729 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QJSEngine: Mark convertV2 variant with int parameter as BC-onlyUlf Hermann2022-11-161-0/+2
| | | | | | | We won't need it anymore in Qt7. Change-Id: Iff8bfd5192d80d7603aaa66da8cb00ab23e60f99 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine: Provide a method to coerce values in JS fashionUlf Hermann2022-11-151-7/+24
| | | | | | | | | | | JavaScript has its own type coercion rules. We already have a methods that coerce QVariants, QJSValues and QJSManagedValues to specific types. The new method is a generalization of all of those and can coerce everything to everything (as far as JavaScript can). Change-Id: I9b6877fb40f67b6f2354781bbd4cf18cf996c7b0 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* QML: Make modules imported with registerModule() available in QMLUlf Hermann2022-09-021-10/+18
| | | | | | | | | So far, you could only use them from pure JavaScript programs. Also, fix re-exporting parts of native modules. Fixes: QTBUG-105901 Change-Id: I170017083284e6457b1aa0c6e606fd26227edae3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-111-38/+2
| | | | | | | | | | | | 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>
* QJSEngine: optimize isInterrupted handlingMarc Mutz2022-06-041-4/+4
| | | | | | | | | | | The isInterrupted flag is just that: a flag, so it doesn't require acquire/release semantics when loading/storing. Use relaxed loads and stores instead. Change-Id: I6d733a6bebcfc7f2b786265fc28f9ba7e25bb1c7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Perform QVariant conversion in JavaScript semanticsUlf Hermann2022-02-181-57/+83
| | | | | | | | | | | | | In JavaScript we have a number of extra conversions not covered by qvariant_cast. Therefore, add a method to perform a QVariant conversion in JavaScript semantics to QJSEngine, and use that in the compiler. Pick-to: 6.3 Fixes: QTBUG-100883 Change-Id: I8b0bfa0974bc6b339d2601fb373859bc710788c8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
* Ensure QQmlData::get const-correctnessFabian Kosmale2021-12-041-1/+1
| | | | | | | | | | | | If we pass in a const pointer, we're not allowed to modify the object, so the create==true case does not make sense there. We therefore provide now two versions of the function: One taking only a const pointer, and one taking a non-const pointer and a bool. The latter no longer provides a default parameter to encourage usage of the the const version wherever possible. Change-Id: Ifb5a7e0605127de429403982b31f754e154b8048 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QJSEngine: Make uiLanguage a QObjectBindablePropertyFabian Kosmale2021-10-071-6/+2
| | | | | | | | | | | | It was a plain QProperty before. Given that the property is exposed in the global Qt object in the engine, this could be problematic as with the QProperty it is possible to change the value without emitting the uiLanguageChanged signal. By using QObjectBindableProperty, we ensure that the signal is always emitted. Pick-to: 6.2 Change-Id: I0f771a4e4d752704f469de27617835260b261052 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QJSValue: Avoid BIC breakFabian Kosmale2021-07-051-0/+8
| | | | | | | | | | | | The toScriptValue function template called the exported create function. Thus, we can not change the signature of create, even though it was private. To avoid the BIC break, we keep the old version (and ifdef it so that it will go away in Qt 7). Task-number: QTBUG-94407 Pick-to: 6.2 Change-Id: I5b07f978dca156f52bdb529d3e15aea8c0c3c97e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Use QV4::Scope::hasException() where applicableUlf Hermann2021-06-301-2/+2
| | | | | | | It is shorter and encapsulates the exception handling a bit. Change-Id: I8e2dc0eb3b930e222b8cb4852b73d99ca18a0379 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add more links to QJSEngine's ownership documentationFabian Kosmale2021-06-171-1/+10
| | | | | | | | | Also explictily mention again that objects with JS ownership won't be deleted as long as they have a parent. Pick-to: 6.2 6.1 Change-Id: I1eeb5bc8183b6621f24f3751b8152b36acf2eeae Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Doc: Fix documentation issuesTopi Reinio2021-06-021-4/+6
| | | | | | | | | | * Comment out \instantiates referring to an internal class * Remove duplicate module page for Qt QML * Fix various linking problems Task-number: QTBUG-91875 Change-Id: I7675f8a253e0b0e0a031d8a3642b3d2786b75149 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Add QJSEngine::registerModuleAlex Shaw2021-05-011-0/+73
| | | | | | | | | | | | | | | | | | | | | | | | Some applications that use JavaScript as a scripting language may want to extend JS through C++ code. The current way to do that is with global objects. ES6 provides a better way of encapsulating code: modules. registerModule() allows an application to provide a QJSValue as a named module. Developers familiar with Node.js will find this very easy to use. Example: ```c++ QJSValue num(666); myEngine.registerModule("themarkofthebeast", num); ``` ```js import badnews from "themarkofthebeast"; ``` [ChangeLog][QtQml][QJSEngine] Adds the ability to register QJSValues in C++ as modules for importing in MJS files. Change-Id: I0c98dcb746aa2aa15aa2ab3082129d106413a23b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Rework qmljsrootgenUlf Hermann2021-04-161-0/+17
| | | | | | | | | 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>
* Use QMetaType for ExecutionEngine::metaTypeFromJS()Ulf Hermann2021-03-241-6/+16
| | | | | | | | We should avoid looking up metatypes by ID. That's expensive. Change-Id: I00ce0a7f95ec82b0db6e7eb976e39e50522a7fe4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* metaTypeToJS: use QMetaType instead of idFabian Kosmale2021-02-191-2/+2
| | | | | | Task-number: QTBUG-82931 Change-Id: I7b663c5f774ef3edbb19d5f2ef53cfe623a8e4cf Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qjsengine: Clarify to/fromScriptValue documentationMaximilian Goldstein2021-02-081-0/+2
| | | | | | Fixes: QTBUG-89956 Change-Id: I96439433b1f172e933c6c56daae639be7e18b931 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QJSEngine: Add a function to throw a pre-generated error objectUlf Hermann2021-01-221-0/+14
| | | | | | | | | | | | | | | 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>
* Add a QJSManagedValueUlf Hermann2020-12-181-0/+12
| | | | | | | | | | | | | 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 checking for and catching errors from QJSEngineUlf Hermann2020-12-071-0/+27
| | | | | | | | | 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>