diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-14 12:05:25 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-14 12:05:25 (GMT) |
commit | e0a86dc604b87921652b844a5f85889bb6291ed9 (patch) | |
tree | edc084c4e047dfc1724d76adc8bb65ae9ca0be19 /tests/auto/qscriptcontext | |
parent | 61c303e8bab04312c17ad2ee03e9ba3f29a0184b (diff) | |
download | Qt-e0a86dc604b87921652b844a5f85889bb6291ed9.zip Qt-e0a86dc604b87921652b844a5f85889bb6291ed9.tar.gz Qt-e0a86dc604b87921652b844a5f85889bb6291ed9.tar.bz2 |
make it possible for any script object to serve as activation object
This was possible in the old back-end. In JSC, activation objects
have to be instances of JSC::JSVariableObject. So the way we solve
it is by having our QScriptActivationObject be able to act as a
proxy to any other JSObject.
Diffstat (limited to 'tests/auto/qscriptcontext')
-rw-r--r-- | tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index 761b233..6401f62 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -77,6 +77,7 @@ private slots: void calledAsConstructor(); void argumentsObjectInNative(); void jsActivationObject(); + void qobjectAsActivationObject(); }; tst_QScriptContext::tst_QScriptContext() @@ -716,9 +717,7 @@ void tst_QScriptContext::getSetActivationObject() QCOMPARE(ctx->engine(), &eng); QScriptValue obj = eng.newObject(); - QTest::ignoreMessage(QtWarningMsg, "QScriptContext::setActivationObject() failed: not an activation object"); ctx->setActivationObject(obj); - QEXPECT_FAIL("", "Normal object cannot be set as activation object", Continue); QVERIFY(ctx->activationObject().equals(obj)); { @@ -913,5 +912,41 @@ void tst_QScriptContext::jsActivationObject() QCOMPARE(result2.property("arguments").property(1).toString() , QString::fromLatin1("2")); } +void tst_QScriptContext::qobjectAsActivationObject() +{ + QScriptEngine eng; + QObject object; + QScriptValue scriptObject = eng.newQObject(&object); + QScriptContext *ctx = eng.pushContext(); + ctx->setActivationObject(scriptObject); + QVERIFY(ctx->activationObject().equals(scriptObject)); + + QVERIFY(!scriptObject.property("foo").isValid()); + eng.evaluate("function foo() { return 123; }"); + { + QScriptValue val = scriptObject.property("foo"); + QVERIFY(val.isValid()); + QVERIFY(val.isFunction()); + } + QVERIFY(!eng.globalObject().property("foo").isValid()); + + QVERIFY(!scriptObject.property("bar").isValid()); + eng.evaluate("var bar = 123"); + { + QScriptValue val = scriptObject.property("bar"); + QVERIFY(val.isValid()); + QVERIFY(val.isNumber()); + QCOMPARE(val.toInt32(), 123); + } + QVERIFY(!eng.globalObject().property("bar").isValid()); + + { + QScriptValue val = eng.evaluate("delete foo"); + QVERIFY(val.isBool()); + QVERIFY(val.toBool()); + QVERIFY(!scriptObject.property("foo").isValid()); + } +} + QTEST_MAIN(tst_QScriptContext) #include "tst_qscriptcontext.moc" |