aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmljavascriptexpression.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QPropertyChangeTrigger: Inherit directly from QPropertyObserverFabian Kosmale2020-10-121-4/+5
| | | | | | Change-Id: If2ffeef14d33200e39fb8b3e7fd88c232164a241 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Handle QProperty inside bindingsFabian Kosmale2020-09-211-4/+53
| | | | | | | | | | | | | | | | | | | If we have a binding containing QProperties, and the binding target is an old style binding, still we have to trigger an update if any of the captured properties changes. We cannot reuse the QQmlJavaScriptExpressionGuards as those depend on Qt's signals, and a QProperty is not associated with a change signal in the general case. Therefore, we introduce a new list of QPropertyChangeHandler, which when triggered cause a reevaluation of the binding. As an optimization, we skip the whole capturing process for QQmlPropertyBinding, as that one already takes care of updating itself. Reverts 845bbb99a41a3e4f05c2b3d05d6db748c825dca0 (because skipping the capture is only possible when _both_ the bindee and the property in the binding are QProperty based.) Change-Id: Iafed2a41dcd708bcc33912ce810d803949379c63 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Replace QFlagPointer with QTaggedPointerSimon Hausmann2020-04-031-1/+1
| | | | | | | | The latter has the advantage of allowing the use of a real type for the tag, instead of the generic flag/flag2 boolean accessors. Change-Id: Icc9e854ce4af3eb5808a4bed45aa22f377e223da Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Minor cleanup in QQmlJavaScriptExpressionSimon Hausmann2020-03-231-0/+12
| | | | | | | | | | We _can_ provide a default implementation for expressionIdentifier() - it doesn't have to be located in QQmlBinding as it only uses fields from QQmlJavaScriptExpression. Change-Id: Ifcead72c4f3ed4597cde732afca466eba83f5e0d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Encapsulate QQmlContextDataUlf Hermann2020-03-231-20/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This class is not a private detail of QQmlContext. And it is incredibly hard to see who owns what in there. Let's add some civilization ... We enforce refcounting for QQmlContextData across the code base, with two exceptions: 1. QQmlContextPrivate may or may not own its QQmlContextData. 2. We may request a QQmlContextData owned by its parent QQmlContextData. For these two cases we keep flags in QQmlContextData and when the respective field (m_parent or m_publicContext) is reset, we release() once. Furthermore, QQmlContextData and QQmlGuardedContextData are moved to their own files, in order to de-spaghettify qqmlcontext_p.h and qqmlcontext.cpp. When the QQmlEngine is deleted, any QQmlComponents drop their object creators now, in order to release any context data held by those. Before, the context data would be deleted, but the object creators would retain the dangling pointer. [ChangeLog][QML][Important Behavior Changes] QQmlContext::baseUrl() does what the documentation says now: It prefers explicitly set baseUrls over compilation unit URLs. Only if no baseUrl is set, the CU's URL is returned. It used to prefer the CU's URL. Change-Id: Ieeb5dcb07b45d891526191321386d5443b8f5738 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Restore offset/length in QQmlJS::DiagnosticMessageSimon Hausmann2020-03-021-2/+3
| | | | | | | | | | | | This is needed in a few places outside of declarative, so this change restores the loc member in DiagnosticMessage and moves QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory. QQmlError is unaffected and retains only line/column. Amends d4d197d06279f9257647628f7e1ccc9ec763a6bb Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Split QV4::Value into a static and a dynamic partUlf Hermann2019-05-311-1/+4
| | | | | | | | The static part can be used for compilation and won't resolve managed objects. This allows us to remove all the remaining V4_BOOTSTRAP. Change-Id: Id2f6feb64c48beb2a407697881aea8c0d791a532 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Split CompiledData::CompilationUnit in twoUlf Hermann2019-05-161-2/+2
| | | | | | | | We need a CompilationUnit that only holds the data needed for compilation and another one that is executable by the runtime. Change-Id: I704d859ba028576a18460f5e3a59f210f64535d3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove dead compile time QML context/scope property and id object codeSimon Hausmann2019-03-201-77/+5
| | | | | | | | | | | After enabling lookups in QML files, we can remove all the code that tries to deal with (type) compile time detection of access to id objects and properties of the scope/context object. This also allows removing quite a bit of run-time code paths and even byte code instructions. Task-number: QTBUG-69898 Change-Id: I7b26d7983393594a3ef56466d3e633f1822b76f4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Fix parsing of js files via Qt.include()Simon Hausmann2018-11-291-2/+2
| | | | | | | | | | | Make sure to parse them as JavaScript, not as QML, so that certain keywords such as char or double map to identifiers as expected. Also removed an unused function. Fixes: QTBUG-71524 Change-Id: Ie8a8dabe717ee12def6af512943e6d01efcf9876 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove bindings that have no dependenciesSimon Hausmann2018-05-161-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After the initial enabling of a binding we can quickly determine if there is a chance whether this binding will be re-evaluated again in the future as a consequence of dependency changes (properties or translations). If that is not the case, then we can save memory by removing that binding again. One implementation consequence of this change is that such constant bindings used with the "when" property of states require a proper reference count increase, which was previously implicit through the binding association with the target object. In tst_qqmlecmascript a test that verifies that we don't create run-time bindings for assignments of literal "null" to QObject pointer properties now also covers the more complex case where we don't know the property at parse time. We still evaluate the binding once though and perform one property assignment. Similarly on the QtQuick Designer Support API test side a binding such as x: Math.max(0, 200) will not create a persistent binding anymore and needs a tweak to remain. On a large scale application this optimization saved up to 5% of all bindings on start-up (~9000 of ~180000). On Linux x86-64 one binding is approximately 144 bytes, so the savings are in the range of ~1.2 MB of heap, as well as reduced fragmentation. Task-number: QTBUG-64541 Change-Id: Id3653008346fdf36611f5b4c4e82f5f78b5319aa Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Clean up manual reference of QQmlTypeData and QQmlPropertyCacheSimon Hausmann2018-04-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | We have a few places in the type loader where we do adventurous manual reference counting, where getType() returns a raw pointer that has been addref()'ed and then sometimes somehow we call release() later. Commit 0b394e30bba4f6bb7e6f7dbe5585a2e15aa0f21d is an example of where this can easily go wrong. As a consequence and also in preparation for future work on the type loader, this patch starts replacing the manual reference counting there. Changing the return type from QQmlTypeData *getType() to a QQmlRefPointer<> itself is not sufficient though, as the implicit operator T*() will still allow the caller to store the result as a raw pointer. Therefore this patch removes the "unsafe" implicit extraction operator. As a result of that change, other types that are sometimes stored in QQmlRefPointer are also affected and their usage needs to be adapted to QQmlRefPointer usage or manual raw pointer extraction with .data(). Change-Id: I18fd40634047f13196a237f4e6766cbef3bfbea2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix calling Qt.binding() on bound functionsLars Knoll2018-04-161-13/+1
| | | | | | | | | | | | | | | | | | | Calling Qt.binding() on a bound function object is a valid use case and used to work until Qt 5.8. The problem was that we optimized the code in QQmlBinding and QQmlJavascriptExpression to directly work on a QV4::Function, so this wouldn't work anymore. To fix this make sure recursive calls to Function.bind() are unrolled (so that the BoundFunction's target is never a bound function itself), then add the bound function as an optional member to the QQmlBinding and use it's bound arguments if present. Task-number: QTBUG-61927 Change-Id: I472214ddd82fc2a1212efd9b769861fc43d2ddaf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix crash when QML engine warning handler feeds errors back into QMLSimon Hausmann2018-04-091-1/+1
| | | | | | | | | | | | | | When a QQmlEngine warning handler that's called during component instantiation results in subsequent component instantiations, either via the signal or via a Qt message handler like in the bug report, then we might end up modifying the linked list of errored bindings before returning from the QQmlEnginePrivate::warning() call. The easy fix is to extract the QQmlError, unlink the delayed error from the linked list and then deliver the error to the QQmlEngine. Change-Id: I6b7be61b57b35636282595937046ff76091144a3 Task-number: QTBUG-53293 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix QQmlExpression::hasError()/error() on syntax errorsSimon Hausmann2018-03-271-9/+5
| | | | | | | | | | | | Record errors that happen during QV4::Script::parse() time in the same way as we record errors during binding evaluation, in order to correctly set the error state of QQmlExpression. This also removes dead code about setting line, description, etc. which is taken care of by ExecutionEngine::catchExceptionAsQmlError. Task-number: QTBUG-67240 Change-Id: I2d586e16803d0883cdd2d1d262b4c67202c00562 Reviewed-by: Michael Brasser <michael.brasser@live.com>
* use nullptr consistently (clang-tidy)Shawn Rutledge2018-02-261-13/+13
| | | | | | | | | | | | | From now on we prefer nullptr instead of 0 to clarify cases where we are assigning or testing a pointer rather than a numeric zero. Also, replaced cases where 0 was passed as Qt::KeyboardModifiers with Qt::NoModifier (clang-tidy replaced them with nullptr, which waas wrong, so it was just as well to make the tests more readable rather than to revert those lines). Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove double indirection between QJSEngine and QV4::ExecutionEngineUlf Hermann2018-02-021-4/+4
| | | | | | | | As QJSEngine's handle() method is internal, we can redefine it to return a pointer to an ExecutionEngine. That makes many things easier. Change-Id: Ie3df99e0bad5f00ad4fe73182896cd135fa82994 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Cut out one more C++ layer when doing JS function callsLars Knoll2017-11-131-8/+2
| | | | | Change-Id: I0e2ac30b7e6d77fe41deb84a97b0a7f220437c6a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify JSCallData constructionLars Knoll2017-11-071-1/+1
| | | | | Change-Id: Ic53532edae9a209aa7125af6f00a9d993d74f1a3 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get rid of the implicit cast operator to a CallDataLars Knoll2017-11-071-1/+1
| | | | | Change-Id: I1c35fbf8f7355bc2393ae931f99e591b800f2f45 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Rename JSCall to JSCallDataLars Knoll2017-11-071-1/+1
| | | | | | | | As, this is going to change in a simple stack based structure to keep pointers to the data to pass to calls. Change-Id: Ia9aa3f81ee3eeba36affd16aac7b2fe97d59aea9 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Don't add to the JS stack after creating the calldataLars Knoll2017-11-071-7/+6
| | | | | Change-Id: Ibc8dc71ffa3b4efb9bc8d6705fb8ac9ee1b4e4d6 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Move the registration of QML dependencies to where it belongsLars Knoll2017-10-231-0/+9
| | | | | | | | | The only plaec we can possibly have those dependencies is when we execute JS code from QQmlJavascriptExpression, so let's also more the dependency registration there. Change-Id: I12e7c69f7d126027e4fd9e73355173a45be01c65 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Always set the correct FunctionObject when calling JS functionsLars Knoll2017-09-021-2/+2
| | | | | | | | | Renamed ScopedCallData to JSCall, enforced passing a JS FunctionObject to it, and added call() and callAsConstructor() methods to it. Change-Id: I30db65c9765c2896b5909fe2105c0934c6dad861 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Move ScopedCallData and ScopedStackFrame into a separate fileLars Knoll2017-09-011-0/+1
| | | | | Change-Id: I9ae42aa7a811aa93fe0950725e9d253a0c5e8dba Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Use the context member in CallDataLars Knoll2017-09-011-2/+3
| | | | | | | | Store the current context in the context member instead of passing it along as arguments. Change-Id: If3dd0d32eddb2a02bcbf65fe6e8d15142403170e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/dev' into wip/new-backendLars Knoll2017-08-221-6/+12
|\ | | | | | | Change-Id: Iff06429f948ac6cdec77a9e5bb8c5375c56fe705
| * Merge remote-tracking branch 'origin/5.9' into devSimon Hausmann2017-07-281-2/+2
| |\ | | | | | | | | | Change-Id: I7d092cce33cb009d63e7b0df7c71183089dea53f
| | * Do not (dis)connectNotify on dynamically created model item objectsErik Verbruggen2017-07-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These item objects are direct subclasses of QObject, and cannot override connectNotify/disconnectNotify. This prevents the creation of the backing QMetaObject during disconnect, which happens during destruction, which in turn will call back into the model that is being destroyed. Task-number: QTBUG-59704 Change-Id: I7f997e5d2fda242b38e67b9147224d72aa4508ba Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| * | Add support for QEvent::LanguageChangeSimon Hausmann2017-07-141-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Respond to the language change event by refreshing all binding expressions. For constant string translation bindings we must now create special QQmlBinding instances instead of a one-time property write meta-call upon instantiation. Those however are more lightweight than an entire JavaScript expression. In addition this provides a slot to explicitly trigger a re-evaluation of bindings, to make it a little easier to discover for the developer. [ChangeLog][QtQml][QQmlEngine] Added retranslate() slot and QEvent::LanguageChange support to refresh bindings when changing the language at run-time. Task-number: QTBUG-15602 Change-Id: Ide174648e1d8a5738acb88e15495018d0869d7bc Reviewed-by: Michael Brasser <michael.brasser@live.com>
| * | Refactor le integer types from qjson_p.h to qendian_p.hAllan Sandfeld Jensen2017-07-061-3/+3
| |/ | | | | | | | | Change-Id: Ibb24b0a55dd94e03fea3104e8af5ddb266004300 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| * Don't leak QQmlJavaScriptExpression errorsColin Ogilvie2017-06-161-0/+1
| | | | | | | | | | | | | | Ensure any error is deleted when the expression is Change-Id: Ibbfd28f50279d4c66830b40c5c917eb8d98f266e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Always create a valid CallData object for interpreter callsLars Knoll2017-08-101-1/+1
| | | | | | | | | | | | | | | | This will allow removing a few more special cases and to simplify the code further. Change-Id: I3a958e9f68e3c103ea4f2ee6825f893e5931b11d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Get rid of simpleCallLars Knoll2017-08-101-7/+3
| | | | | | | | | | | | | | | | After the recent changes this can easily be unified with the call method without loss of performance. Change-Id: I0385b47b6a86e890f97dcbada3a1be1129ae0b84 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Refactor context handlingLars Knoll2017-08-101-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the push/pop context instructions to not modify the JS stack anymore, as that can cause conflicts with the VME (and was an ugly hack in any case). Instead, these instructions not return the old context, that is then stored in a temporary. Get rid of Engine::current and Engine::currentContext. The StackFrame structures do now contain the only and authoritive data. This finally gives us a nice setup where we create and destroy frames on the stack when entering/leaving functions. Change-Id: If161e3e941f59865c47ecfe1e094faf62b52bfa0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Avoid creating a CallContext for simple functionsLars Knoll2017-08-101-1/+2
| | | | | | | | | | | | | | | | This cuts out quite a bit of overhead when entering and leaving functions. Change-Id: I32670c98a4087ea3b2d45853d9cabff9066399e8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Completely avoid intermediate scopes for simple functionsLars Knoll2017-08-081-2/+2
| | | | | | | | | | Change-Id: I1fe2ff987e79cf590ad5ad3fc520b17925f8b616 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Remove Scope dependency from registerQmlDependenciesLars Knoll2017-08-081-5/+4
| | | | | | | | | | | | | | An engine pointer is sufficient. Change-Id: I6430cfeac3bd2881e89bbbd22ff31ffbd2a2339a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Remove Scope::result and convert calling convention for builtinsLars Knoll2017-08-081-3/+2
| | | | | | | | | | | | | | | | Allow for faster calling of builtins, and completely avoid scope creation in many cases. Change-Id: I0f1681e19e9908db10def85a74e134a87fc2e44c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Change function signatures for call/construct backLars Knoll2017-08-041-4/+15
|/ | | | | | | | Change those back again to return a value. This will be required to avoid creation of Scope objects between JS function calls. Change-Id: I05cb5cf8fd0c13dcefa60d213ccd5983fab57ea3 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get rid of QQmlJavaScriptExpression::setFunctionObject()Lars Knoll2016-12-091-12/+0
| | | | | | | | It was only used in one place now, and the code is actually cleaner when calling setupFunction() instead. Change-Id: Idfe2842b81e765569f2c70f3d5dcd1862442a2ee Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Avoid passing a FunctionObject to QQmlBinding::create()Lars Knoll2016-12-091-1/+1
| | | | | | | | Like this we can remove the QQmlBinding::create() overload that takes a FunctionObject. Change-Id: Ib6c37395ded325e68cf0fbf3afd08fb6dd6efa3b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Directly store the referenced QV4::Function pointer in the binding functionLars Knoll2016-12-091-4/+0
| | | | | | | | | There's no need to store a pointer to the original function here, we can simplify the code when storing the pointer to the QV4::Function directly. Change-Id: I377aaecf56a0118606713c26cc7da4da001766b1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Don't store a source location in the QQmlBindingFunction anymoreLars Knoll2016-12-091-1/+0
| | | | | | | | It's not needed anymore as we now store this in the binding directly. Change-Id: I518c83207f219b690f31200e4d17251075bbd322 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add a setSourceLocation() methodLars Knoll2016-12-091-1/+8
| | | | | Change-Id: I611ab4fe5dd59cb8e07b0fa69ce22c7df5a6c3f2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Don't create a FunctionObject in createQmlBinding()Lars Knoll2016-12-091-5/+2
| | | | | | | | This also removes the last use of the QmlBindingWrapper, so remove that class as well. Change-Id: I2ec795b6ab695a689fb24d64c9b8809b651c2b37 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Avoid the creation of a FunctionObject for most bindingsLars Knoll2016-12-091-0/+9
| | | | | Change-Id: Ia62d380945250015009d9c2b6ed65f6d830277ef Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Don't store a FunctionObject in QQmlJavaScriptExpression anymoreLars Knoll2016-12-091-17/+25
| | | | | | | Instead store the QmlContext, the QV4::Function and a source location. Change-Id: Iafa54c09b9be7e78bace3498673ca94a2a145c97 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Limit access to m_function to QQmlJavaScriptExpressionLars Knoll2016-12-091-3/+12
| | | | | Change-Id: I070f73f106440667fce2c7fe33310369a6aa1376 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Avoid using the FunctionObject in QQmlJavaScriptExpression::evaluate()Lars Knoll2016-12-091-3/+10
| | | | | | | Rather directly execute the call on the QV4::Function. Change-Id: I1de52075760be6b3a0358af83270ebd4e1d1e8ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>