aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp24
-rw-r--r--src/qml/jsruntime/qv4runtime_p.h44
-rw-r--r--src/qml/jsruntime/qv4value.cpp1
-rw-r--r--src/qml/jsruntime/qv4value_inl_p.h22
4 files changed, 42 insertions, 49 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 38d46f3eea..f89a51fd85 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -729,10 +729,10 @@ Bool __qmljs_strict_equal(const ValueRef x, const ValueRef y)
QV4::Bool __qmljs_cmp_gt(const QV4::ValueRef l, const QV4::ValueRef r)
{
TRACE2(l, r);
- if (QV4::Value::integerCompatible(*l, *r))
+ if (l->isInteger() && r->isInteger())
return l->integerValue() > r->integerValue();
- if (QV4::Value::bothDouble(*l, *r))
- return l->doubleValue() > r->doubleValue();
+ if (l->isNumber() && r->isNumber())
+ return l->asDouble() > r->asDouble();
if (l->isString() && r->isString())
return r->stringValue()->compare(l->stringValue());
@@ -752,10 +752,10 @@ QV4::Bool __qmljs_cmp_gt(const QV4::ValueRef l, const QV4::ValueRef r)
QV4::Bool __qmljs_cmp_lt(const QV4::ValueRef l, const QV4::ValueRef r)
{
TRACE2(l, r);
- if (QV4::Value::integerCompatible(*l, *r))
+ if (l->isInteger() && r->isInteger())
return l->integerValue() < r->integerValue();
- if (QV4::Value::bothDouble(*l, *r))
- return l->doubleValue() < r->doubleValue();
+ if (l->isNumber() && r->isNumber())
+ return l->asDouble() < r->asDouble();
if (l->isString() && r->isString())
return l->stringValue()->compare(r->stringValue());
@@ -775,10 +775,10 @@ QV4::Bool __qmljs_cmp_lt(const QV4::ValueRef l, const QV4::ValueRef r)
QV4::Bool __qmljs_cmp_ge(const QV4::ValueRef l, const QV4::ValueRef r)
{
TRACE2(l, r);
- if (QV4::Value::integerCompatible(*l, *r))
+ if (l->isInteger() && r->isInteger())
return l->integerValue() >= r->integerValue();
- if (QV4::Value::bothDouble(*l, *r))
- return l->doubleValue() >= r->doubleValue();
+ if (l->isNumber() && r->isNumber())
+ return l->asDouble() >= r->asDouble();
if (l->isString() && r->isString())
return !l->stringValue()->compare(r->stringValue());
@@ -798,10 +798,10 @@ QV4::Bool __qmljs_cmp_ge(const QV4::ValueRef l, const QV4::ValueRef r)
QV4::Bool __qmljs_cmp_le(const QV4::ValueRef l, const QV4::ValueRef r)
{
TRACE2(l, r);
- if (QV4::Value::integerCompatible(*l, *r))
+ if (l->isInteger() && r->isInteger())
return l->integerValue() <= r->integerValue();
- if (QV4::Value::bothDouble(*l, *r))
- return l->doubleValue() <= r->doubleValue();
+ if (l->isNumber() && r->isNumber())
+ return l->asDouble() <= r->asDouble();
if (l->isString() && r->isString())
return !r->stringValue()->compare(l->stringValue());
diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h
index 3c2824ee23..1c34e554c3 100644
--- a/src/qml/jsruntime/qv4runtime_p.h
+++ b/src/qml/jsruntime/qv4runtime_p.h
@@ -350,11 +350,10 @@ inline QV4::ReturnedValue __qmljs_add(QV4::ExecutionContext *ctx, const QV4::Val
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(*left, *right))
+ if (left->isInteger() && right->isInteger())
return add_int32(left->integerValue(), right->integerValue()).asReturnedValue();
-
- if (QV4::Value::bothDouble(*left, *right))
- return QV4::Primitive::fromDouble(left->doubleValue() + right->doubleValue()).asReturnedValue();
+ if (left->isNumber() && right->isNumber())
+ return QV4::Primitive::fromDouble(left->asDouble() + right->asDouble()).asReturnedValue();
return __qmljs_add_helper(ctx, left, right);
}
@@ -363,11 +362,12 @@ inline QV4::ReturnedValue __qmljs_sub(const QV4::ValueRef left, const QV4::Value
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(*left, *right))
+ if (left->isInteger() && right->isInteger())
return sub_int32(left->integerValue(), right->integerValue()).asReturnedValue();
- double lval = __qmljs_to_number(left);
- double rval = __qmljs_to_number(right);
+ double lval = left->isNumber() ? left->asDouble() : left->toNumberImpl();
+ double rval = right->isNumber() ? right->asDouble() : right->toNumberImpl();
+
return QV4::Primitive::fromDouble(lval - rval).asReturnedValue();
}
@@ -375,11 +375,12 @@ inline QV4::ReturnedValue __qmljs_mul(const QV4::ValueRef left, const QV4::Value
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(*left, *right))
+ if (left->isInteger() && right->isInteger())
return mul_int32(left->integerValue(), right->integerValue()).asReturnedValue();
- double lval = __qmljs_to_number(left);
- double rval = __qmljs_to_number(right);
+ double lval = left->isNumber() ? left->asDouble() : left->toNumberImpl();
+ double rval = right->isNumber() ? right->asDouble() : right->toNumberImpl();
+
return QV4::Primitive::fromDouble(lval * rval).asReturnedValue();
}
@@ -387,8 +388,8 @@ inline QV4::ReturnedValue __qmljs_div(const QV4::ValueRef left, const QV4::Value
{
TRACE2(left, right);
- double lval = __qmljs_to_number(left);
- double rval = __qmljs_to_number(right);
+ double lval = left->toNumber();
+ double rval = right->toNumber();
return QV4::Primitive::fromDouble(lval / rval).asReturnedValue();
}
@@ -411,11 +412,8 @@ inline QV4::ReturnedValue __qmljs_shl(const QV4::ValueRef left, const QV4::Value
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(*left, *right))
- return Encode((int)(left->integerValue() << ((uint(right->integerValue()) & 0x1f))));
-
int lval = left->toInt32();
- unsigned rval = right->toUInt32() & 0x1f;
+ int rval = right->toInt32() & 0x1f;
return Encode((int)(lval << rval));
}
@@ -423,9 +421,6 @@ inline QV4::ReturnedValue __qmljs_shr(const QV4::ValueRef left, const QV4::Value
{
TRACE2(left, right);
- if (QV4::Value::integerCompatible(*left, *right))
- return Encode((int)(left->integerValue() >> ((uint(right->integerValue()) & 0x1f))));
-
int lval = left->toInt32();
unsigned rval = right->toUInt32() & 0x1f;
return Encode((int)(lval >> rval));
@@ -435,14 +430,9 @@ inline QV4::ReturnedValue __qmljs_ushr(const QV4::ValueRef left, const QV4::Valu
{
TRACE2(left, right);
- uint res;
- if (QV4::Value::integerCompatible(*left, *right)) {
- res = uint(left->integerValue()) >> (uint(right->integerValue()) & 0x1f);
- } else {
- unsigned lval = left->toUInt32();
- unsigned rval = right->toUInt32() & 0x1f;
- res = lval >> rval;
- }
+ unsigned lval = left->toUInt32();
+ unsigned rval = right->toUInt32() & 0x1f;
+ uint res = lval >> rval;
return Encode(res);
}
diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp
index c91084caee..a610f0b73a 100644
--- a/src/qml/jsruntime/qv4value.cpp
+++ b/src/qml/jsruntime/qv4value.cpp
@@ -98,6 +98,7 @@ double Value::toNumberImpl() const
case QV4::Value::Null_Type:
case QV4::Value::Boolean_Type:
case QV4::Value::Integer_Type:
+ return int_32;
default: // double
Q_UNREACHABLE();
}
diff --git a/src/qml/jsruntime/qv4value_inl_p.h b/src/qml/jsruntime/qv4value_inl_p.h
index d82af0643e..35508f442a 100644
--- a/src/qml/jsruntime/qv4value_inl_p.h
+++ b/src/qml/jsruntime/qv4value_inl_p.h
@@ -142,7 +142,7 @@ inline Primitive Primitive::fromUInt32(uint i)
inline double Value::toNumber() const
{
- if (integerCompatible())
+ if (isInteger())
return int_32;
if (isDouble())
return doubleValue();
@@ -151,13 +151,9 @@ inline double Value::toNumber() const
inline int Value::toInt32() const
{
- if (integerCompatible())
+ if (isInteger())
return int_32;
- double d;
- if (isDouble())
- d = doubleValue();
- else
- d = toNumberImpl();
+ double d = isNumber() ? doubleValue() : toNumberImpl();
const double D32 = 4294967296.0;
const double D31 = D32 / 2.0;
@@ -215,9 +211,15 @@ inline uint Value::asArrayIndex() const
inline uint Value::asArrayLength(bool *ok) const
{
*ok = true;
- if (integerCompatible() && int_32 >= 0)
- return (uint)int_32;
- if (isDouble()) {
+ if (isInteger()) {
+ if (int_32 >= 0) {
+ return (uint)int_32;
+ } else {
+ *ok = false;
+ return UINT_MAX;
+ }
+ }
+ if (isNumber()) {
double d = doubleValue();
uint idx = (uint)d;
if (idx != d) {