aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-01-18 10:00:02 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-20 23:35:18 +0100
commit23805ae47898a1ae4b5c8d8bb30b8b69d2fc435a (patch)
tree487d8a346511974e210393a416dbeb95880387f7 /tests/auto
parent45a83b43ea431a27a7ea05e7e621013dfcfe409a (diff)
Add QJSValue::deleteProperty() function
This makes it possible to delete a property without relying on passing a QJSValue of invalid type to setProperty() (the invalid type is going to be removed). Task-number: QTBUG-23604 Change-Id: I653b3349050ad1aac1cf6ccc8547c753abbb9f1d Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp44
-rw-r--r--tests/auto/declarative/qjsvalue/tst_qjsvalue.h4
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
index e8073bc69a..caff7fc065 100644
--- a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
@@ -1843,6 +1843,50 @@ void tst_QJSValue::hasProperty_changePrototype()
QVERIFY(obj.hasOwnProperty("foo"));
}
+void tst_QJSValue::deleteProperty_basic()
+{
+ QJSEngine eng;
+ QJSValue obj = eng.newObject();
+ // deleteProperty() behavior matches JS delete operator
+ QVERIFY(obj.deleteProperty("foo"));
+
+ obj.setProperty("foo", 123);
+ QVERIFY(obj.deleteProperty("foo"));
+ QVERIFY(!obj.hasOwnProperty("foo"));
+}
+
+void tst_QJSValue::deleteProperty_globalObject()
+{
+ QJSEngine eng;
+ QJSValue global = eng.globalObject();
+ // deleteProperty() behavior matches JS delete operator
+ QVERIFY(global.deleteProperty("foo"));
+
+ global.setProperty("foo", 123);
+ QVERIFY(global.deleteProperty("foo"));
+ QVERIFY(!global.hasProperty("foo"));
+
+ QVERIFY(global.deleteProperty("Math"));
+ QVERIFY(!global.hasProperty("Math"));
+
+ QVERIFY(!global.deleteProperty("NaN")); // read-only
+ QVERIFY(global.hasProperty("NaN"));
+}
+
+void tst_QJSValue::deleteProperty_inPrototype()
+{
+ QJSEngine eng;
+ QJSValue obj = eng.newObject();
+ QJSValue proto = eng.newObject();
+ obj.setPrototype(proto);
+
+ proto.setProperty("foo", 123);
+ QVERIFY(obj.hasProperty("foo"));
+ // deleteProperty() behavior matches JS delete operator
+ QVERIFY(obj.deleteProperty("foo"));
+ QVERIFY(obj.hasProperty("foo"));
+}
+
void tst_QJSValue::getSetProperty_HooliganTask162051()
{
QJSEngine eng;
diff --git a/tests/auto/declarative/qjsvalue/tst_qjsvalue.h b/tests/auto/declarative/qjsvalue/tst_qjsvalue.h
index 7f7c04abe8..7696f61a06 100644
--- a/tests/auto/declarative/qjsvalue/tst_qjsvalue.h
+++ b/tests/auto/declarative/qjsvalue/tst_qjsvalue.h
@@ -117,6 +117,10 @@ private slots:
void hasProperty_globalObject();
void hasProperty_changePrototype();
+ void deleteProperty_basic();
+ void deleteProperty_globalObject();
+ void deleteProperty_inPrototype();
+
void getSetPrototype_cyclicPrototype();
void getSetPrototype_evalCyclicPrototype();
void getSetPrototype_eval();