aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
Commit message (Collapse)AuthorAgeFilesLines
* Eliminate QT_QML_BEGIN_NAMESPACE and QT_QML_END_NAMESPACEShawn Rutledge2019-03-2213-30/+26
| | | | | | | These are equivalent to the usual namespace macros. Change-Id: I3891397511e29694fe508414e77eb8483b877e03 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-03-185-29/+58
|\ | | | | | | | | | | | | Conflicts: src/qml/compiler/qv4codegen.cpp Change-Id: I66b7db42bf208855889094ace0267326595ce03c
| * Unify the JavaScript parsing recursion checksUlf Hermann2019-03-154-14/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | We only need to check in one central location and we can allow for more recursion. 4k recursions seem tolerable. A common default for stack sizes is 8MB. Each recursion step takes up to 1k stack space in debug mode. So, exhausting this would burn about half of the available stack size. We don't report the exact source location in this case as finding the source location may itself trigger a deep recursion. Fixes: QTBUG-74087 Change-Id: I43e6e20b322f6035c7136a6f381230ec285c30ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| * Save some stack space during code generationUlf Hermann2019-03-142-18/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Result objects are rather large, 96 bytes here. In a recursive algorithm such as our parser, we should not keep too many of them on the stack. Also, the size of Reference can be reduced by employing a bit field rather than a number of booleans. Also, try to convince the compiler to inline the accept() functions. The extra stack frames those create are unnecessary. Task-number: QTBUG-74087 Change-Id: I5c064491172366bb0abef99ffe9314080401a7d1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-02-201-2/+6
|\| | | | | | | Change-Id: I69c3e6610ff590d9c18f386fc17ed2e429b58d26
| * QML: Don't crash the parser on certain kinds of bad inputUlf Hermann2019-02-181-2/+6
| | | | | | | | | | | | Fixes: QTBUG-72734 Change-Id: I92146ec517c6a26a67e13830618e137f2a3021c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | V4: Move the FixedPoolArray into the MemoryPool headerErik Verbruggen2019-01-251-0/+77
| | | | | | | | | | | | | | So now the FixedPoolArray can be re-used in other places. Change-Id: I0e0504892944722a0c18f207dc6400d5b314f6ae Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into devQt Forward Merge Bot2018-12-121-1/+1
|\| | | | | | | | | | | | | Conflicts: tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp Change-Id: Ic1dace832ad4b29023d24808b8617b5dcc915eb5
| * Merge remote-tracking branch 'origin/5.12.0' into 5.12Qt Forward Merge Bot2018-12-071-1/+1
| |\ | | | | | | | | | | | | | | | | | | | | | Conflicts: src/qml/jsruntime/qv4script.cpp src/qml/parser/qqmljslexer.cpp Change-Id: I82252a8c504a4b77c45f4f8efe849ff9acb949fd
| | * QML Lexer: Stop scanning template literals on closing '`'v5.12.0-rc2v5.12.0-rc1v5.12.0Ulf Hermann2018-11-191-1/+1
| | | | | | | | | | | | | | | | | | | | | Fixes: QTBUG-71812 Change-Id: I93b99496a7572c0f5128c69b865bb2b4f87d29af Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* | | Merge remote-tracking branch 'origin/5.12' into devQt Forward Merge Bot2018-11-302-7/+17
|\| | | | | | | | | | | Change-Id: Ie977b1998eba8c9aa8582a96132bf1aa0ec55ca4
| * | JS: Limit expression and statement nesting levelErik Verbruggen2018-11-291-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is to prevent extremely deeply nested expressions and statements make the code-generator run out of (native) stack space. Task-number: QTBUG-71087 Change-Id: I8e1a20a361bff3e49101e535754546475a63ca18 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| * | Fix failing assertion in memory pool allocator in large QML scenesVitaly Fanaskov2018-11-281-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the previous implementation MemoryPool wasn't able to allocate more memory than predefined block size (8 kB). Now, if a user tries to allocate more memory than default block size, the block size will be increased for current block only. All remain space in a new block will be used according to the current allocation strategy. Increasing block size of some certain blocks doesn't lead to reallocation of the entire memory pool. Also this situation happens very rarely, e.g., when compiling something contains more than approx. 2500 objects. Also fixed some warnings and used more casts in C++ style. Fixes: QTBUG-71195 Change-Id: I65d57959849f282178cffc92285a6a32f6bb9b25 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | | Merge remote-tracking branch 'origin/5.12' into devQt Forward Merge Bot2018-11-064-26/+68
|\| | | | | | | | | | | Change-Id: I85be5e6ef173fa733d7febd3209164bb31762e0d
| * | Pass the raw string value to template literalsLars Knoll2018-11-022-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | They are required for spec compliance of tagged templates. Change-Id: I8ef8e2314843f07a02d204394400f3f3894f8f91 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| * | Also store the raw string value for template strings in the lexerLars Knoll2018-11-022-22/+48
| |/ | | | | | | | | | | | | | | This is required to properly implement support for tagged templates and String.raw. Change-Id: Id548f97dd8ebfb7206abb55967f979c3fa6f6eea Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* | Add an extra diagnostic kind "Hint"Ulf Hermann2018-10-241-1/+1
| | | | | | | | | | | | | | | | We will want to use that for things like "Don't do this if you want to use Qt Quick Designer on the file". Change-Id: I50fefd9dc8896fe98612519dfc8fa765abea2677 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Move QQmlJS::SourceLocation to its own fileUlf Hermann2018-10-244-23/+91
|/ | | | | | | | We shouldn't need to include all of the QmlJS AST to deal with source locations. Change-Id: I09bd32656b151136fe7cc70318aad26fec3e0056 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* JS: Fix stack buffer overflow in the QML/JS parserLars Knoll2018-10-181-15/+10
| | | | | | Task-number: QTBUG-71083 Change-Id: I7a06a01871c2ae0b3162699189c4e836c36d7759 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Correctly create methods for functions in object literalsLars Knoll2018-08-313-2/+5
| | | | | | | | | | Methods behave slightly different than normal functions as they have a home object and define how super property access is being done. To implement this correctly, we need to create these methods during object initialization time. Change-Id: Ib3f670c8790b882c6472de786938ca4f0b73f66f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix the class name property of default exported classesSimon Hausmann2018-08-161-0/+8
| | | | | Change-Id: I171e571a336a15c27881999a10ffe3c52e92d816 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix the name of anonymous generators and function declarationsSimon Hausmann2018-08-151-5/+12
| | | | | | | | | | | | | | | | | | The spec says in 14.4.12 that an anonymous generator declaration can only occur as part of the export declaration. The same applies to anonymous function declarations in 14.1.20. It is only in the default export declaration rule that we can detect that we have an anonymous declaration/generator, so that is where we implement the step of setting "default" as the function name. It is safe to use an empty string in GeneratorDeclaration_Default and FunctionDeclaration_Default because that rule is only referenced from HoistableDeclaration_Default, which in turn is only referenced from ExportDeclaration. Change-Id: Ibd341b941f67cbcc727da4df23af04af313b6251 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix usage of const in for declarationsSimon Hausmann2018-08-152-0/+3
| | | | | | | | | | | | | | | We correctly produce a syntax error for a const declaration that is without an initialize, such as const x; but we have to make an exception if it's part of a for declaration, such as for (const x of [1, 2, 3]) Change-Id: Iab86d73f2edc1f3deaf62f0f43f8b04789696b65 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Cleanup RegExpObjectLars Knoll2018-08-152-1/+3
| | | | | | | | | | | Move properties from RegExpObject to getters in RegExp.prototype to be compliant with the JS spec. Implement support for the sticky flags ('y') and correctly parse the flags in the RegExp constructor. Change-Id: I5cf05d14e8139cf30d46235b8d466fb96084fcb7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify ES module body handlingSimon Hausmann2018-08-144-99/+16
| | | | | | | | | Now that ImportDeclaration and ExportDeclaration are also statements in the AST, we can get rid of the ModuleItemList in the AST. We keep it in the grammar, but map it to a statement list. Change-Id: I4cab29fe9b075e88454fe3b194126f728000856a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix module dependency handlingSimon Hausmann2018-08-143-26/+13
| | | | | | | | | | | | | | | | | | | | | 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 multi variable module import listsSimon Hausmann2018-08-141-1/+1
| | | | | | | | Select the correct head when finishing the linked list for ImportList AST nodes. Change-Id: I34ae2ccfd0e969dbd92ce2458de019bb02046aa5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix support for default exports in modulesSimon Hausmann2018-08-103-12/+31
| | | | | | | | | | | 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>
* Enable unicode regular expressionsLars Knoll2018-08-102-1/+3
| | | | | | | Add support for the 'u' flag for regular expressions. Change-Id: I409054eaa9c50183619752d14f2638f5a38c0ea7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add initial basic support for ES6 modulesSimon Hausmann2018-08-092-1/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix grammar for ES modulesLars Knoll2018-08-023-5/+7
| | | | | | | | | | | | * Always parse 'import' as a keyword, as it is now one in Qml and ES. * Always parse 'as' as keyword but allow it as identifier using the same trick as for the other keywords. This fixes basic import statements such as import "foo.mjs" as bar but still allows funny variations such as import "foo.mjs" as as. Change-Id: I76a600aab90c1b5c07d079bf11b0a78742d44c53 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix typoLars Knoll2018-08-011-4/+4
| | | | | Change-Id: Iad064b97010548304e37ad6592712d585d2885a3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Smaller grammar cleanupLars Knoll2018-08-011-16/+2
| | | | | Change-Id: Ic0b70e9b2c6f656a8abdf408013201625045ac65 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify parsing of pragma directivesLars Knoll2018-08-015-96/+12
| | | | | | | | We only support 'pragma Singleton' currently, so there is no need to parse the right hand side of pragma as a member expression. Change-Id: Ic0dcbedb52cb58db2fd1cc099f14fd399b7162e3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Build AST nodes when parsing ES6 modulesSimon Hausmann2018-07-315-1/+891
| | | | | | | | | | | | | This introduces the structures in the AST that allow for the extraction of imports, exports as well as location of tokens. The ModuleItemList as entry point is special with regards to the statements (so not import/export declarations) in the sense that the statement list contained in ModuleItemList::item is not linked yet between different ModuleItemList instances. Change-Id: If553a6ebaf53d5f3cf755c8327d3fe0ea7db68c2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.11' into devQt Forward Merge Bot2018-07-162-1/+23
|\ | | | | | | | | | | | | | | Conflicts: src/quick/items/qquickloader.cpp tests/auto/quick/qquickanimations/tst_qquickanimations.cpp Change-Id: I0cb9f637d24ccd0ecfb50c455cc210119f744b02
| * Fix conversion of numeric literals in the AST to stringsSimon Hausmann2018-07-132-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | After commit 91f3687ee51db83d9018bd61c3fbc736c6e9912e in qtbase, QString::number includes a zero padding in the exponent that breaks compliance with the ECMAScript tests. Instead of QString::number, we have to use a QLocale instance that turns off the padding of the exponent. Change-Id: Ib8c63bc501cadca026c52359006628f6c271ba6d Task-number: QTBUG-69432 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* | Fix naming of classes in class expressionsLars Knoll2018-07-033-1/+46
| | | | | | | | | | | | | | | | As with function expressions, class expressions also get an implicitly defined name if they are directly assigned to a named variable. Change-Id: I5fda9d74c1c299107f15b82245333b54ca6d8917 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Properly distinguish between class expressions and declarationsLars Knoll2018-06-265-2/+49
| | | | | | | | | | | | | | | | Introduce both types in the AST, and handle them properly in the code generator. Change-Id: I754ac0976de69009bdb8b203d890e4ec0ad03b30 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix string memory leak in JavaScript ASTSimon Hausmann2018-06-254-16/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 02252ae08d introduced a QString member in a JS memory pool class, which leaks unfortunately as the pool is not designed to call destructors of allocated types. Typically strings in the AST are derived from input and therefore a QStringRef is fine. The bindingIdentifier in the PatterElement however is sometimes synthesized, so a separate storage for dynamically allocated strings in the memory pool allows for using QStringRef again. Change-Id: I94d090df653d784c554452722b3b759031e4735b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Fix const expressions containing destructuring patternsLars Knoll2018-06-211-1/+0
| | | | | | | | | | | | | | | | Don't throw a syntax error when encountering a destructuring pattern. Change-Id: I93250a2963d2d50ff61d725229e1b51be17689e9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix array destructuring nested in a rest elementLars Knoll2018-06-211-18/+18
| | | | | | | | | | Change-Id: I3a8c15fe221bff04a3b9b21ed8c0b06c04770a3d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix more issues with destructuringLars Knoll2018-06-212-25/+23
| | | | | | | | | | | | | | | | | | | | Fix destructuring targets that are complex lhs expressions. There are still some failures remaining, but this fixes another larger chunk of test cases. Change-Id: Icf08f42d7c70d4e81be5d5d2e27ebe6249d25467 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix handling of elisions in destructuring expressionsLars Knoll2018-06-213-14/+13
| | | | | | | | | | | | | | | | We need to iterator over elisions at the end, as those could trigger side effects by calling iterator.next() Change-Id: Ieb5fa3562b6e60fdf179fa228510b2eeaaf9da30 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix more test failures for destructuring expressionsLars Knoll2018-06-211-3/+6
| | | | | | | | | | | | | | | | Fix parsing of var { x = function(){} } = ... Change-Id: I524e39c7a556c392a5359eafc445b59020ccadf2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Correctly set the name of anonymous functions in most casesLars Knoll2018-06-211-0/+6
| | | | | | | | | | | | | | | | If the anonymous function is bound to an identifier, set the name to the identifier. Change-Id: Idbb3170210e6f91cca3c9bd36b2b6ddcb3a50c7b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Allow a trailing comma in parameter listsLars Knoll2018-06-211-8/+19
| | | | | | | | | | | | | | | | This got changed in ES8, but let's already take this in now, as there are quite a few tests checking this behavior. Change-Id: I73f86b8fd8a681881bcc9cc3132bef1589d5194f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | The first branch in a ( ? : ) operator can always include the in keywordLars Knoll2018-05-281-1/+1
| | | | | | | | | | | | | | Fix the grammar to be compliant with the spec in this case. Change-Id: I5740c9427db6f5c6c2551d4e23f1f14070e497fb Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
* | Fix multi line string literals using backquotesLars Knoll2018-05-261-1/+1
| | | | | | | | | | | | Task-number: QTBUG-67476 Change-Id: Ia8c6863ad35c8a92298e5dffd750d17628200573 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Unify AST for the different 'for' statementsLars Knoll2018-05-115-46/+5
| | | | | | | | | | Change-Id: I70ca83b0ce933d64dad4984a236e48592e989742 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>