aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-03-15 01:00:09 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-03-15 11:20:40 +0100
commit67cc0be410e0325ff5c8757684cacd02eea91572 (patch)
treed41a8a73b6792e6ebd70b94cd439d6b33bdcadda /src/qml/jsruntime
parent662c53dc583188d0278c86f59ab6b80056dbd419 (diff)
parentf10ac43ebb839b61315bd3b370b77683b625e4c4 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts: src/qml/compiler/qv4codegen.cpp Change-Id: I604517d0948fb5056ce36cc104f13ac956fbcc24
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4functiontable_win64.cpp2
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp38
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp21
3 files changed, 20 insertions, 41 deletions
diff --git a/src/qml/jsruntime/qv4functiontable_win64.cpp b/src/qml/jsruntime/qv4functiontable_win64.cpp
index bc5b24f6cd..fc13dc2602 100644
--- a/src/qml/jsruntime/qv4functiontable_win64.cpp
+++ b/src/qml/jsruntime/qv4functiontable_win64.cpp
@@ -43,7 +43,7 @@
#include <QtCore/qdebug.h>
-#include <Windows.h>
+#include <windows.h>
QT_BEGIN_NAMESPACE
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index d26e888069..13f6912371 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -223,41 +223,9 @@ ReturnedValue NumberPrototype::method_toString(const FunctionObject *b, const Va
return v4->throwError(QStringLiteral("Number.prototype.toString: %0 is not a valid radix").arg(radix));
}
- if (std::isnan(num)) {
- return Encode(v4->newString(QStringLiteral("NaN")));
- } else if (qt_is_inf(num)) {
- return Encode(v4->newString(QLatin1String(num < 0 ? "-Infinity" : "Infinity")));
- }
-
- if (radix != 10) {
- QString str;
- bool negative = false;
- if (num < 0) {
- negative = true;
- num = -num;
- }
- double frac = num - std::floor(num);
- num = Value::toInteger(num);
- do {
- char c = (char)std::fmod(num, radix);
- c = (c < 10) ? (c + '0') : (c - 10 + 'a');
- str.prepend(QLatin1Char(c));
- num = std::floor(num / radix);
- } while (num != 0);
- if (frac != 0) {
- str.append(QLatin1Char('.'));
- do {
- frac = frac * radix;
- char c = (char)std::floor(frac);
- c = (c < 10) ? (c + '0') : (c - 10 + 'a');
- str.append(QLatin1Char(c));
- frac = frac - std::floor(frac);
- } while (frac != 0);
- }
- if (negative)
- str.prepend(QLatin1Char('-'));
- return Encode(v4->newString(str));
- }
+ QString str;
+ RuntimeHelpers::numberToString(&str, num, radix);
+ return Encode(v4->newString(str));
}
return Encode(Value::fromDouble(num).toString(v4));
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 310fa5282e..9753ee4b1d 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -291,13 +291,22 @@ void RuntimeHelpers::numberToString(QString *result, double num, int radix)
if (frac != 0) {
result->append(QLatin1Char('.'));
+ double magnitude = 1;
+ double next = frac;
do {
- frac = frac * radix;
- char c = (char)::floor(frac);
+ next *= radix;
+ const int floored = ::floor(next);
+ char c = char(floored);
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
result->append(QLatin1Char(c));
- frac = frac - ::floor(frac);
- } while (frac != 0);
+ magnitude /= radix;
+ frac -= double(floored) * magnitude;
+ next -= double(floored);
+
+ // The next digit still makes a difference
+ // if a value of "radix" for it would change frac.
+ // Otherwise we've reached the limit of numerical precision.
+ } while (frac > 0 && frac - magnitude != frac);
}
if (negative)
@@ -1647,12 +1656,14 @@ ReturnedValue Runtime::TailCall::call(CppStackFrame *frame, ExecutionEngine *eng
const Value &thisObject = tos[StackOffsets::tailCall_thisObject];
Value *argv = reinterpret_cast<Value *>(frame->jsFrame) + tos[StackOffsets::tailCall_argv].int_32();
int argc = tos[StackOffsets::tailCall_argc].int_32();
+ Q_ASSERT(argc >= 0);
if (!function.isFunctionObject())
return engine->throwTypeError();
const FunctionObject &fo = static_cast<const FunctionObject &>(function);
- if (!frame->callerCanHandleTailCall || !fo.canBeTailCalled() || engine->debugger()) {
+ if (!frame->callerCanHandleTailCall || !fo.canBeTailCalled() || engine->debugger()
+ || unsigned(argc) > fo.formalParameterCount()) {
// Cannot tailcall, do a normal call:
return fo.call(&thisObject, argv, argc);
}