summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4functionobject.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Cleanup JS stack allocationsLars Knoll2018-05-261-1/+1
| | | | | | | | Avoid double writes to the stack, and use scope.alloc() for most allocations on the stack. Change-Id: I8b89273c1b6796d955fc8eeb72c67cff208ef786 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove spurious qDebug()Lars Knoll2018-05-241-2/+0
| | | | | | | Amends e87b82351762663fa2ebd7e3589e99004bfd5b17. Change-Id: Ia46d38047f8201555fa1083c24ddf93eac8852bd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix Function.prototype.nameLars Knoll2018-05-241-0/+1
| | | | | Change-Id: I2ace040cc8f65d34412909bf677252b097ab0aa3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix some corner cases when parsing Function(...)Lars Knoll2018-05-241-1/+3
| | | | | | | | | | | The arguments of the body could end with a comment, so insert a newline before the closing braces to parse this correctly. Unfortunately doesn't cause the test case to pass as it's verification code that this worked has a bug. Change-Id: Ifaed50e75aa987809bc36faea51c356026d3fd13 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Print function identifier when calling toString() on a functionMitch Curtis2018-05-231-1/+13
| | | | | | Task-number: QTBUG-50669 Change-Id: Ia0e9491b12ca1db1da2bfa8eb5ca8bbe4658f699 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Ensure we have a lexical scope for global codeLars Knoll2018-05-111-1/+1
| | | | | | | | | | | | | | | This requires a bit more work than simply pushing a new BlockContext for the lexically declared variables, as eval() and the Function constructor operate on the global scope (including the lexically declared names). To fix this introduce Push/PopScriptContext instructions, that create a BlockContext for the lexically declared vars and pushes that one as a global script context that eval and friends use. Change-Id: I0fd0b0f682f82e250545e874fe93978449fe5e46 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* name anonymous functions that wayLars Knoll2018-05-031-1/+1
| | | | | | | | | Function and Generator objects created through the Functon or GeneratorObject constructors are supposed to have the name "anonymous" (ref. section 19.2.1.1.1 in the ES8 spec) Change-Id: I1eff4abce882b9508f8e161de1de9efaca1a5129 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add Generator supportLars Knoll2018-05-031-20/+31
| | | | | | | | | | | | | Add support for ES6 generators. Those are currently always executed in the interpreter (we never JIT them), to simplify the initial implementation. Most functionality, except for 'yield *' expressions are supported. 'yield *' will have to wait until we support for(... of ...) Change-Id: I7c059d1e3b301cbcb79e3746b4bec346738fd426 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Cleanup creation code for builtin functionsLars Knoll2018-05-021-0/+12
| | | | | | | | Centralize the code in FunctionObject::createBuiltinFunction and setup function names and length properties there. Change-Id: I21f1d42b475070ee091d96d97387149af1dc47f2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Make instanceOf compliant with the ES7 specLars Knoll2018-05-021-0/+13
| | | | | | | | Add implementation for Function.prototype[Symbol.hasInstance] and call it when defined. Change-Id: Iad6b0c075452b46ba710ffe7b94b74b71f715d22 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix crash in Function.prototype.bindLars Knoll2018-05-021-7/+9
| | | | | Change-Id: I0251b2b38f4b48c7ed35d22f88c0c5c4a98e6464 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove String dependency from InternalClassLars Knoll2018-05-021-4/+4
| | | | | | | | This is required, so we can also use Symbols in the internal classes. Change-Id: I630e7aa7b8b16d5a94041f8d18515fd582f94264 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix length property of Function objectsLars Knoll2018-04-261-1/+1
| | | | | | | | | | | According to ES6, the length property is the number of required arguments, ie. the number of arguments until the first arg that has adefault parameter. Also fix a crash when parsing a parameterlist with a trailing comma. Change-Id: I4f6b2be4feae7b513388be66b43b160bb3cc77f1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Clean up handling of the 'caller' propertyLars Knoll2018-04-261-9/+0
| | | | | | | | | | This brings it closer in line with the ES8 spec. Also remove a couple of tests testing the 'caller' property of non strict functions, as it's not mandated by the spec and we never set it. Change-Id: Icece8a03989c474df1eae0e4e77b356e49575b32 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Correctly check for duplicate parameter namesLars Knoll2018-04-251-0/+3
| | | | | | | | Those are not allowed as soon as we have default values for parameters or rest arguments. Change-Id: I7dec826c37e6045e4dd1f6b0adb90301efe33daf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/5.11' into devQt Forward Merge Bot2018-04-181-15/+32
|\ | | | | | | Change-Id: I4a9c7802c180757e70fa4dd16df3287104a088bc
| * Fix calling Qt.binding() on bound functionsLars Knoll2018-04-161-15/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | garbage collect InternalClassLars Knoll2018-04-121-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Internal classes are now allocated and collected through the GC. As they are important to the deletion of other objects (because of the vtable pointer living inside the internal class), they need to get destroyed after regular objects have been sweeped. Achieve this by using a separate block allocator for internal class objects. Our lookups do often contain pointers to internal classes, so those need to be marked as well, so we don't accidentally collect them. Change-Id: I4762b054361c70c31f79f920f669ea0e8551601f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Better encapsulation for EngineBase::internalClassLars Knoll2018-04-121-3/+3
| | | | | | | | | | | | | | | | Turn it into a method instead of accessing the array directly to simplify refactoring. Change-Id: I197b56c8f58cfdfd294f429e6b15268c755f9837 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Clean up Engine::newObject/newArrayObjectLars Knoll2018-04-121-1/+1
| | | | | | | | | | | | | | They don't need a prototype argument neither anymore. Change-Id: I80fa99cb382e8dca4cfa51fdd87b4c9b0f59573a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Disambiguate different allocation functions in the memory managerLars Knoll2018-04-121-1/+1
|/ | | | | | | | | | | Some compilers (in this case MingW 5.3) don't manage to properly disambiguate the template overloads, and try to instantiate the wrong template function. Solve this by renaming the one of the template functions. Change-Id: I3574e617fe96c4bd52920a0127a1dfe39cc3d302 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* use nullptr consistently (clang-tidy)Shawn Rutledge2018-02-261-3/+3
| | | | | | | | | | | | | 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>
* Get rid of BuiltinFunctionLars Knoll2018-01-151-21/+0
| | | | | | | It's now unused. Change-Id: Id2941c212d488c9b0933fa06aac9922b9db13a05 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Bring back markObjects(), this time generatedLars Knoll2017-11-141-2/+0
| | | | | | | | Doing the marking of objects in a function instead of using the table seems to be somewhat faster. Change-Id: I9ec00cc0264f9a15c69b285db493bee31d99bf96 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Convert more builtin methods to new calling conventionLars Knoll2017-11-131-10/+10
| | | | | | | | Convert the methods of the global object and the remaining methods in in the Function object. Change-Id: I7c9a5f39b07f9c9cb0f31e83cdf41fade71a7dc5 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Introduce new calling convention for builtin functionsLars Knoll2017-11-131-52/+58
| | | | | | | And implement Function.apply()/call() with it. Change-Id: I028c82d5f9adfd23328d669db1adccec9de5824c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Cut out one more C++ layer when doing JS function callsLars Knoll2017-11-131-18/+4
| | | | | Change-Id: I0e2ac30b7e6d77fe41deb84a97b0a7f220437c6a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove one indirection when doing JS callsLars Knoll2017-11-071-17/+6
| | | | | Change-Id: Idcc313903b1ac39f6ab8914751fa8bf3f6269115 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Change signature for call/callAsConstructorLars Knoll2017-11-071-60/+68
| | | | | Change-Id: I159b57acc7a2133ef1ad545aa84e792c63449a57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Rename the construct 'virtual' method to callAsConstructorLars Knoll2017-11-071-7/+7
| | | | | | | To make it consistent with the rest of the engine. Change-Id: I57b98fa26134f9864c663f47371ef3e9ca16ac9c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Simplify JSCallData constructionLars Knoll2017-11-071-2/+2
| | | | | Change-Id: Ic53532edae9a209aa7125af6f00a9d993d74f1a3 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get rid of the implicit cast operator to a CallDataLars Knoll2017-11-071-2/+2
| | | | | Change-Id: I1c35fbf8f7355bc2393ae931f99e591b800f2f45 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Rename JSCall to JSCallDataLars Knoll2017-11-071-5/+6
| | | | | | | | 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>
* Change signature of call/constructLars Knoll2017-11-071-11/+13
| | | | | Change-Id: I139a7a31651d9a2ea46ced88978ac4633294bc60 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Add functions pointers for call/construct to FunctionObjectLars Knoll2017-11-071-4/+22
| | | | | | | | This will allow us to avoid one level of indirection when calling js functions in the future. Change-Id: I814b72d18adb5a5580c11053e53b582549b629fc Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Refactor Call/Construct instructionsLars Knoll2017-11-071-5/+9
| | | | | | | | | | | | | | | | 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>
* Optimize Function.apply and calling bound functionsLars Knoll2017-10-231-69/+62
| | | | | Change-Id: I11d2db6c912f52ec6dff90a2637644689d8d6fb6 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Change CallData::argc to be a QV4::ValueErik Verbruggen2017-09-191-15/+15
| | | | | | | | | | | Instead of mimicking a Value. This makes sure that argc now stays correct even when anything on Value changes. Most of the change is mechanical: replace callData->argc by callData->argc(). Change-Id: I521831ae1ffb3966bad6589c18d7a373e13439d7 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Always set the correct FunctionObject when calling JS functionsLars Knoll2017-09-021-28/+25
| | | | | | | | | 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>
* Move the stack limit check into VME::execLars Knoll2017-09-011-5/+0
| | | | | Change-Id: Iac870dbb1b2cbf26501694319ebcc168ec9b1df1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* CleanupsLars Knoll2017-09-011-5/+0
| | | | | Change-Id: Iba5a238c98617f99049dc0e529e642b924e42755 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify JSStackFrame and CallDataLars Knoll2017-09-011-1/+1
| | | | | Change-Id: I4494dae8166026074c9efc74bac62de9d3fa2342 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Use the context member in CallDataLars Knoll2017-09-011-2/+4
| | | | | | | | 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>
* Get rid of the FunctionObject parameter to VME::exec()Lars Knoll2017-09-011-2/+2
| | | | | Change-Id: I5b833d1f76899a5b8fceb0f4fc109b77b1b431fc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Cleanup argument handling in contextsLars Knoll2017-08-181-2/+2
| | | | | | | | | | | | | | | | | | Fix the compiler to already deal with duplicated argument names. Doing this at runtime was not ideal. Remove the callData member from the context. Instead use the fact that the arguments already followed the locals in the context. Don't copy the thisObject over into the CallContext anymore, it's never used from there anyway. Fix the ordering of names in the internalclass, so that arguments don't require special handling anymore when looking them up by name. Adjust all places that used callData, and related methods. Change-Id: I0bc45e1be3f1fcd38dc3b4f04e91edaf7b9ed103 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Always create a valid CallData object for interpreter callsLars Knoll2017-08-101-2/+2
| | | | | | | | 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>
* Fix a bug in new Function()Lars Knoll2017-08-101-1/+1
| | | | | | | | The strict mode of the generated function should not depend on the strict mode of the surrounding context. Change-Id: I15a0c8f89f8cb19a3cd14622fa03187411e00cbf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Get rid of simpleCallLars Knoll2017-08-101-13/+2
| | | | | | | | 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>
* Avoid creating a CallContext for simple functionsLars Knoll2017-08-101-10/+10
| | | | | | | | This cuts out quite a bit of overhead when entering and leaving functions. Change-Id: I32670c98a4087ea3b2d45853d9cabff9066399e8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>