aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilercontext_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove dead compile time QML context/scope property and id object codeSimon Hausmann2019-03-201-5/+0
| | | | | | | | | | | 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>
* Implement dummy QML lookups for "global" variablesSimon Hausmann2019-03-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When resolving names in the context of QML bindings, we now direct runtime access to QQmlContextWrapper::resolveQmlPropertyLookupGetter. At the moment this does basically the same as Runtime::method_loadName, which we called earlier. However this now provides the opportunity to optimize lookups in the QML context in a central place. When performing a call on a scope or context object property, we also did not use a CallName() instruction - which would have gotten the thisObject wrong - but instead we use a dedicated CallScopeObjectProperty and CallContextObjectProperty instruction. These rely on identifying these properties at compile time, which goes away with lookups (and also doesn't work when using ahead-of-time compilation). Therefore the qml context property lookup is using a getPropertyAndBase style signature and Runtime::method_callQmlContextPropertyLookup uses that. For the tests to pass, some error expectations need adjusting. In particular the compile-time detection of write attempts to id objects is now delayed to the run-time. The old code path is still there and will be removed separately in the next commit (as it is massive). Task-number: QTBUG-69898 Change-Id: Iad1ff93d3758c4db984a7c2d003beee21ed2275c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Create proper template objects for tagged templatesLars Knoll2018-11-051-0/+9
| | | | | | | | If a tagged template gets evaluated multiple times, the underlying template object is shared. Change-Id: Ie2f476fbc93d5991322ce1087c42719a8d8333ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Clone ContextType::Global as ContextType::ScriptImportedByQMLJüri Valdmann2018-11-011-2/+3
| | | | | | | | | | Add new enum value QV4::Compiler::ContextType::ScriptImportedByQML, which behaves exactly the same as ContextType::Global. A follow-up patch will change the behavior slightly. Task-number: QTBUG-69408 Change-Id: I20d27804fd1433f2229704546bcd78a0ac108c01 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix error reporting when imports or re-exports in modules failSimon Hausmann2018-10-111-0/+2
| | | | | | | | Collect the location of the import/export statement and include it in the exception thrown. Change-Id: I7966dfd53ed67d2d7087acde2dd8ff67c64cb044 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* ES7: Detect Tail Position Calls and pass that to the runtimeErik Verbruggen2018-10-041-0/+11
| | | | | | | Doing the tail call in the runtime will come in a follow-up patch Change-Id: I8224aac0edbdc765ee9b97703948edd52fd33f3e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Make a method constErik Verbruggen2018-09-281-1/+1
| | | | | Change-Id: I70043699d15daf858c47d30018060aef31810abb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix new.target access from eval()Lars Knoll2018-09-071-0/+1
| | | | | Change-Id: I1855eb303225d1784b019f8eebab0ad8bf2cdf5e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* fix accesses to this in arrow functionsLars Knoll2018-09-051-0/+1
| | | | | Change-Id: I4c0cfc3a120fc0b246760886b576e92d3f7623ff Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Optimize access to lexically scoped variablesSimon Hausmann2018-08-291-2/+7
| | | | | | | | | | | | | If we access a lexically scoped variable after the initializer, then we know it's either initialized or at least undefined, so we don't need to do the TDZ check anymore. The ES tests ensure that we don't optimize too much and the newly revived tst_v4misc test ensures that we do not generate the TDZ check instruction for certain scenarios. Change-Id: I6706d1feb22217f323124ee698ebadb70324693b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement the dead temporal zoneSimon Hausmann2018-08-281-0/+4
| | | | | | | | | | | | | | With const and let it is possible to access the declared member before initialization. This is expected to throw a type reference error at run-time. We initialize such variables with the empty value when entering their scope and check upon access for that. For locals we place the lexically scoped variables at the end. For register allocated lexical variables we group them into one batch and remember the index/size. Change-Id: Icb493ee0de0525bb682e1bc58981a4dfd33f750e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix initialization of default exported functions and generatorsSimon Hausmann2018-08-151-1/+1
| | | | | | | | | When registering a default export, make sure that the local name points either to an entry that we've entered into the environment or the synthetic entry we create. Change-Id: I37e160dc1e3231214bb68f72d6bb0746d7aee3b3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix module dependency handlingSimon Hausmann2018-08-141-0/+2
| | | | | | | | | | | | | | | | | | | | | The evaluation of a module can have side-effects by modifying the global object or objects in it. Therefore even a seemingly empty import such as import "./foo.js" needs to be listed in the module requests. It's also important that they are evaluated in the order of declaration. Therefore we collect all module requests separately - even those that don't have import variables to process. This patch also ensures that the export and import declarations are visited in the correct order, by unifying both AST nodes to be hooked into the statement list. The fact that we connect the module list items into a statement list is solely an artifact of re-using defineFunction() which takes a StatementList as body. Change-Id: I75dc357b2aecfc324d9a9fe66952eff1ec1dfd8a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix support for default exports in modulesSimon Hausmann2018-08-101-0/+1
| | | | | | | | | | | Default export declarations require a binding setup step at run-time, so we hook it into the ESModule's statement list to make it visible to the code gen visitor. We also reserve local slot zero for the default export. Change-Id: Ie064caad0422b92cfdadbd7d94db72a05e95c0cc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add initial basic support for ES6 modulesSimon Hausmann2018-08-091-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The entry point from the parsing perspective into modules is not QV4::Script but QV4::ExecutionEngine::compileModule. For convenience, the ESModule AST node gets a body, which is the statement list connected between the ModuleItemList items that are not import/export declarations. The QV4::Module allocates a call context where the exported variables are stored as named locals. This will also become the module namespace object. The imports in turn is an array of value pointers that point into the locals array of the context of the imported modules. The default module loading in ExecutionEngine assumes the accessibility of module urls via QFile (so local file system or resource). This is what qmljs also uses and QJSEngine as well via public API in the future. The test runner compiles the modules manually and injects them, because they need to be compiled together with the test harness code. The QML type loader will the mechanism for injection in the future for module imports from .qml files. Change-Id: I93be9cfe54c651fdbd08c5e1d22d58f47284e54f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Various fixes for class supportLars Knoll2018-06-261-4/+4
| | | | | | | | | | | | | | | | Add support for a default constructor if none is given. Fix support for computed method names, by unifying the handling between static and non static methods. Fix our table generation, so that we write UINT_MAX as the string index for undefined strings and not a reference to the empty string, as that can actually be a valid method name. Add support for getter and setter methods in classes. Change-Id: If52c57d6a67424b0218b86339b95aed9d0351e47 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* throw a type error when trying to write to a const variableLars Knoll2018-06-261-0/+1
| | | | | | | | | This makes them really const. The codegen needs some smaller changes to ensure that writing to the variable when it's being defined is allowed. Change-Id: I781b4bc9c0e0397b9d00cad3daf758a062c17600 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add basic support for EcmaScript classesYulong Bai2018-06-261-0/+19
| | | | | | | | | | | | | | | | Most of the class creation is done inside the runtime in the CreateClass method. Added a corresponding instruction to the interpreter and jit. The compiled data now contains an array of classes containing the compile time generated layout of the class. Currently, classes without an explicit constructor and classes with inheritance are not supported. Done-with: Yulong Bai <yulong.bai@qt.io> Change-Id: I0185dcc1e3b0b8f44deff74e44a8262fc646aa9e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove some dead codeLars Knoll2018-06-211-1/+0
| | | | | | | maxNumberOfArguments isn't used anymore. Change-Id: Ibb891101b971b4b0b01be7897e6d1490e1dde62c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Cleanup handling of direct evalsLars Knoll2018-05-231-0/+1
| | | | | | | | | | There's no need to force lookups by name in an outer function just because an inner function uses eval(). The lookup by name is only required on the call context level, where eval() could add new variables. Change-Id: I8cad6d27524f496304342dfe1449ea913ef99fca Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify Push and PopContext instructionsLars Knoll2018-05-231-2/+2
| | | | | | | | | There's no need for a temp register to store the old context in, as PopContext can simply retrieve the old context from the current one. Change-Id: Ife9cfdff7fa8e47fc71e844a7798de88dbc79e26 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Support destructuring inside catch()Lars Knoll2018-05-111-1/+1
| | | | | Change-Id: Ib60b56ac6a7111446e01235564a4cf92ad8ad025 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Cleanup handling of with() statementsLars Knoll2018-05-021-2/+1
| | | | | | | | | | | Add a CompilerContext for with, whose only purpose it is to trigger variable lookup by name. This avoids looking up variables declared inside the with() {} block by name and we do not lookup variables outside the with block by name neither anymore. Change-Id: I52e9fb2daa9601f9e5102714c002dc506ad5ed23 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rework catch context handlingLars Knoll2018-05-021-0/+2
| | | | | | | | | | | | Remove the need for a specialized catch context, instead use a regular block context, that also captures the catched variable. This also removes the need to do lookups by name inside a catch expression. Change-Id: I8b037add7f423922e2a76b4c0da646ca7e25813a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for proper lexical scopingLars Knoll2018-05-021-9/+12
| | | | | | | | | | | | | This is still to some extend work in progress as lexically scoped for loops won't yet do the right thing. let and const variables are still accessible before they are declared, and the global scope doesn't yet have a proper context for lexically declared variables. Change-Id: Ie39f74a8fccdaead437fbf07f9fc228a444c26ed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove unused methodLars Knoll2018-05-021-7/+0
| | | | | Change-Id: If22845b19c72362249347083edef591f7032f468 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Split out the generation of indices for locals and registersLars Knoll2018-05-021-1/+4
| | | | | Change-Id: I0e98ccba9ae3026cd8bfdc4cae100f280b5aa22c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Refactor variable resolvingLars Knoll2018-05-021-27/+24
| | | | | | | | | | Move variable resolving into the context, and avoid creating ExecutionContext's whereever we can. This prepares things for block scoping, where this becomes rather important to be able to achieve decent performance. Change-Id: Idf3d3c12cf348a2c3da01989c26c8529ceb36c12 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rename the CompilationMode enum to ContextTypeLars Knoll2018-05-021-9/+10
| | | | | | | | | And make it an enum class. The new name fits better, as it's mainly used to determine the type of the context when parsing. Also already added the 'Block' value that will be needed. Change-Id: I70d963b6a0b22db1a3c607cce6bdd2054b29e000 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix crashes when parsing functions with no parametersSimon Hausmann2018-05-021-1/+1
| | | | | | | | | | Commit da5fffbd34d8be68f8ee4c649881dbb673c9c0a5 introduced deferencing of the formals parameter list that can be a null pointer if the declared function has no parameters. Change-Id: Id7dce0f78b16266e672f0ae430ee4f979de5734d Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Use a PatternElement for VariableDeclarationsLars Knoll2018-04-271-5/+5
| | | | | | | Required to get proper destructuring working. Change-Id: I99fc20a9f1bace1fe3981d88ce5466f9c8d98245 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Added support for generator functions and yield expressions to the ASTLars Knoll2018-04-271-0/+1
| | | | | | | | | Some smaller changes to the codegen are included as well to ensure that we catch all uses of generators and properly throw an unimplemented error on them for now. Change-Id: Ib915a0e862e128644ff00dfe989507783c912c66 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for arrow functionsLars Knoll2018-04-261-0/+1
| | | | | | | | | | | | | Arrow parameter lists are tricky and require some reparsing by the standard to avoid conflicts in the parser with expression statements. Add an IsArrowFunction flag to the CompiledData::Function. This information is required in the runtime, when creating Function objects, as it does influence their behaviour in subtle ways. Change-Id: I298801b091f98e30a9269d3c77d9ff94e519dabc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Partially support binding patternsLars Knoll2018-04-251-3/+2
| | | | | | | | Destructuring objects works, but arrays are not yet supported. Change-Id: I61e917e1964e3c719f71b8f11d194e09dfe288c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Properly handle redeclarations of variablesLars Knoll2018-04-161-20/+23
| | | | | | | | | | This is only allowed for var type variables. Also fixes an assertion we'd run into with code such as let x; var x; Change-Id: I2588cf37e0964c879c60b4fd292e7d7b5476e322 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Handle function expressions as signal handlersErik Verbruggen2018-03-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two ways to use function expressions on the right-hand side of bindings: property var somethingPressed somethingPressed: function() { /* ..press something else.. */ } signal buttonPressed onButtonPressed: function() { /* ..handle buttonPress.. */ } In the former case, it declares a property that holds a function. So on initialization, the right-hand side of the binding returns a closure that gets assigned to the property 'somethingPressed'. In the latter case, the signal handler is explicitly marked as a function for clarity. So, the handler should not be returning the closure, but the handler should *be* the closure. In general, it is not possible to detect if the left-hand side is a property or a signal handler when generating QML cache files ahead of time. So for this case, we mark the function as only returning a closure. Then when instantiating the object, we check if it is a signal handler, and if the handler is marked as only returning a closure. If so, we set that closure to be the signal handler. Task-number: QTBUG-57043 Task-number: QTBUG-50328 Change-Id: I3008ddd847e30b7d0adef07344a326f84d85f1ba Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* init variables where they are declared when possible (clang-tidy)Shawn Rutledge2018-02-261-3/+3
| | | | | | | | clang-tidy -p compile_commands.json $file -checks='-*,modernize-use-default-member-init,readability-redundant-member-init' -config='{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: "1"}]}' -header-filter='qtdeclarative' -fix Change-Id: I705f3235ff129ba68b0d8dad54a083e29fcead5f Reviewed-by: Johan Helsing <johan.helsing@qt.io>
* use nullptr consistently (clang-tidy)Shawn Rutledge2018-02-261-5/+5
| | | | | | | | | | | | | 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>
* Merge remote-tracking branch 'origin/5.10' into devLiang Qi2018-02-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp src/qml/compiler/qqmlirbuilder.cpp src/qml/compiler/qqmlirbuilder_p.h src/qml/compiler/qqmltypecompiler.cpp src/qml/compiler/qv4codegen.cpp src/qml/compiler/qv4codegen_p.h src/qml/compiler/qv4compileddata_p.h src/qml/compiler/qv4compiler.cpp src/qml/compiler/qv4compilercontext_p.h src/qml/compiler/qv4isel_moth.cpp src/qml/compiler/qv4jsir.cpp src/qml/compiler/qv4jsir_p.h src/qml/jit/qv4isel_masm.cpp src/qml/jsruntime/qv4engine.cpp src/qml/jsruntime/qv4functionobject.cpp src/qml/jsruntime/qv4runtimecodegen.cpp src/qml/jsruntime/qv4script.cpp src/qml/jsruntime/qv4script_p.h src/qml/qml/qqmltypeloader.cpp src/quick/items/qquickanimatedimage.cpp src/quick/items/qquickanimatedimage_p_p.h src/quick/scenegraph/compressedtexture/qsgpkmhandler.cpp tests/auto/qml/qmlplugindump/qmlplugindump.pro tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp tools/qmlcachegen/qmlcachegen.cpp tools/qmljs/qmljs.cpp Done-with: Shawn Rutledge <shawn.rutledge@qt.io> Done-with: Lars Knoll <lars.knoll@qt.io> Done-with: Ulf Hermann <ulf.hermann@qt.io> Change-Id: I010e6525440a85f3b9a10bb9083f8e4352751b1d
* Minor data structure cleanupSimon Hausmann2018-01-221-1/+0
| | | | | | | | The cache files are architecture and ABI independent, so we can remove any associated field/code as well as the workaround for Android. Change-Id: Ia52a5be886fc22a2105460e003e7a76af7dc1818 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Don't create a CallContext if arguments are being used in strict modeLars Knoll2017-11-151-1/+1
| | | | | | | The strict arguments object doesn't need a callcontext. Change-Id: I1d6419c456b28741167f76937906faffd2d5d3b4 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Refactor Call/Construct instructionsLars Knoll2017-11-071-1/+1
| | | | | | | | | | | | | | | | Give them a pointer to argc and argv instead of a pointer to a full callData. Like this we can construct the callData at the end of the JS stack and avoid the need to create an additional copy in VME::exec(). This also opens up the option of completely avoiding all copies for calls into runtime methods. Also make sure that the calldata we pass into other functions is always at the top of the JS stack. Change-Id: I3d0eb49f7bfd7adb9ddabb213422087c66e5a520 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get rid of the hack for named expressionsLars Knoll2017-09-021-2/+2
| | | | | | | | Instead simply use the pointer to the FunctionObject we have in the CallData now. Change-Id: I6d7ed8af22e89e0217bef427110611b661ac7965 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix line number mapping to work with non increasing line numbersLars Knoll2017-08-291-1/+2
| | | | | | | | | The old map assumed that line numbers are always increasing, something that isn't always true. So move to a format where we map blocks of bytecode to a line number instead. Change-Id: I1cd9dd1329d415122cd3d560294ef53007f879f8 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Move line number information into a side tableLars Knoll2017-08-251-0/+1
| | | | | | | | | Don't emit any Line instructions anymore, and instead store the info in a side table in the compiled data, where it can be looked up on demand. Change-Id: Idcaf3bf4ee4129fd62f9e717bf1277dc6a34fe19 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Store arguments in the stack frame before the locals/tempsErik Verbruggen2017-08-031-1/+1
| | | | | | | | | | All escaping arguments will still be loaded/stored from/to the CallData, but this is not the common case. In a subsequent patch we can make the caller prepare the stack frame, and for the common case we don't even need to copy arguments around. Change-Id: I3fbb6fe575a564d05a9fd5dcc0c8f4129eac3bc2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Limit the amount of escaping variablesLars Knoll2017-07-041-4/+6
| | | | | | | | | | Calculate more exactly which variables can be referenced from an inner context, and convert all the non escaping ones to temporaries on the stack. Change-Id: I0e33e85b0f6f426ef2812b8ecccee1870492b7b5 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Properly calculate escaping variablesLars Knoll2017-07-041-8/+8
| | | | | Change-Id: Ia9f0b6d3f31bd3a7bd4316ee3f3e9ff977f973b7 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Split up qv4codegen into several filesLars Knoll2017-07-031-0/+286
And changed the namespace of those classes to QV4::Compiler. ScanFunctions should over time also move into its own file. Change-Id: If084acea4a9a20b9c79ad47dac19e02dc720e098 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>