diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-09 11:00:02 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-09 11:00:02 (GMT) |
commit | d9b959c85b1b285e63e8aa2dcc01ac0426614ddf (patch) | |
tree | 5ed7dc3bdc22ec6d7475b262390346c8c54869ce /tests/auto/qscriptvalue | |
parent | c0612a4557dc5e79bd4c1f941971b5a9ef1e2322 (diff) | |
download | Qt-d9b959c85b1b285e63e8aa2dcc01ac0426614ddf.zip Qt-d9b959c85b1b285e63e8aa2dcc01ac0426614ddf.tar.gz Qt-d9b959c85b1b285e63e8aa2dcc01ac0426614ddf.tar.bz2 |
make native object constructors work
With commit 6985212c8909c89183b232ca28b96a2c8a2f1385,
context->thisObject() now returns the right thing.
Diffstat (limited to 'tests/auto/qscriptvalue')
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 9ad47cf..06f1ec6 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -2525,18 +2525,56 @@ void tst_QScriptValue::call() } } +static QScriptValue ctorReturningUndefined(QScriptContext *ctx, QScriptEngine *) +{ + ctx->thisObject().setProperty("foo", 123); + return QScriptValue(QScriptValue::UndefinedValue); +} + +static QScriptValue ctorReturningNewObject(QScriptContext *, QScriptEngine *eng) +{ + QScriptValue result = eng->newObject(); + result.setProperty("bar", 456); + return result; +} + void tst_QScriptValue::construct() { QScriptEngine eng; { - QScriptValue fun = eng.evaluate("function () { }"); + QScriptValue fun = eng.evaluate("function () { this.foo = 123; }"); QEXPECT_FAIL("", "JSC parser doesn't understand function expressions", Continue); QVERIFY(fun.isFunction()); - fun = eng.evaluate("(function () { })"); + fun = eng.evaluate("(function () { this.foo = 123; })"); QScriptValue ret = fun.construct(); QVERIFY(ret.isObject()); QVERIFY(ret.instanceOf(fun)); + QCOMPARE(ret.property("foo").toInt32(), 123); + } + // returning a different object overrides the default-constructed one + { + QScriptValue fun = eng.evaluate("(function () { return { bar: 456 }; })"); + QVERIFY(fun.isFunction()); + QScriptValue ret = fun.construct(); + QVERIFY(ret.isObject()); + QVERIFY(!ret.instanceOf(fun)); + QCOMPARE(ret.property("bar").toInt32(), 456); + } + + { + QScriptValue fun = eng.newFunction(ctorReturningUndefined); + QScriptValue ret = fun.construct(); + QVERIFY(ret.isObject()); + QVERIFY(ret.instanceOf(fun)); + QCOMPARE(ret.property("foo").toInt32(), 123); + } + { + QScriptValue fun = eng.newFunction(ctorReturningNewObject); + QScriptValue ret = fun.construct(); + QVERIFY(ret.isObject()); + QVERIFY(!ret.instanceOf(fun)); + QCOMPARE(ret.property("bar").toInt32(), 456); } QScriptValue Number = eng.evaluate("Number"); |