aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-01-18 09:50:31 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-20 23:35:18 +0100
commit45a83b43ea431a27a7ea05e7e621013dfcfe409a (patch)
treefc379a3d1e7ba1297ca0cd7dd896f084447c4ca8 /tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
parentb4cd91c2409d5487cb576899f22f654a5bff93e2 (diff)
Add QJSValue::hasProperty() and hasOwnProperty() functions
These functions provide a way of querying whether a property exists, without relying on the QJSValue invalid type (which will be removed). Task-number: QTBUG-23604 Change-Id: I2efd53a1e54cc202ecc022d12730b2775384cf53 Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp')
-rw-r--r--tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
index e3e259dcbc..e8073bc69a 100644
--- a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
@@ -1792,6 +1792,57 @@ static QJSValue getSet__proto__(QScriptContext *ctx, QScriptEngine *)
}
#endif
+void tst_QJSValue::hasProperty_basic()
+{
+ QJSEngine eng;
+ QJSValue obj = eng.newObject();
+ QVERIFY(obj.hasProperty("hasOwnProperty")); // inherited from Object.prototype
+ QVERIFY(!obj.hasOwnProperty("hasOwnProperty"));
+
+ QVERIFY(!obj.hasProperty("foo"));
+ QVERIFY(!obj.hasOwnProperty("foo"));
+ obj.setProperty("foo", 123);
+ QVERIFY(obj.hasProperty("foo"));
+ QVERIFY(obj.hasOwnProperty("foo"));
+
+ QVERIFY(!obj.hasProperty("bar"));
+ QVERIFY(!obj.hasOwnProperty("bar"));
+}
+
+void tst_QJSValue::hasProperty_globalObject()
+{
+ QJSEngine eng;
+ QJSValue global = eng.globalObject();
+ QVERIFY(global.hasProperty("Math"));
+ QVERIFY(global.hasOwnProperty("Math"));
+ QVERIFY(!global.hasProperty("NoSuchStandardProperty"));
+ QVERIFY(!global.hasOwnProperty("NoSuchStandardProperty"));
+
+ QVERIFY(!global.hasProperty("foo"));
+ QVERIFY(!global.hasOwnProperty("foo"));
+ global.setProperty("foo", 123);
+ QVERIFY(global.hasProperty("foo"));
+ QVERIFY(global.hasOwnProperty("foo"));
+}
+
+void tst_QJSValue::hasProperty_changePrototype()
+{
+ QJSEngine eng;
+ QJSValue obj = eng.newObject();
+ QJSValue proto = eng.newObject();
+ obj.setPrototype(proto);
+
+ QVERIFY(!obj.hasProperty("foo"));
+ QVERIFY(!obj.hasOwnProperty("foo"));
+ proto.setProperty("foo", 123);
+ QVERIFY(obj.hasProperty("foo"));
+ QVERIFY(!obj.hasOwnProperty("foo"));
+
+ obj.setProperty("foo", 456); // override prototype property
+ QVERIFY(obj.hasProperty("foo"));
+ QVERIFY(obj.hasOwnProperty("foo"));
+}
+
void tst_QJSValue::getSetProperty_HooliganTask162051()
{
QJSEngine eng;