Fix QJSEngine::evaluate using the wrong execution context
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 5 May 2014 13:45:54 +0000 (15:45 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 9 May 2014 15:27:07 +0000 (17:27 +0200)
commit073cde9d21f95a896ffff3abfcc9a9da89175e28
treebe52c78b99e870489e7cb336a1110859a44605f6
parent0640dce6cd3200979a9b98d5bbae4526fc6dcec8
Fix QJSEngine::evaluate using the wrong execution context

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>
src/qml/jsapi/qjsengine.cpp
tests/auto/qml/qjsengine/tst_qjsengine.cpp