summaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine/tst_qjsengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qjsengine/tst_qjsengine.cpp')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index b2723b02fd..17acb4fd32 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -157,6 +157,8 @@ private slots:
void dynamicProperties();
+ void scopeOfEvaluate();
+
signals:
void testSignal();
};
@@ -3011,6 +3013,43 @@ void tst_QJSEngine::dynamicProperties()
}
}
+class EvaluateWrapper : public QObject
+{
+ Q_OBJECT
+public:
+ EvaluateWrapper(QJSEngine *engine)
+ : engine(engine)
+ {}
+
+public slots:
+ QJSValue cppEvaluate(const QString &program)
+ {
+ return engine->evaluate(program);
+ }
+
+private:
+ QJSEngine *engine;
+};
+
+void tst_QJSEngine::scopeOfEvaluate()
+{
+ QJSEngine engine;
+ QJSValue wrapper = engine.newQObject(new EvaluateWrapper(&engine));
+
+ engine.evaluate("testVariable = 42");
+
+ QJSValue function = engine.evaluate("(function(evalWrapper){\n"
+ "var testVariable = 100; \n"
+ "try { \n"
+ " return evalWrapper.cppEvaluate(\"(function() { return testVariable; })\")\n"
+ " ()\n"
+ "} catch (e) {}\n"
+ "})");
+ QVERIFY(function.isCallable());
+ QJSValue result = function.call(QJSValueList() << wrapper);
+ QCOMPARE(result.toInt(), 42);
+}
+
QTEST_MAIN(tst_QJSEngine)
#include "tst_qjsengine.moc"