diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-18 12:26:14 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-18 12:26:14 (GMT) |
commit | 91cb5464a35d2f461644677973ffdcc91985e7fd (patch) | |
tree | 91707880b76513c7a43a4de22b97ea5f2c98d226 /tests | |
parent | a2af6621a00cf0be03077132a271b2620a725bee (diff) | |
download | Qt-91cb5464a35d2f461644677973ffdcc91985e7fd.zip Qt-91cb5464a35d2f461644677973ffdcc91985e7fd.tar.gz Qt-91cb5464a35d2f461644677973ffdcc91985e7fd.tar.bz2 |
implement getter/setter proxying for Global Object and activation object
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index cf6ebd8..ef86f2a 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -79,6 +79,7 @@ private slots: void newActivationObject(); void getSetGlobalObject(); void globalObjectProperties(); + void globalObjectGetterSetterProperty(); void checkSyntax_data(); void checkSyntax(); void canEvaluate_data(); @@ -955,6 +956,13 @@ void tst_QScriptEngine::getSetGlobalObject() } } +static QScriptValue getSetFoo(QScriptContext *ctx, QScriptEngine *) +{ + if (ctx->argumentCount() > 0) + ctx->thisObject().setProperty("foo", ctx->argument(0)); + return ctx->thisObject().property("foo"); +} + void tst_QScriptEngine::globalObjectProperties() { QScriptEngine eng; @@ -1094,6 +1102,23 @@ void tst_QScriptEngine::globalObjectProperties() QVERIFY(remainingNames.isEmpty()); } +void tst_QScriptEngine::globalObjectGetterSetterProperty() +{ + QScriptEngine engine; + QScriptValue global = engine.globalObject(); + global.setProperty("bar", engine.newFunction(getSetFoo), + QScriptValue::PropertySetter | QScriptValue::PropertyGetter); + global.setProperty("foo", 123); + QVERIFY(global.property("bar").equals(global.property("foo"))); + QVERIFY(engine.evaluate("bar").equals(global.property("foo"))); + global.setProperty("bar", 456); + QVERIFY(global.property("bar").equals(global.property("foo"))); + + engine.evaluate("__defineGetter__('baz', function() { return 789; })"); + QVERIFY(engine.evaluate("baz").equals(789)); + QVERIFY(global.property("baz").equals(789)); +} + void tst_QScriptEngine::checkSyntax_data() { QTest::addColumn<QString>("code"); |