summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp60
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.h5
2 files changed, 63 insertions, 2 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index 5a50e49..ec33e81 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -1970,7 +1970,7 @@ void tst_QScriptValue::getSetProperty_gettersAndSetters()
QCOMPARE(object.property("foo").isUndefined(), true);
}
-void tst_QScriptValue::getSetProperty_gettersAndSettersThrowError()
+void tst_QScriptValue::getSetProperty_gettersAndSettersThrowErrorNative()
{
// getter/setter that throws an error
QScriptEngine eng;
@@ -1984,6 +1984,32 @@ void tst_QScriptValue::getSetProperty_gettersAndSettersThrowError()
QVERIFY(ret.isError());
QVERIFY(eng.hasUncaughtException());
QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
+ QCOMPARE(ret.toString(), QLatin1String("Error: get foo"));
+ eng.evaluate("Object"); // clear exception state...
+ QVERIFY(!eng.hasUncaughtException());
+ object.setProperty("foo", str);
+ QVERIFY(eng.hasUncaughtException());
+ QCOMPARE(eng.uncaughtException().toString(), QLatin1String("Error: set foo"));
+}
+
+void tst_QScriptValue::getSetProperty_gettersAndSettersThrowErrorJS()
+{
+ // getter/setter that throws an error (from js function)
+ QScriptEngine eng;
+ QScriptValue str = QScriptValue(&eng, "bar");
+
+ eng.evaluate("o = new Object; "
+ "o.__defineGetter__('foo', function() { throw new Error('get foo') }); "
+ "o.__defineSetter__('foo', function() { throw new Error('set foo') }); ");
+ QScriptValue object = eng.evaluate("o");
+ QVERIFY(!eng.hasUncaughtException());
+ QScriptValue ret = object.property("foo");
+ QEXPECT_FAIL("", "Exception thrown from js function are not returned by the JSC port", Continue);
+ QVERIFY(ret.isError());
+ QVERIFY(eng.hasUncaughtException());
+ QEXPECT_FAIL("", "Exception thrown from js function are not returned by the JSC port", Continue);
+ QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
+ QCOMPARE(eng.uncaughtException().toString(), QLatin1String("Error: get foo"));
eng.evaluate("Object"); // clear exception state...
QVERIFY(!eng.hasUncaughtException());
object.setProperty("foo", str);
@@ -2051,6 +2077,12 @@ void tst_QScriptValue::getSetProperty_gettersAndSettersChange()
QVERIFY(!object.property("x").isValid());
object.setProperty("foo", num);
QVERIFY(object.property("x").equals(num));
+
+ eng.globalObject().setProperty("object", object);
+ QScriptValue res = eng.evaluate("object.x = 89; var a = object.foo; object.foo = 65; a");
+ QCOMPARE(res.toInt32(), 89);
+ QCOMPARE(object.property("x").toInt32(), 65);
+ QCOMPARE(object.property("foo").toInt32(), 65);
}
void tst_QScriptValue::getSetProperty_array()
@@ -3931,4 +3963,30 @@ void tst_QScriptValue::nestedObjectToVariant()
QCOMPARE(o.toVariant(), expected);
}
+void tst_QScriptValue::propertyFlags_data()
+{
+ QTest::addColumn<QString>("program");
+ QTest::addColumn<uint>("expected");
+
+ QTest::newRow("nothing") << "" << 0u;
+ QTest::newRow("getter") << "o.__defineGetter__('prop', function() { return 'blah' } );\n" << uint(QScriptValue::PropertyGetter);
+ QTest::newRow("setter") << "o.__defineSetter__('prop', function(a) { this.setted_prop2 = a; } );\n" << uint(QScriptValue::PropertySetter);
+ QTest::newRow("getterSetter") << "o.__defineGetter__('prop', function() { return 'ploup' } );\n"
+ "o.__defineSetter__('prop', function(a) { this.setted_prop3 = a; } );\n" << uint(QScriptValue::PropertySetter|QScriptValue::PropertyGetter);
+ QTest::newRow("nothing2") << "o.prop = 'nothing'" << 0u;
+}
+
+void tst_QScriptValue::propertyFlags()
+{
+ QFETCH(QString, program);
+ QFETCH(uint, expected);
+ QScriptEngine eng;
+ eng.evaluate("o = new Object;");
+ eng.evaluate(program);
+ QScriptValue o = eng.evaluate("o");
+
+ QCOMPARE(uint(o.propertyFlags("prop")), expected);
+}
+
+
QTEST_MAIN(tst_QScriptValue)
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h
index 46f5526..6f55bc3 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.h
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h
@@ -127,7 +127,8 @@ private slots:
void getSetProperty_resolveMode();
void getSetProperty_twoEngines();
void getSetProperty_gettersAndSetters();
- void getSetProperty_gettersAndSettersThrowError();
+ void getSetProperty_gettersAndSettersThrowErrorNative();
+ void getSetProperty_gettersAndSettersThrowErrorJS();
void getSetProperty_gettersAndSettersOnNative();
void getSetProperty_gettersAndSettersOnGlobalObject();
void getSetProperty_gettersAndSettersChange();
@@ -178,6 +179,8 @@ private slots:
void objectId();
void nestedObjectToVariant_data();
void nestedObjectToVariant();
+ void propertyFlags_data();
+ void propertyFlags();
private: