diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-12 12:43:00 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-13 13:44:14 +0000 |
commit | f42207cbdb0cbe5e345bfd9e000b3e77b34a503c (patch) | |
tree | b43052cd9866eb7b4b098b3b763ee21913576b38 /src/qml/parser/qqmljsast.cpp | |
parent | cf0b965aaab0ea7e777c1f8e8d35de3a73d7d08e (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/qqmljsast.cpp')
-rw-r--r-- | src/qml/parser/qqmljsast.cpp | 22 |
1 files changed, 22 insertions, 0 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)) { |