aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi/qjsengine.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add extension API to QJSEngineMitch Curtis2015-09-251-14/+107
| | | | | | | | | | | | | | | | | | | | | | This allows users in a JavaScript-only environment to install extensions including: - Translation functions (qsTr(), etc.) - The console object (console.log(), print(), etc.) - Garbage collection functions (gc()) This deprecates installTranslatorFunctions(). This API results in less clutter in the API, as we'd otherwise need to have several functions for each type of extension. [ChangeLog][QJSEngine] Introduced an extension API that allows installing various function and object extensions (qsTr(), console.log(), etc.) to QJSEngine. [ChangeLog][QJSEngine] installTranslatorFunctions() was deprecated in favor of the new extension API (see installExtensions()). Change-Id: I4d6eb2097c3eda6810e967b2e8f6441c28c91a16 Task-number: QTBUG-40772 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Rename currentExecutionContext to currentContextLars Knoll2015-09-151-1/+1
| | | | | | | | Now that the other method is gone, let's use the shorter currentContext Change-Id: I2a6fb3b77f83a1ffdf314ad29081e303d17030ed Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Cleanup usage of ExecutionEngine::currentContextLars Knoll2015-09-151-3/+4
| | | | | Change-Id: Ic79d6da162375928ec25871cd0341daeab6483d2 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Doc: Fixed several link errorsNico Vertriest2015-09-071-1/+1
| | | | | | | Change-Id: I684b8c0d238b7592b49abc0156bbc9791fdf6991 Task-number: QTBUG-43810 Reviewed-by: Martin Smith <martin.smith@digia.com> Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
* Hold a pointer to the QV4::ExecutionEngine in the property cacheLars Knoll2015-08-191-1/+1
| | | | | | | This makes more sense than a pointer to the QQmlEngine. Change-Id: Ic6037b0df63b6cf1585539bc3ac78822f0e69d02 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Store rootcontext in a GC safe wayLars Knoll2015-06-171-2/+2
| | | | | Change-Id: If81d638c0ccd2b34df918ae5055e309f4eae031f Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* doc: Remove uses of \mainclassMartin Smith2015-06-071-1/+0
| | | | | | | | This qdoc command is deprecated. Change-Id: I4fd7ab301f1fa5b5b9b5db6a7d710ee2f147dfcb Task-number: QTBUG-46476 Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
* Move more objects from the v4 engine to the js stackLars Knoll2015-04-241-1/+1
| | | | | | | Convert most of the prototype objects in the v4 engine. Change-Id: I365f290493c20973bc991b6a383649836e42a16a Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Move exceptionValue and globalObject from the Engine onto the JS stackLars Knoll2015-04-241-2/+2
| | | | | | | | | We'll need to move all GC'ed objects currently stored in ExecutionEngine onto the JS stack for easier management in a new garbage collection scheme. This is the start of that change. Change-Id: Ib3ad8e846875dade8a807ea79f063173d40e4aad Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.5' into devLiang Qi2015-04-221-9/+19
|\ | | | | | | | | | | | | | | | | Conflicts: src/qml/qml/qqmlbinding.cpp src/qml/jsruntime/qv4arraybuffer.cpp src/qml/jsruntime/qv4functionobject.cpp Change-Id: Ic752e9dfd69b282093651c9234c110a49762f06d
| * Doc: Expand on QJSEngine exception handlingSze Howe Koh2015-04-181-9/+19
| | | | | | | | | | | | | | | | | | | | | | - List the properties provided by the Error object. They consist of the standard properties and a subset of the Mozilla extensions. - Add QJSValue::property() usage to the example code. - Add cross-referencing. - Some rephrasing for clarity and conciseness. Change-Id: I1eb6943899fee2bd81851ccb03660a7a474a975d Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
* | More cleanupsLars Knoll2015-04-211-1/+1
|/ | | | | | | | Get rid of Value::asObject(), and pass const Managed pointers into some more vtable methods. Change-Id: Ia4f427d5fd8868f77b4015d1ce5424d32bfc2115 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* QtQml: Micro-optimize iterator loops.Friedemann Kleint2015-02-261-1/+3
| | | | | | | Avoid repeated instantiation of end() in loops, use variable instead. Change-Id: I3bb1c6918cfd16a5dcefbcc03c442e99fe9bf76b Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-121-7/+7
| | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9 Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
* CleanupsLars Knoll2015-01-231-5/+5
| | | | | | | | Remove duplicated methods. Remove some mostly unused methods, and simplify some others. Change-Id: I605b249e54417bb32c3dfc8e22f2c8b6b684a1e1 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Rework QJSValue internalsLars Knoll2015-01-211-14/+20
| | | | | | | | | | | | | Use a flagged pointer to either store a pointer to a QV4::Value (from the persistent storage) or a pointer to a QVariant in QJSValue::d. Like this we don't need to malloc to create a QJSValue for most use cases. Significantly reduces the memory consumption of QJSValue and speeds it up a lot. Change-Id: I10902cc4b6cc3f43d3f816875dc6c4bbb6b4490f Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Add C++11 move operators, and a simpler internal constructorLars Knoll2015-01-211-6/+6
| | | | | | | | | Move semantics should optimize some copy operations on QJSValues, and the internal constructor will simplify refactoring the QJSValue class to get rid of the extra allocated private. Change-Id: I24863b30523af2432aa81ad6b87fda7fe35749c4 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Refactor persistent valuesLars Knoll2015-01-161-48/+57
| | | | | | | | | | Use a page wise allocation mechanism for persistent values. This significantly reduces memory consumption of persistent values and also improves their performance a lot. Change-Id: I8499d2ca5bdd871e029f643ae605a94544558bb5 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Add ability to retrieve QJSEngine for a given QObjectSimon Hausmann2015-01-121-0/+18
| | | | | | | | [ChangeLog][QtQml] Added qjsEngine(QObject*) getter similar to qmlEngine(object) that allows retrieving the engine for an exposed object. Change-Id: Id14adec58d45fe58133f65bab773b07d6bc18569 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Cleanup variant conversion codeLars Knoll2015-01-091-2/+2
| | | | | | | | Make public methods proper members of the ExecutionEngine, and move private methods into the .cpp file only. Change-Id: I3ca49e39bb1c4e559a2c63346e6ae6cfa446147d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Move the variant conversion methods from qv8engine to qv4::ExecutionEngineLars Knoll2015-01-091-2/+2
| | | | | Change-Id: Ibd529ae5cc3ba06f46152e9daa9119a4e7a2561c Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Make the remaining variant conversion methods staticLars Knoll2015-01-091-1/+1
| | | | | | | And make most private as well Change-Id: If215aba4985a5150aa5a901f2e50e31bf0afa709 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Use QV4::ScopedArrayObject typedef instead of actual typeOleg Shparber2015-01-031-1/+1
| | | | | Change-Id: I975536745ac6c264aca074f84d223fbec7682d3d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Remove v8engine dependency in toVariant conversionsLars Knoll2015-01-021-5/+4
| | | | | Change-Id: I0f2f77c9cc268a0c5ca3ffe0cd66fc98bb1964b3 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Enable gadget wrapping for custom value typesSimon Hausmann2015-01-021-1/+6
| | | | | | | | | | | | | | | | | | [ChangeLog][QtQml] Custom C++ value types annotated with Q_GADGET are now fully accessible in the QML and QJSEngine JavaScript environment. QJSEngine::toScriptValue can be used for injection and fromScriptValue to extraction. The QML "built-in" gadget wrappers for QPoint and the gui types are not exposed this way, toScriptValue(point) will still return an opaque QVariant wrapper. We could expose the core types right away, but then we would be lacking an API to enable use of the Gui types that are registered in QtQuick. It would be better to make the core types in qtbase gadgets and thus enable them without the need for hooks and init functions to be called by the user. Task-number: QTBUG-29769 Change-Id: I8179cd599bdc1209ff61cfdbdda419cb400296bb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fix constructions of QJSEngine objectsLars Knoll2015-01-011-2/+3
| | | | | | | | The private class is not empty anymore, so calling the wrong constructor would lead to memory corruption Change-Id: I6d477fc63bba46be733273f548397c2a50ef2bf4 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Make QQmlPropertyCache available in QJSEngineSimon Hausmann2014-12-291-0/+21
| | | | | | | | | The QQmlEngine has two containers for property caches, one for QML types and one for all-purpose meta-objects. The latter is rather useful and now being moved to QJSEngine to be available there. Change-Id: Ieab65c400b8a2e410e5f9eee6d603162dbb864d9 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Make Managed inherit ValueLars Knoll2014-12-201-2/+2
| | | | | | | | This completes the first milestone towards being able to move objects across the GC heap. Change-Id: I8e6ce90254ea767188a31f0dc85b133534c87eb0 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Move prototype back from the vtable into ObjectLars Knoll2014-12-111-3/+3
| | | | | | | | This is the only way we can support a GC that moves objects around in memory. Change-Id: I1d168fae4aa9f575b730e469e762bc5b5549b886 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Better encapsulate access to the global objectLars Knoll2014-12-111-2/+2
| | | | | Change-Id: I8a76112d821cb3fc172ba0d16ee8410d39b4422a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Encapsulate accesses to the root contextLars Knoll2014-12-111-2/+2
| | | | | Change-Id: I668cef1363a5c1a5c5b9a7e138f3bd0338712eea Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Merge remote-tracking branch 'origin/5.4' into devSimon Hausmann2014-12-091-0/+6
|\ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/qml/jsruntime/qv4arraydata.cpp src/qml/jsruntime/qv4context_p.h src/qml/jsruntime/qv4globalobject.cpp src/qml/jsruntime/qv4internalclass.cpp src/quick/items/qquicktext_p.h src/quick/items/qquicktextedit_p.h src/quick/items/qquicktextinput_p.h Change-Id: If07e483e03197cb997ef47a9c647a479cdb09f4c
| * Add string::arg method in installTranslatorFunctionsKai Koehne2014-12-051-0/+6
| | | | | | | | | | | | | | | | | | | | | | QJSEngine::installTranslatorFunctions install the translator functions to any given JS object. However, the custom string::arg() method is only added in qqmlbuiltinfunctions.cpp, making the use of qsTr() in other pure-JS programs quite hard. Task-number: QTBUG-43113 Change-Id: Ia9ed97a4c07a4d167c792f3ea13e4f6e96c97423 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* | Cleanup exception catching codeLars Knoll2014-11-151-1/+1
|/ | | | | Change-Id: I85afd5758f72e19c280dc196601ee145f0c25f01 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix mapping of JS objects/arrays to C++Simon Hausmann2014-09-171-11/+16
| | | | | | | | | | | | | | | [ChangeLog][QtQml][Important Behavior Changes] When a JavaScript object/array is passed to C++ through a QVariant, the engine no longer immediately converts the object recursively into a QVariantMap or QVariantList but instead stores a QJSValue in the QVariant. This prevents a loss of data when the JS object contains non-primitive types such as function objects for example. Code that expects the variant type to be exactly QVariant::Map or QVariant::List may need to be adapted. Registered conversion functions however ensure that code that merely calls toMap() or toList() continues to work. Task-number: QTBUG-40431 Change-Id: I1dbc1d5f8e78ad28bb62db3681b9a0b34557e7f5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Update license headers and add new licensesJani Heikkinen2014-08-251-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 & LICENSE.GPLv2 - Removed LICENSE.GPL Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0 Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
* Convert ExecutionContext to new storage schemeLars Knoll2014-07-221-1/+1
| | | | | Change-Id: I9fcc13da5360f37cef3149b114ed9263b9b74281 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Add support for translations in pure QJSEngine based environmentsSimon Hausmann2014-06-131-0/+40
| | | | | | | | | | | Re-add the QScriptEngine::addTranslatorFunctions API that brings back qsTr() and friends to pure QJSEngine based environments. The auto-test were also ported where applicable. Change-Id: Ib03e3495ef09eeea9e4c8341061499768caed307 Sanity-Review: Simon Hausmann <simon.hausmann@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fix QJSEngine::evaluate using the wrong execution contextv5.3.0Simon Hausmann2014-05-091-4/+9
| | | | | | | | | | | | | | | | | | In contrary to what the documentation says, QJSEngine in Qt 5.x executes in the context of the global object (QScriptIsolate always called enter on the QV8Engine's "root" context, thus making it current). The v4 implementation unfortunately did what the documentation said and used the current context, which is wrong in many ways. For example it completely breaks the optimization of stack allocated contexts, because when a C++ callback is called from within a JS function with a stack allocated context and that C++ code calls QJSEngine::evaluate and creates new closures, the stack context would become an outter context and cause crashes during GC. This patch restores the behavior of Qt 5.0/5.1 and fixes the documentation. Task-number: QTBUG-38530 Change-Id: Ie6481f02e676954cc94b188a1c87c88e7c56dafa Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Document QJSEngine as reentrant.Michael Brasser2014-04-101-0/+1
| | | | | Change-Id: I7fc41b33036bca6736bc24fa62522ce5d30ef1f4 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Cleanup our runtime methodsLars Knoll2014-03-111-1/+1
| | | | | | | | | Move all our runtime methods into the QV4::Runtime struct and give them nicer names without underscores. Sort them logically and remove a few unused methods. Change-Id: Ib69b71764ff194d0ba211aac581f9a99734d8180 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Make it possible to call QQmlEngine::setObjectOwnership at any timeSimon Hausmann2014-03-021-1/+5
| | | | | | | | | | | | | QJSEngine::newQObject should call setObjectOwnership only if it wasn't called before, to preserve any policy set by the user earlier. Otherwise it's only safe to call after newQObject and then you'd have to call it _every_ time the QObject is wrapped, at all call sites. Instead this patch preserves any policy set. Task-number: QTBUG-37160 Change-Id: I6178fa38cd7f4b09d818b6f18762c21588562422 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Encapsulate the current context and fix it's usageLars Knoll2013-12-041-1/+1
| | | | | | | | | | | Encapsulate accesses to the current context, and rework the way we push and pop this context from the context stack. Largely a cleanup, but simplifies the code in the long term Change-Id: I409e378490d0ab027be6a4c01a4031b2ea35c51d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fixup the implementation mess for QJSValue(QString)Lars Knoll2013-12-041-0/+49
| | | | | | | | | | | | | | | Until now we were using a QV4::String without engine to represent this case. But this leads to lots of quirks, where we ended up trying to access the engine (or the internalclass/vtable) of this string anyway. Now just represent it by using an QString in QJSValuePrivate, and use an empty value to represent it. This adds a little bit of code to QJSValue and QJSEngine, but is more stable and maintainable in the longer term. Change-Id: I3358165ee64e788274225743a95dfb13346225cc Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Properly propagate parse errorsLars Knoll2013-10-291-7/+7
| | | | | | | | Replace all try/catch statements used when parsing with checks for engine->hasException. Change-Id: I4493cb600d5a3eb095c2003bb88bd031403e47c9 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Touch up QJSEngine::evaluate documentation.Mitch Curtis2013-10-141-4/+4
| | | | | Change-Id: I350ad1ccb8a6cf522787e4579292fa4ba1c8e043 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Cleanup exception handlingSimon Hausmann2013-10-031-1/+0
| | | | | | | | | | The code in the Exception class operates entirely on the engine's data, so move it into ExecutionEngine instead. This eliminates the need for a QV4::Exception class and catches and old code that tries to still do catch (Exception &) instead of catch (...) Change-Id: Ie608bec6af652038aca6c9423c225a4d7eb13b39 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change exception handling APISimon Hausmann2013-10-021-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes the exception handling API in the engine slightly, encapsulating any use of direct throw statements and catch blocks with concrete types. In the future we need to be able to change the way these are implemented, in order to ensure that the correct stack unwinding code is triggered for throw and re-throw. This patch separates the C++ exception object thrown from the V4 exception (that includes value, throwing context pointer) and stores the latter inside the engine. In order for that to compile, ExecutionEngine::StackTrace and StackFrame had to move into the QV4 namespace directly. In addition the syntax for catching exceptions changes from try { ... } catch (QV4::Exception &ex) { ex.accept(context); QV4::ScopedValue exceptionValue(scope, ex.value()); } to try { ... } catch (...) { QV4::ScopedValue exception(scope, context->catchException()); } Context::catchException() checks if there's a "current" exception in the engine, and if not assumes that we caught an unrelated exception and consequently re-throws. partiallyUnwind() is also gone and replaced with rethrowException(), in order to encapsulate the re-throw. Lastly, in the future nesting try/catch blocks isn't going to be possible due to limitations in the common C++ ABI with regards to foreign exceptions. Change-Id: Ic81c75b057a2147e3176d8e0b4d326c14278b47d Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Move more API over to use ValueRefLars Knoll2013-09-261-1/+3
| | | | | Change-Id: I372f1f3e3e78d45912a913f437e622e0acfc9646 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix Persistent/WeakValue APILars Knoll2013-09-261-4/+11
| | | | | | | Don't use unprotected Values in the API anymore. Change-Id: I8851628227fca374de24701bc8ee0908b5ae3923 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>