summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptvalue
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-11-09 08:20:36 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-11-09 10:00:13 (GMT)
commit8aee86b8ce4700f48b8a30752cb2293860957bb7 (patch)
tree277d71ec3021aaba33108aa3dd660eebb0a1a434 /tests/auto/qscriptvalue
parent6b8a95b2521d843ec2b3f7c787c15b92e4ea686f (diff)
downloadQt-8aee86b8ce4700f48b8a30752cb2293860957bb7.zip
Qt-8aee86b8ce4700f48b8a30752cb2293860957bb7.tar.gz
Qt-8aee86b8ce4700f48b8a30752cb2293860957bb7.tar.bz2
Fix GC-related crash in QScriptValue::setData()
Yet another missing API shim. When converting the QScriptValue to JSC, a JSCell may be allocated, which can cause the GC to trigger. If an identifier (JSC::Identifier) is then garbage collected, the destructor will try to remove itself from the currentIdentifierTable(). Because the API shim was missing, the identifier table was 0. It's difficult to create a bulletproof test for this case, but the attached test is a best effort (it crashes on my machine without the fix). Task-number: QTBUG-15144 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/auto/qscriptvalue')
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp13
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index 639df36..53e2699 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -2253,6 +2253,19 @@ void tst_QScriptValue::getSetData()
QVERIFY(!object.data().isValid());
}
+void tst_QScriptValue::setData_QTBUG15144()
+{
+ QScriptEngine eng;
+ QScriptValue obj = eng.newObject();
+ for (int i = 0; i < 10000; ++i) {
+ // Create an object with property 'fooN' on it, and immediately kill
+ // the reference to the object so it and the property name become garbage.
+ eng.evaluate(QString::fromLatin1("o = {}; o.foo%0 = 10; o = null;").arg(i));
+ // Setting the data will cause a JS string to be allocated, which could
+ // trigger a GC. This should not cause a crash.
+ obj.setData("foodfight");
+ }
+}
class TestScriptClass : public QScriptClass
{
public:
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h
index 462749a..aa6bc6c 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.h
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h
@@ -216,6 +216,7 @@ private slots:
void getSetProperty();
void arrayElementGetterSetter();
void getSetData();
+ void setData_QTBUG15144();
void getSetScriptClass();
void call();
void construct();