summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-08-10 20:10:51 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-10 20:10:51 (GMT)
commit62281ca6f9e74a5c8b66204d74ceec0215ecab92 (patch)
treedbd15ba8bd78edbafd555fe7b3dda80ad74ddafc
parent71caeca273d4b76d9ca9b490bf444443d6875c54 (diff)
downloadQt-62281ca6f9e74a5c8b66204d74ceec0215ecab92.zip
Qt-62281ca6f9e74a5c8b66204d74ceec0215ecab92.tar.gz
Qt-62281ca6f9e74a5c8b66204d74ceec0215ecab92.tar.bz2
Test the activationObject for js functions
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index ca062ca..a278d2c 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -76,6 +76,7 @@ private slots:
void toString();
void calledAsConstructor();
void argumentsObjectInNative();
+ void jsActivationObject();
};
tst_QScriptContext::tst_QScriptContext()
@@ -888,7 +889,31 @@ void tst_QScriptContext::argumentsObjectInNative()
QVERIFY(!eng.hasUncaughtException());
QCOMPARE(result.toString(), QString::fromLatin1("success"));
}
+}
+
+static QScriptValue get_jsActivationObject(QScriptContext *ctx, QScriptEngine *)
+{
+ return ctx->parentContext()->parentContext()->activationObject();
+}
+void tst_QScriptContext::jsActivationObject()
+{
+ QScriptEngine eng;
+ eng.globalObject().setProperty("get_jsActivationObject", eng.newFunction(get_jsActivationObject));
+ eng.evaluate("function f1() { var w = get_jsActivationObject('arg1'); return w; }");
+ eng.evaluate("function f2(x,y,z) { var v1 = 42;\n"
+ // "function foo() {};\n" //this would avoid JSC to optimize
+ "var v2 = f1(); return v2; }");
+ eng.evaluate("function f3() { var v1 = 'nothing'; return f2(1,2,3); }");
+ QScriptValue result1 = eng.evaluate("f2('hello', 'useless', 'world')");
+ QScriptValue result2 = eng.evaluate("f3()");
+ QVERIFY(result1.isObject());
+ QEXPECT_FAIL("", "JSC optimize away the activation object", Abort);
+ QCOMPARE(result1.property("v1").toInt32() , 42);
+ QCOMPARE(result1.property("arguments").property(1).toString() , QString::fromLatin1("useless"));
+ QVERIFY(result2.isObject());
+ QCOMPARE(result2.property("v1").toInt32() , 42);
+ QCOMPARE(result2.property("arguments").property(1).toString() , QString::fromLatin1("2"));
}
QTEST_MAIN(tst_QScriptContext)