summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-02-18 11:36:32 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-02-18 16:35:34 (GMT)
commit0cad410d78758c79126d15664ec3d527883a9496 (patch)
tree8aaad705cd01e13755667d9edf2e13e75ec983fb /src
parentc86e7dfb0f6bcc0821ece5cf42a793d164d3f7a2 (diff)
downloadQt-0cad410d78758c79126d15664ec3d527883a9496.zip
Qt-0cad410d78758c79126d15664ec3d527883a9496.tar.gz
Qt-0cad410d78758c79126d15664ec3d527883a9496.tar.bz2
Cleanup: Move number conversion functions to QScriptEnginePrivate
Also rename ToUint{16,32} to ToUInt{16,32} to follow the Qt naming (it takes precedence over the ECMA one). Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'src')
-rw-r--r--src/script/api/qscriptengine.cpp72
-rw-r--r--src/script/api/qscriptengine_p.h5
-rw-r--r--src/script/api/qscriptvalue.cpp88
3 files changed, 81 insertions, 84 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 237b6fd..d8f7b3f 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -24,7 +24,6 @@
#include "config.h"
#include "qscriptengine.h"
#include "qscriptsyntaxchecker_p.h"
-#include "qnumeric.h"
#include "qscriptengine_p.h"
#include "qscriptengineagent_p.h"
@@ -41,6 +40,9 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qmetaobject.h>
+#include <QtCore/qnumeric.h>
+#include <math.h>
+
#include "Error.h"
#include "JSArray.h"
#include "JSLock.h"
@@ -328,6 +330,74 @@ public:
namespace QScript
{
+static const qsreal D32 = 4294967296.0;
+
+qint32 ToInt32(qsreal n)
+{
+ if (qIsNaN(n) || qIsInf(n) || (n == 0))
+ return 0;
+
+ qsreal sign = (n < 0) ? -1.0 : 1.0;
+ qsreal abs_n = fabs(n);
+
+ n = ::fmod(sign * ::floor(abs_n), D32);
+ const double D31 = D32 / 2.0;
+
+ if (sign == -1 && n < -D31)
+ n += D32;
+
+ else if (sign != -1 && n >= D31)
+ n -= D32;
+
+ return qint32 (n);
+}
+
+quint32 ToUInt32(qsreal n)
+{
+ if (qIsNaN(n) || qIsInf(n) || (n == 0))
+ return 0;
+
+ qsreal sign = (n < 0) ? -1.0 : 1.0;
+ qsreal abs_n = fabs(n);
+
+ n = ::fmod(sign * ::floor(abs_n), D32);
+
+ if (n < 0)
+ n += D32;
+
+ return quint32 (n);
+}
+
+quint16 ToUInt16(qsreal n)
+{
+ static const qsreal D16 = 65536.0;
+
+ if (qIsNaN(n) || qIsInf(n) || (n == 0))
+ return 0;
+
+ qsreal sign = (n < 0) ? -1.0 : 1.0;
+ qsreal abs_n = fabs(n);
+
+ n = ::fmod(sign * ::floor(abs_n), D16);
+
+ if (n < 0)
+ n += D16;
+
+ return quint16 (n);
+}
+
+qsreal ToInteger(qsreal n)
+{
+ if (qIsNaN(n))
+ return 0;
+
+ if (n == 0 || qIsInf(n))
+ return n;
+
+ int sign = n < 0 ? -1 : 1;
+ return sign * ::floor(::fabs(n));
+}
+
void GlobalClientData::mark(JSC::MarkStack& markStack)
{
engine->mark(markStack);
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h
index 9a357e5..f55dc27 100644
--- a/src/script/api/qscriptengine_p.h
+++ b/src/script/api/qscriptengine_p.h
@@ -83,6 +83,11 @@ namespace QScript
#endif
class TimeoutCheckerProxy;
+ qint32 ToInt32(qsreal);
+ quint32 ToUInt32(qsreal);
+ quint16 ToUInt16(qsreal);
+ qsreal ToInteger(qsreal);
+
//some conversion helper functions
inline QScriptEnginePrivate *scriptEngineFromExec(const JSC::ExecState *exec);
bool isFunction(JSC::JSValue value);
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp
index 1faade9..e8c2050 100644
--- a/src/script/api/qscriptvalue.cpp
+++ b/src/script/api/qscriptvalue.cpp
@@ -180,86 +180,8 @@
\omitvalue ResolveFull Check the object's own properties first, then search the prototype chain, and finally search the scope chain.
*/
-// ### move
-
-#include <QtCore/qnumeric.h>
-#include <math.h>
-
QT_BEGIN_NAMESPACE
-namespace QScript
-{
-
-static const qsreal D32 = 4294967296.0;
-
-qint32 ToInt32(qsreal n)
-{
- if (qIsNaN(n) || qIsInf(n) || (n == 0))
- return 0;
-
- qsreal sign = (n < 0) ? -1.0 : 1.0;
- qsreal abs_n = fabs(n);
-
- n = ::fmod(sign * ::floor(abs_n), D32);
- const double D31 = D32 / 2.0;
-
- if (sign == -1 && n < -D31)
- n += D32;
-
- else if (sign != -1 && n >= D31)
- n -= D32;
-
- return qint32 (n);
-}
-
-quint32 ToUint32(qsreal n)
-{
- if (qIsNaN(n) || qIsInf(n) || (n == 0))
- return 0;
-
- qsreal sign = (n < 0) ? -1.0 : 1.0;
- qsreal abs_n = fabs(n);
-
- n = ::fmod(sign * ::floor(abs_n), D32);
-
- if (n < 0)
- n += D32;
-
- return quint32 (n);
-}
-
-quint16 ToUint16(qsreal n)
-{
- static const qsreal D16 = 65536.0;
-
- if (qIsNaN(n) || qIsInf(n) || (n == 0))
- return 0;
-
- qsreal sign = (n < 0) ? -1.0 : 1.0;
- qsreal abs_n = fabs(n);
-
- n = ::fmod(sign * ::floor(abs_n), D16);
-
- if (n < 0)
- n += D16;
-
- return quint16 (n);
-}
-
-qsreal ToInteger(qsreal n)
-{
- if (qIsNaN(n))
- return 0;
-
- if (n == 0 || qIsInf(n))
- return n;
-
- int sign = n < 0 ? -1 : 1;
- return sign * ::floor(::fabs(n));
-}
-
-} // namespace QScript
-
QScriptValue QScriptValuePrivate::propertyHelper(const JSC::Identifier &id, int resolveMode) const
{
JSC::JSValue result;
@@ -1370,9 +1292,9 @@ quint32 QScriptValue::toUInt32() const
return result;
}
case QScriptValuePrivate::Number:
- return QScript::ToUint32(d->numberValue);
+ return QScript::ToUInt32(d->numberValue);
case QScriptValuePrivate::String:
- return QScript::ToUint32(((JSC::UString)d->stringValue).toDouble());
+ return QScript::ToUInt32(((JSC::UString)d->stringValue).toDouble());
}
return 0;
}
@@ -1397,12 +1319,12 @@ quint16 QScriptValue::toUInt16() const
switch (d->type) {
case QScriptValuePrivate::JavaScriptCore: {
// ### no equivalent function in JSC
- return QScript::ToUint16(toNumber());
+ return QScript::ToUInt16(toNumber());
}
case QScriptValuePrivate::Number:
- return QScript::ToUint16(d->numberValue);
+ return QScript::ToUInt16(d->numberValue);
case QScriptValuePrivate::String:
- return QScript::ToUint16(((JSC::UString)d->stringValue).toDouble());
+ return QScript::ToUInt16(((JSC::UString)d->stringValue).toDouble());
}
return 0;
}