summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptcontext
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-31 08:17:20 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-31 08:18:27 (GMT)
commit65f6a08ba7d26405a9de683ea0806b400ba8b26d (patch)
tree6e9303bc1bcea90417a5c84728b10e70f479c9fc /tests/auto/qscriptcontext
parent4066cc8a2f2b824d1047913d863b4d3261dd2479 (diff)
downloadQt-65f6a08ba7d26405a9de683ea0806b400ba8b26d.zip
Qt-65f6a08ba7d26405a9de683ea0806b400ba8b26d.tar.gz
Qt-65f6a08ba7d26405a9de683ea0806b400ba8b26d.tar.bz2
test that activation and this-object can be inherited from parent context
Diffstat (limited to 'tests/auto/qscriptcontext')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index d96006d..3c9ea4c9 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -72,6 +72,7 @@ private slots:
void scopeChain();
void pushAndPopScope();
void getSetActivationObject();
+ void inheritActivationAndThisObject();
void toString();
};
@@ -689,6 +690,35 @@ void tst_QScriptContext::getSetActivationObject()
}
}
+static QScriptValue myEval(QScriptContext *ctx, QScriptEngine *eng)
+{
+ QString code = ctx->argument(0).toString();
+ ctx->setActivationObject(ctx->parentContext()->activationObject());
+ ctx->setThisObject(ctx->parentContext()->thisObject());
+ return eng->evaluate(code);
+}
+
+void tst_QScriptContext::inheritActivationAndThisObject()
+{
+ QScriptEngine eng;
+ eng.globalObject().setProperty("myEval", eng.newFunction(myEval));
+ {
+ QScriptValue ret = eng.evaluate("var a = 123; myEval('a')");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toInt32(), 123);
+ }
+ {
+ QScriptValue ret = eng.evaluate("(function() { return myEval('this'); }).call(Number)");
+ QVERIFY(ret.isFunction());
+ QVERIFY(ret.equals(eng.globalObject().property("Number")));
+ }
+ {
+ QScriptValue ret = eng.evaluate("(function(a) { return myEval('a'); })(123)");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toInt32(), 123);
+ }
+}
+
static QScriptValue parentContextToString(QScriptContext *ctx, QScriptEngine *)
{
return ctx->parentContext()->toString();