aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-07-12 12:43:00 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-07-13 13:44:14 +0000
commitf42207cbdb0cbe5e345bfd9e000b3e77b34a503c (patch)
treeb43052cd9866eb7b4b098b3b763ee21913576b38 /src/qml/parser
parentcf0b965aaab0ea7e777c1f8e8d35de3a73d7d08e (diff)
Fix conversion of numeric literals in the AST to strings
After commit 91f3687ee51db83d9018bd61c3fbc736c6e9912e in qtbase, QString::number includes a zero padding in the exponent that breaks compliance with the ECMAScript tests. Instead of QString::number, we have to use a QLocale instance that turns off the padding of the exponent. Change-Id: Ib8c63bc501cadca026c52359006628f6c271ba6d Task-number: QTBUG-69432 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r--src/qml/parser/qqmljsast.cpp22
-rw-r--r--src/qml/parser/qqmljsast_p.h2
2 files changed, 23 insertions, 1 deletions
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index 34657a7d48..0d1b512c92 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -267,6 +267,28 @@ void NumericLiteralPropertyName::accept0(Visitor *visitor)
visitor->endVisit(this);
}
+namespace {
+struct LocaleWithoutZeroPadding : public QLocale
+{
+ LocaleWithoutZeroPadding()
+ : QLocale(QLocale::C)
+ {
+ setNumberOptions(QLocale::OmitLeadingZeroInExponent | QLocale::OmitGroupSeparator);
+ }
+};
+}
+
+QString NumericLiteralPropertyName::asString()const
+{
+ // Can't use QString::number here anymore as it does zero padding by default now.
+
+ // In C++11 this initialization is thread-safe (6.7 [stmt.dcl] p4)
+ static LocaleWithoutZeroPadding locale;
+ // Because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562 we can't use thread_local
+ // for the locale variable and therefore rely on toString(double) to be thread-safe.
+ return locale.toString(id, 'g', 16);
+}
+
void ArrayMemberExpression::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index ed3c83badf..9c5fd5adf6 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -760,7 +760,7 @@ public:
void accept0(Visitor *visitor) override;
- QString asString() const override { return QString::number(id, 'g', 16); }
+ QString asString() const override;
// attributes
double id;