aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4runtime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4runtime.cpp')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp80
1 files changed, 56 insertions, 24 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 0a05c50432..60136a9bd9 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1,37 +1,44 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qv4global_p.h"
+#include "qv4engine_p.h"
#include "qv4runtime_p.h"
#ifndef V4_BOOTSTRAP
#include "qv4object_p.h"
@@ -43,6 +50,7 @@
#include "qv4dateobject_p.h"
#include "qv4lookup_p.h"
#include "qv4function_p.h"
+#include "qv4numberobject_p.h"
#include "private/qlocale_tools_p.h"
#include "qv4scopedvalue_p.h"
#include <private/qqmlcontextwrapper_p.h>
@@ -60,8 +68,6 @@
#include <wtf/MathExtras.h>
-#include "../../3rdparty/double-conversion/double-conversion.h"
-
#ifdef QV4_COUNT_RUNTIME_FUNCTIONS
# include <QtCore/QBuffer>
# include <QtCore/QDebug>
@@ -155,14 +161,14 @@ struct RuntimeCounters::Data {
buf.open(QIODevice::WriteOnly);
QTextStream outs(&buf);
QList<Line> lines;
- foreach (const char *func, counters.keys()) {
- const Counters &fCount = counters[func];
+ for (auto it = counters.cbegin(), end = counters.cend(); it != end; ++it) {
+ const Counters &fCount = it.value();
for (int i = 0, ei = fCount.size(); i != ei; ++i) {
quint64 count = fCount[i];
if (!count)
continue;
Line line;
- line.func = func;
+ line.func = it.key();
unmangle(i, line.tag1, line.tag2);
line.count = count;
lines.append(line);
@@ -220,16 +226,42 @@ void RuntimeHelpers::numberToString(QString *result, double num, int radix)
if (std::isnan(num)) {
*result = QStringLiteral("NaN");
return;
- } else if (qIsInf(num)) {
+ } else if (qt_is_inf(num)) {
*result = num < 0 ? QStringLiteral("-Infinity") : QStringLiteral("Infinity");
return;
}
if (radix == 10) {
- char str[100];
- double_conversion::StringBuilder builder(str, sizeof(str));
- double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToShortest(num, &builder);
- *result = QString::fromLatin1(builder.Finalize());
+ // We cannot use our usual locale->toString(...) here, because EcmaScript has special rules
+ // about the longest permissible number, depending on if it's <0 or >0.
+ const int ecma_shortest_low = -6;
+ const int ecma_shortest_high = 21;
+
+ const QLatin1Char zero('0');
+ const QLatin1Char dot('.');
+
+ int decpt = 0;
+ int sign = 0;
+ *result = qdtoa(num, &decpt, &sign);
+
+ if (decpt <= ecma_shortest_low || decpt > ecma_shortest_high) {
+ if (result->length() > 1)
+ result->insert(1, dot);
+ result->append(QLatin1Char('e'));
+ if (decpt > 0)
+ result->append(QLatin1Char('+'));
+ result->append(QString::number(decpt - 1));
+ } else if (decpt <= 0) {
+ result->prepend(QString::fromLatin1("0.%1").arg(QString().fill(zero, -decpt)));
+ } else if (decpt < result->length()) {
+ result->insert(decpt, dot);
+ } else {
+ result->append(QString().fill(zero, decpt - result->length()));
+ }
+
+ if (sign)
+ result->prepend(QLatin1Char('-'));
+
return;
}