summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptcontext
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-29 10:58:20 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-29 10:59:12 (GMT)
commitad255eac6aaba9ac1689145bbf47376c354996aa (patch)
tree6094a1775227e290b3d0d62647e7162188b9823b /tests/auto/qscriptcontext
parent1ae869d6dfaf3f07d5cdb1fd951a711edd96eff7 (diff)
downloadQt-ad255eac6aaba9ac1689145bbf47376c354996aa.zip
Qt-ad255eac6aaba9ac1689145bbf47376c354996aa.tar.gz
Qt-ad255eac6aaba9ac1689145bbf47376c354996aa.tar.bz2
set calledAsConstructor to true when function is called as constructor
Diffstat (limited to 'tests/auto/qscriptcontext')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index 8b3d1d7..d9fb1ff 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -73,6 +73,7 @@ private slots:
void pushAndPopScope();
void getSetActivationObject();
void toString();
+ void calledAsConstructor();
void argumentsObjectInNative();
};
@@ -743,6 +744,37 @@ void tst_QScriptContext::toString()
QCOMPARE(ret.toString(), QString::fromLatin1("foo (first=1, second=2, third=3) at script.qs:2"));
}
+static QScriptValue storeCalledAsConstructor(QScriptContext *ctx, QScriptEngine *eng)
+{
+ ctx->callee().setProperty("calledAsConstructor", ctx->isCalledAsConstructor());
+ return eng->undefinedValue();
+}
+
+static QScriptValue storeCalledAsConstructorV2(QScriptContext *ctx, QScriptEngine *eng, void *)
+{
+ ctx->callee().setProperty("calledAsConstructor", ctx->isCalledAsConstructor());
+ return eng->undefinedValue();
+}
+
+void tst_QScriptContext::calledAsConstructor()
+{
+ QScriptEngine eng;
+ {
+ QScriptValue fun = eng.newFunction(storeCalledAsConstructor);
+ fun.call();
+ QVERIFY(!fun.property("calledAsConstructor").toBool());
+ fun.construct();
+ QVERIFY(fun.property("calledAsConstructor").toBool());
+ }
+ {
+ QScriptValue fun = eng.newFunction(storeCalledAsConstructorV2, (void*)0);
+ fun.call();
+ QVERIFY(!fun.property("calledAsConstructor").toBool());
+ fun.construct();
+ QVERIFY(fun.property("calledAsConstructor").toBool());
+ }
+}
+
static QScriptValue argumentsObjectInNative_test1(QScriptContext *ctx, QScriptEngine *)
{
#define VERIFY(statement) \