[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.22-985-g3c00f00
eric at webkit.org
eric at webkit.org
Wed Mar 17 18:10:20 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 49c5c158347041e02245710a6cfe0a073569afc5
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Mar 2 21:20:20 2010 +0000
2010-03-02 Jedrzej Nowacki <jedrzej.nowacki at nokia.com>
Reviewed by Simon Hausmann.
Introduce a new class; QScriptString.
The QScriptString class should act as a handle to "interned"
strings in a QScriptEngine.
[Qt] QtScript should provide QScriptString
https://bugs.webkit.org/show_bug.cgi?id=34843
* qt/api/QtScript.pro:
* qt/api/qscriptengine.cpp:
(QScriptEngine::toStringHandle):
* qt/api/qscriptengine.h:
* qt/api/qscriptengine_p.h:
(QScriptEnginePrivate::toStringHandle):
* qt/api/qscriptstring.cpp: Added.
(QScriptString::QScriptString):
(QScriptString::~QScriptString):
(QScriptString::operator=):
(QScriptString::isValid):
(QScriptString::operator==):
(QScriptString::operator!=):
(QScriptString::toArrayIndex):
(QScriptString::toString):
(QScriptString::operator QString):
(qHash):
* qt/api/qscriptstring.h: Added.
* qt/api/qscriptstring_p.h: Added.
(QScriptStringPrivate::QScriptStringPrivate):
(QScriptStringPrivate::~QScriptStringPrivate):
(QScriptStringPrivate::get):
(QScriptStringPrivate::isValid):
(QScriptStringPrivate::operator==):
(QScriptStringPrivate::operator!=):
(QScriptStringPrivate::toArrayIndex):
(QScriptStringPrivate::toString):
(QScriptStringPrivate::id):
* qt/tests/qscriptstring/qscriptstring.pro: Added.
* qt/tests/qscriptstring/tst_qscriptstring.cpp: Added.
(tst_QScriptString::tst_QScriptString):
(tst_QScriptString::~tst_QScriptString):
(tst_QScriptString::test):
(tst_QScriptString::hash):
(tst_QScriptString::toArrayIndex_data):
(tst_QScriptString::toArrayIndex):
* qt/tests/tests.pro:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55426 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index ff0e973..8a3e133 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,53 @@
+2010-03-02 Jedrzej Nowacki <jedrzej.nowacki at nokia.com>
+
+ Reviewed by Simon Hausmann.
+
+ Introduce a new class; QScriptString.
+
+ The QScriptString class should act as a handle to "interned"
+ strings in a QScriptEngine.
+
+ [Qt] QtScript should provide QScriptString
+ https://bugs.webkit.org/show_bug.cgi?id=34843
+
+ * qt/api/QtScript.pro:
+ * qt/api/qscriptengine.cpp:
+ (QScriptEngine::toStringHandle):
+ * qt/api/qscriptengine.h:
+ * qt/api/qscriptengine_p.h:
+ (QScriptEnginePrivate::toStringHandle):
+ * qt/api/qscriptstring.cpp: Added.
+ (QScriptString::QScriptString):
+ (QScriptString::~QScriptString):
+ (QScriptString::operator=):
+ (QScriptString::isValid):
+ (QScriptString::operator==):
+ (QScriptString::operator!=):
+ (QScriptString::toArrayIndex):
+ (QScriptString::toString):
+ (QScriptString::operator QString):
+ (qHash):
+ * qt/api/qscriptstring.h: Added.
+ * qt/api/qscriptstring_p.h: Added.
+ (QScriptStringPrivate::QScriptStringPrivate):
+ (QScriptStringPrivate::~QScriptStringPrivate):
+ (QScriptStringPrivate::get):
+ (QScriptStringPrivate::isValid):
+ (QScriptStringPrivate::operator==):
+ (QScriptStringPrivate::operator!=):
+ (QScriptStringPrivate::toArrayIndex):
+ (QScriptStringPrivate::toString):
+ (QScriptStringPrivate::id):
+ * qt/tests/qscriptstring/qscriptstring.pro: Added.
+ * qt/tests/qscriptstring/tst_qscriptstring.cpp: Added.
+ (tst_QScriptString::tst_QScriptString):
+ (tst_QScriptString::~tst_QScriptString):
+ (tst_QScriptString::test):
+ (tst_QScriptString::hash):
+ (tst_QScriptString::toArrayIndex_data):
+ (tst_QScriptString::toArrayIndex):
+ * qt/tests/tests.pro:
+
2010-03-02 Oliver Hunt <oliver at apple.com>
Reviewed by NOBODY (Build fix).
diff --git a/JavaScriptCore/qt/api/QtScript.pro b/JavaScriptCore/qt/api/QtScript.pro
index c87eaf4..246a0bc 100644
--- a/JavaScriptCore/qt/api/QtScript.pro
+++ b/JavaScriptCore/qt/api/QtScript.pro
@@ -21,6 +21,7 @@ INCLUDEPATH += $$PWD/../../API
SOURCES += $$PWD/qscriptengine.cpp \
$$PWD/qscriptengine_p.cpp \
$$PWD/qscriptvalue.cpp \
+ $$PWD/qscriptstring.cpp \
HEADERS += $$PWD/qtscriptglobal.h \
$$PWD/qscriptengine.h \
@@ -28,6 +29,8 @@ HEADERS += $$PWD/qtscriptglobal.h \
$$PWD/qscriptvalue.h \
$$PWD/qscriptvalue_p.h \
$$PWD/qscriptconverter_p.h \
+ $$PWD/qscriptstring.h \
+ $$PWD/qscriptstring_p.h \
!static: DEFINES += QT_MAKEDLL
diff --git a/JavaScriptCore/qt/api/qscriptconverter_p.h b/JavaScriptCore/qt/api/qscriptconverter_p.h
index c3ca41f..821dc8d 100644
--- a/JavaScriptCore/qt/api/qscriptconverter_p.h
+++ b/JavaScriptCore/qt/api/qscriptconverter_p.h
@@ -21,6 +21,7 @@
#define qscriptconverter_p_h
#include <JavaScriptCore/JavaScript.h>
+#include <QtCore/qnumeric.h>
#include <QtCore/qstring.h>
/*
@@ -33,6 +34,19 @@
*/
class QScriptConverter {
public:
+ static quint32 toArrayIndex(const JSStringRef jsstring)
+ {
+ // FIXME this function should be exported by JSC C API.
+ QString qstring = toString(jsstring);
+
+ bool ok;
+ quint32 idx = qstring.toUInt(&ok);
+ if (!ok || toString(idx) != qstring)
+ idx = 0xffffffff;
+
+ return idx;
+ }
+
static QString toString(const JSStringRef str)
{
return QString(reinterpret_cast<const QChar*>(JSStringGetCharactersPtr(str)), JSStringGetLength(str));
diff --git a/JavaScriptCore/qt/api/qscriptengine.cpp b/JavaScriptCore/qt/api/qscriptengine.cpp
index fbeb902..41634f4 100644
--- a/JavaScriptCore/qt/api/qscriptengine.cpp
+++ b/JavaScriptCore/qt/api/qscriptengine.cpp
@@ -88,6 +88,19 @@ void QScriptEngine::collectGarbage()
}
/*!
+ Returns a handle that represents the given string, \a str.
+
+ QScriptString can be used to quickly look up properties, and
+ compare property names, of script objects.
+
+ \sa QScriptValue::property()
+*/
+QScriptString QScriptEngine::toStringHandle(const QString& str)
+{
+ return QScriptStringPrivate::get(d_ptr->toStringHandle(str));
+}
+
+/*!
Returns a QScriptValue of the primitive type Null.
\sa undefinedValue()
diff --git a/JavaScriptCore/qt/api/qscriptengine.h b/JavaScriptCore/qt/api/qscriptengine.h
index b8bd5e6..ba9a9bc 100644
--- a/JavaScriptCore/qt/api/qscriptengine.h
+++ b/JavaScriptCore/qt/api/qscriptengine.h
@@ -20,6 +20,7 @@
#ifndef qscriptengine_h
#define qscriptengine_h
+#include "qscriptstring.h"
#include <QtCore/qobject.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
@@ -38,6 +39,8 @@ public:
QScriptValue evaluate(const QString& program, const QString& fileName = QString(), int lineNumber = 1);
void collectGarbage();
+ QScriptString toStringHandle(const QString& str);
+
QScriptValue nullValue();
QScriptValue undefinedValue();
private:
diff --git a/JavaScriptCore/qt/api/qscriptengine_p.h b/JavaScriptCore/qt/api/qscriptengine_p.h
index 8e27c42..c583dac 100644
--- a/JavaScriptCore/qt/api/qscriptengine_p.h
+++ b/JavaScriptCore/qt/api/qscriptengine_p.h
@@ -22,6 +22,7 @@
#include "qscriptconverter_p.h"
#include "qscriptengine.h"
+#include "qscriptstring_p.h"
#include "qscriptvalue.h"
#include <JavaScriptCore/JavaScript.h>
#include <QtCore/qshareddata.h>
@@ -47,6 +48,8 @@ public:
inline JSValueRef makeJSValue(bool number) const;
inline JSValueRef makeJSValue(QScriptValue::SpecialValue value) const;
+ inline QScriptStringPrivate* toStringHandle(const QString& str) const;
+
inline JSGlobalContextRef context() const;
private:
QScriptEngine* q_ptr;
@@ -90,6 +93,11 @@ JSValueRef QScriptEnginePrivate::makeJSValue(QScriptValue::SpecialValue value) c
return JSValueMakeUndefined(m_context);
}
+QScriptStringPrivate* QScriptEnginePrivate::toStringHandle(const QString& str) const
+{
+ return new QScriptStringPrivate(str);
+}
+
JSGlobalContextRef QScriptEnginePrivate::context() const
{
return m_context;
diff --git a/JavaScriptCore/qt/api/qscriptstring.cpp b/JavaScriptCore/qt/api/qscriptstring.cpp
new file mode 100644
index 0000000..83c03c5
--- /dev/null
+++ b/JavaScriptCore/qt/api/qscriptstring.cpp
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include "qscriptstring.h"
+
+#include "qscriptstring_p.h"
+#include <QtCore/qhash.h>
+
+/*!
+ Constructs an invalid QScriptString.
+*/
+QScriptString::QScriptString()
+ : d_ptr(new QScriptStringPrivate())
+{
+}
+/*!
+ Constructs an QScriptString from internal representation
+ \internal
+*/
+QScriptString::QScriptString(QScriptStringPrivate* d)
+ : d_ptr(d)
+{
+}
+
+/*!
+ Constructs a new QScriptString that is a copy of \a other.
+*/
+QScriptString::QScriptString(const QScriptString& other)
+{
+ d_ptr = other.d_ptr;
+}
+
+/*!
+ Destroys this QScriptString.
+*/
+QScriptString::~QScriptString()
+{
+}
+
+/*!
+ Assigns the \a other value to this QScriptString.
+*/
+QScriptString& QScriptString::operator=(const QScriptString& other)
+{
+ d_ptr = other.d_ptr;
+ return *this;
+}
+
+/*!
+ Returns true if this QScriptString is valid; otherwise
+ returns false.
+*/
+bool QScriptString::isValid() const
+{
+ return d_ptr->isValid();
+}
+
+/*!
+ Returns true if this QScriptString is equal to \a other;
+ otherwise returns false.
+*/
+bool QScriptString::operator==(const QScriptString& other) const
+{
+ return d_ptr == other.d_ptr || *d_ptr == *(other.d_ptr);
+}
+
+/*!
+ Returns true if this QScriptString is not equal to \a other;
+ otherwise returns false.
+*/
+bool QScriptString::operator!=(const QScriptString& other) const
+{
+ return d_ptr != other.d_ptr || *d_ptr != *(other.d_ptr);
+}
+
+/*!
+ Attempts to convert this QScriptString to a QtScript array index,
+ and returns the result.
+
+ If a conversion error occurs, *\a{ok} is set to false; otherwise
+ *\a{ok} is set to true.
+*/
+quint32 QScriptString::toArrayIndex(bool* ok) const
+{
+ return d_ptr->toArrayIndex(ok);
+}
+
+/*!
+ Returns the string that this QScriptString represents, or a
+ null string if this QScriptString is not valid.
+
+ \sa isValid()
+*/
+QString QScriptString::toString() const
+{
+ return d_ptr->toString();
+}
+
+/*!
+ Returns the string that this QScriptString represents, or a
+ null string if this QScriptString is not valid.
+
+ \sa toString()
+*/
+QScriptString::operator QString() const
+{
+ return d_ptr->toString();
+}
+
+uint qHash(const QScriptString& key)
+{
+ return qHash(QScriptStringPrivate::get(key)->id());
+}
diff --git a/JavaScriptCore/qt/api/qscriptstring.h b/JavaScriptCore/qt/api/qscriptstring.h
new file mode 100644
index 0000000..16593bc
--- /dev/null
+++ b/JavaScriptCore/qt/api/qscriptstring.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef qscriptstring_h
+#define qscriptstring_h
+
+#include "qtscriptglobal.h"
+#include <QtCore/qshareddata.h>
+#include <QtCore/qstring.h>
+
+class QScriptStringPrivate;
+typedef QExplicitlySharedDataPointer<QScriptStringPrivate> QScriptStringPtr;
+
+class Q_JAVASCRIPT_EXPORT QScriptString {
+public:
+ QScriptString();
+ QScriptString(const QScriptString& other);
+ ~QScriptString();
+
+ QScriptString& operator=(const QScriptString& other);
+
+ bool isValid() const;
+
+ bool operator==(const QScriptString& other) const;
+ bool operator!=(const QScriptString& other) const;
+
+ quint32 toArrayIndex(bool* ok = 0) const;
+
+ QString toString() const;
+ operator QString() const;
+
+private:
+ QScriptString(QScriptStringPrivate* d);
+
+ QScriptStringPtr d_ptr;
+
+ friend class QScriptStringPrivate;
+};
+
+uint qHash(const QScriptString& key);
+
+#endif // qscriptstring_h
diff --git a/JavaScriptCore/qt/api/qscriptstring_p.h b/JavaScriptCore/qt/api/qscriptstring_p.h
new file mode 100644
index 0000000..f4fd117
--- /dev/null
+++ b/JavaScriptCore/qt/api/qscriptstring_p.h
@@ -0,0 +1,112 @@
+/*
+ Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef qscriptstring_p_h
+#define qscriptstring_p_h
+
+#include "qscriptconverter_p.h"
+#include "qscriptstring.h"
+#include <JavaScriptCore/JavaScript.h>
+#include <QtCore/qnumeric.h>
+#include <QtCore/qshareddata.h>
+
+class QScriptStringPrivate : public QSharedData {
+public:
+ inline QScriptStringPrivate();
+ inline QScriptStringPrivate(const QString& qtstring);
+ inline ~QScriptStringPrivate();
+
+ static inline QScriptString get(QScriptStringPrivate* d);
+ static inline QScriptStringPtr get(const QScriptString& p);
+
+ inline bool isValid() const;
+
+ inline bool operator==(const QScriptStringPrivate& other) const;
+ inline bool operator!=(const QScriptStringPrivate& other) const;
+
+ inline quint32 toArrayIndex(bool* ok = 0) const;
+
+ inline QString toString() const;
+
+ inline quint64 id() const;
+
+private:
+ JSStringRef m_string;
+};
+
+
+QScriptStringPrivate::QScriptStringPrivate()
+ : m_string(0)
+{}
+
+QScriptStringPrivate::QScriptStringPrivate(const QString& qtstring)
+ : m_string(JSStringRetain(QScriptConverter::toString(qtstring)))
+{}
+
+QScriptStringPrivate::~QScriptStringPrivate()
+{
+ if (isValid())
+ JSStringRelease(m_string);
+}
+
+QScriptString QScriptStringPrivate::get(QScriptStringPrivate* d)
+{
+ Q_ASSERT(d);
+ return QScriptString(d);
+}
+
+QScriptStringPtr QScriptStringPrivate::get(const QScriptString& p)
+{
+ return p.d_ptr;
+}
+
+bool QScriptStringPrivate::isValid() const
+{
+ return m_string;
+}
+
+bool QScriptStringPrivate::operator==(const QScriptStringPrivate& other) const
+{
+ return isValid() && other.isValid() && JSStringIsEqual(m_string, other.m_string);
+}
+
+bool QScriptStringPrivate::operator!=(const QScriptStringPrivate& other) const
+{
+ return isValid() && other.isValid() && !JSStringIsEqual(m_string, other.m_string);
+}
+
+quint32 QScriptStringPrivate::toArrayIndex(bool* ok) const
+{
+ quint32 idx = QScriptConverter::toArrayIndex(m_string);
+ if (ok)
+ *ok = (idx != 0xffffffff);
+ return idx;
+}
+
+QString QScriptStringPrivate::toString() const
+{
+ return QScriptConverter::toString(m_string);
+}
+
+quint64 QScriptStringPrivate::id() const
+{
+ return reinterpret_cast<quint32>(m_string);
+}
+
+#endif // qscriptstring_p_h
diff --git a/JavaScriptCore/qt/tests/qscriptstring/qscriptstring.pro b/JavaScriptCore/qt/tests/qscriptstring/qscriptstring.pro
new file mode 100644
index 0000000..5ad9b7c
--- /dev/null
+++ b/JavaScriptCore/qt/tests/qscriptstring/qscriptstring.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+TARGET = tst_qscriptstring
+QT += testlib
+include(../tests.pri)
+
+SOURCES += tst_qscriptstring.cpp
+
diff --git a/JavaScriptCore/qt/tests/qscriptstring/tst_qscriptstring.cpp b/JavaScriptCore/qt/tests/qscriptstring/tst_qscriptstring.cpp
new file mode 100644
index 0000000..ff31835
--- /dev/null
+++ b/JavaScriptCore/qt/tests/qscriptstring/tst_qscriptstring.cpp
@@ -0,0 +1,175 @@
+/*
+ Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef tst_qscriptstring_h
+#define tst_qscriptstring_h
+
+#include "qscriptengine.h"
+#include "qscriptstring.h"
+#include <QtCore/qhash.h>
+#include <QtTest/QtTest>
+
+class tst_QScriptString : public QObject {
+ Q_OBJECT
+
+public:
+ tst_QScriptString();
+ virtual ~tst_QScriptString();
+
+private slots:
+ void test();
+ void hash();
+ void toArrayIndex_data();
+ void toArrayIndex();
+};
+
+tst_QScriptString::tst_QScriptString()
+{
+}
+
+tst_QScriptString::~tst_QScriptString()
+{
+}
+
+void tst_QScriptString::test()
+{
+ QScriptEngine eng;
+ {
+ QScriptString str;
+ QVERIFY(!str.isValid());
+ QVERIFY(str == str);
+ QVERIFY(!(str != str));
+ QVERIFY(str.toString().isNull());
+
+ QScriptString str1(str);
+ QVERIFY(!str1.isValid());
+
+ QScriptString str2 = str;
+ QVERIFY(!str2.isValid());
+
+ QCOMPARE(str.toArrayIndex(), quint32(0xffffffff));
+ }
+ for (int x = 0; x < 2; ++x) {
+ QString ciao = QString::fromLatin1("ciao");
+ QScriptString str = eng.toStringHandle(ciao);
+ QVERIFY(str.isValid());
+ QVERIFY(str == str);
+ QVERIFY(!(str != str));
+ QCOMPARE(str.toString(), ciao);
+
+ QScriptString str1(str);
+ QCOMPARE(str, str1);
+
+ QScriptString str2 = str;
+ QCOMPARE(str, str2);
+
+ QScriptString str3 = eng.toStringHandle(ciao);
+ QVERIFY(str3.isValid());
+ QCOMPARE(str, str3);
+
+ eng.collectGarbage();
+
+ QVERIFY(str.isValid());
+ QCOMPARE(str.toString(), ciao);
+ QVERIFY(str1.isValid());
+ QCOMPARE(str1.toString(), ciao);
+ QVERIFY(str2.isValid());
+ QCOMPARE(str2.toString(), ciao);
+ QVERIFY(str3.isValid());
+ QCOMPARE(str3.toString(), ciao);
+ }
+ {
+ QScriptEngine* eng2 = new QScriptEngine;
+ QString one = QString::fromLatin1("one");
+ QString two = QString::fromLatin1("two");
+ QScriptString oneInterned = eng2->toStringHandle(one);
+ QCOMPARE(oneInterned.toString(), one);
+ QScriptString twoInterned = eng2->toStringHandle(two);
+ QCOMPARE(twoInterned.toString(), two);
+ QVERIFY(oneInterned != twoInterned);
+ QVERIFY(!(oneInterned == twoInterned));
+
+ delete eng2;
+ }
+}
+
+void tst_QScriptString::hash()
+{
+ QScriptEngine engine;
+ QHash<QScriptString, int> stringToInt;
+ QScriptString foo = engine.toStringHandle("foo");
+
+ QScriptString bar = engine.toStringHandle("bar");
+ QVERIFY(!stringToInt.contains(foo));
+ for (int i = 0; i < 1000000; ++i)
+ stringToInt.insert(foo, 123);
+ QCOMPARE(stringToInt.value(foo), 123);
+ QVERIFY(!stringToInt.contains(bar));
+ stringToInt.insert(bar, 456);
+ QCOMPARE(stringToInt.value(bar), 456);
+ QCOMPARE(stringToInt.value(foo), 123);
+}
+
+void tst_QScriptString::toArrayIndex_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<bool>("expectSuccess");
+ QTest::addColumn<quint32>("expectedIndex");
+ QTest::newRow("foo") << QString::fromLatin1("foo") << false << quint32(0xffffffff);
+ QTest::newRow("empty") << QString::fromLatin1("") << false << quint32(0xffffffff);
+ QTest::newRow("0") << QString::fromLatin1("0") << true << quint32(0);
+ QTest::newRow("00") << QString::fromLatin1("00") << false << quint32(0xffffffff);
+ QTest::newRow("1") << QString::fromLatin1("1") << true << quint32(1);
+ QTest::newRow("123") << QString::fromLatin1("123") << true << quint32(123);
+ QTest::newRow("-1") << QString::fromLatin1("-1") << false << quint32(0xffffffff);
+ QTest::newRow("0a") << QString::fromLatin1("0a") << false << quint32(0xffffffff);
+ QTest::newRow("0x1") << QString::fromLatin1("0x1") << false << quint32(0xffffffff);
+ QTest::newRow("01") << QString::fromLatin1("01") << false << quint32(0xffffffff);
+ QTest::newRow("101a") << QString::fromLatin1("101a") << false << quint32(0xffffffff);
+ QTest::newRow("4294967294") << QString::fromLatin1("4294967294") << true << quint32(0xfffffffe);
+ QTest::newRow("4294967295") << QString::fromLatin1("4294967295") << false << quint32(0xffffffff);
+ QTest::newRow("11111111111") << QString::fromLatin1("11111111111") << false << quint32(0xffffffff);
+ QTest::newRow("0.0") << QString::fromLatin1("0.0") << false << quint32(0xffffffff);
+ QTest::newRow("1.0") << QString::fromLatin1("1.0") << false << quint32(0xffffffff);
+ QTest::newRow("1.5") << QString::fromLatin1("1.5") << false << quint32(0xffffffff);
+ QTest::newRow("1.") << QString::fromLatin1("1.") << false << quint32(0xffffffff);
+ QTest::newRow(".1") << QString::fromLatin1(".1") << false << quint32(0xffffffff);
+ QTest::newRow("1e0") << QString::fromLatin1("1e0") << false << quint32(0xffffffff);
+}
+
+void tst_QScriptString::toArrayIndex()
+{
+ QFETCH(QString, input);
+ QFETCH(bool, expectSuccess);
+ QFETCH(quint32, expectedIndex);
+ QScriptEngine engine;
+ for (int x = 0; x < 2; ++x) {
+ bool isArrayIndex;
+ bool* ptr = (!x) ? &isArrayIndex : (bool*)0;
+ quint32 result = engine.toStringHandle(input).toArrayIndex(ptr);
+ if (!x)
+ QCOMPARE(isArrayIndex, expectSuccess);
+ QCOMPARE(result, expectedIndex);
+ }
+}
+
+QTEST_MAIN(tst_QScriptString)
+#include "tst_qscriptstring.moc"
+
+#endif // tst_qscriptstring_h
diff --git a/JavaScriptCore/qt/tests/tests.pro b/JavaScriptCore/qt/tests/tests.pro
index 6e5edb1..7c3f590 100644
--- a/JavaScriptCore/qt/tests/tests.pro
+++ b/JavaScriptCore/qt/tests/tests.pro
@@ -1,3 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = qscriptengine \
- qscriptvalue
+ qscriptvalue \
+ qscriptstring
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list