aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/v8/qv8sequencewrapper_p_p.h25
-rw-r--r--tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml14
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp4
3 files changed, 14 insertions, 29 deletions
diff --git a/src/qml/qml/v8/qv8sequencewrapper_p_p.h b/src/qml/qml/v8/qv8sequencewrapper_p_p.h
index 9d519809fa..eebc40eeed 100644
--- a/src/qml/qml/v8/qv8sequencewrapper_p_p.h
+++ b/src/qml/qml/v8/qv8sequencewrapper_p_p.h
@@ -265,6 +265,7 @@ static QString convertUrlToString(QV8Engine *, const QUrl &v)
static QVariant toVariant(QV8Engine *e, v8::Handle<v8::Array> array, uint32_t length, bool *succeeded) \
{ \
SequenceType list; \
+ list.reserve(length); \
for (uint32_t ii = 0; ii < length; ++ii) { \
list.append(ConversionFromV8fn(e, array->Get(ii))); \
} \
@@ -334,14 +335,15 @@ static QString convertUrlToString(QV8Engine *, const QUrl &v)
/* according to ECMA262r3 we need to insert */ \
/* undefined values increasing length to newLength. */ \
/* We cannot, so we insert default-values instead. */ \
+ QT_TRY { \
+ c.reserve(newCount); \
+ } QT_CATCH (std::bad_alloc &exception) { \
+ generateWarning(engine, QString(QLatin1String(exception.what()) \
+ + QLatin1String(" during length set"))); \
+ return; /* failed; don't write back any result. */ \
+ } \
while (newCount > count++) { \
- QT_TRY { \
- c.append(DefaultValue); \
- } QT_CATCH (std::bad_alloc &exception) { \
- generateWarning(engine, QString(QLatin1String(exception.what()) \
- + QLatin1String(" during length set"))); \
- return; /* failed; don't write back any result. */ \
- } \
+ c.append(DefaultValue); \
} \
} else { \
/* according to ECMA262r3 we need to remove */ \
@@ -382,15 +384,16 @@ static QString convertUrlToString(QV8Engine *, const QUrl &v)
/* according to ECMA262r3 we need to insert */ \
/* the value at the given index, increasing length to index+1. */ \
QT_TRY { \
- while (signedIdx > count++) { \
- c.append(DefaultValue); \
- } \
- c.append(elementValue); \
+ c.reserve(signedIdx + 1); \
} QT_CATCH (std::bad_alloc &exception) { \
generateWarning(engine, QString(QLatin1String(exception.what()) \
+ QLatin1String(" during indexed set"))); \
return v8::Undefined(); /* failed; don't write back any result. */ \
} \
+ while (signedIdx > count++) { \
+ c.append(DefaultValue); \
+ } \
+ c.append(elementValue); \
} \
/* write back. already checked that object is non-null, so skip that check here. */ \
if (objectType == QV8SequenceResource::Reference) \
diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml
index 23f1e90417..962e8dd474 100644
--- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml
+++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml
@@ -71,19 +71,5 @@ Item {
success = false;
if (!verifyExpected(msco.intListProperty, 4))
success = false;
-
- // NOTE: while these two operations are technically
- // fine, we expect std::bad_alloc exceptions here
- // which we handle in the sequence wrapper.
- msco.intListProperty.length = maxIndex;
- if (msco.intListProperty.length != expectedLength)
- success = false;
- if (!verifyExpected(msco.intListProperty, 4))
- success = false;
- msco.intListProperty[maxIndex] = 15;
- if (msco.intListProperty.length != expectedLength)
- success = false;
- if (!verifyExpected(msco.intListProperty, 4))
- success = false;
}
}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 0dc0e5aca8..5770dc4e03 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -4649,13 +4649,9 @@ void tst_qqmlecmascript::sequenceConversionIndexes()
QString w1 = qmlFile.toString() + QLatin1String(":34: Index out of range during length set");
QString w2 = qmlFile.toString() + QLatin1String(":41: Index out of range during indexed set");
QString w3 = qmlFile.toString() + QLatin1String(":48: Index out of range during indexed get");
- QString w4 = qmlFile.toString() + QLatin1String(":78: std::bad_alloc during length set");
- QString w5 = qmlFile.toString() + QLatin1String(":83: std::bad_alloc during indexed set");
QTest::ignoreMessage(QtWarningMsg, qPrintable(w1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(w2));
QTest::ignoreMessage(QtWarningMsg, qPrintable(w3));
- QTest::ignoreMessage(QtWarningMsg, qPrintable(w4));
- QTest::ignoreMessage(QtWarningMsg, qPrintable(w5));
QMetaObject::invokeMethod(object, "indexedAccess");
QVERIFY(object->property("success").toBool());
delete object;