return __qmljs_to_uint16(*this, ctx);
}
-int Value::toInt32(ExecutionContext *ctx)
-{
- if (isConvertibleToInt())
- return int_32;
-
- return Value::toInt32(__qmljs_to_number(*this, ctx));
-}
-
-unsigned int Value::toUInt32(ExecutionContext *ctx)
-{
- if (isConvertibleToInt())
- return (unsigned) int_32;
-
- return toUInt32(__qmljs_to_number(*this, ctx));
-}
-
Bool Value::toBoolean(ExecutionContext *ctx) const
{
return __qmljs_to_boolean(*this, ctx);
struct ArgumentsObject;
struct ExecutionContext;
struct ExecutionEngine;
+struct Value;
+
+extern "C" {
+double __qmljs_to_number(Value value, ExecutionContext *ctx);
+}
typedef uint Bool;
int toUInt16(ExecutionContext *ctx);
int toInt32(ExecutionContext *ctx);
unsigned int toUInt32(ExecutionContext *ctx);
+
Bool toBoolean(ExecutionContext *ctx) const;
double toInteger(ExecutionContext *ctx) const;
double toNumber(ExecutionContext *ctx) const;
return v;
}
+inline int Value::toInt32(ExecutionContext *ctx)
+{
+ if (isConvertibleToInt())
+ return int_32;
+ double d;
+ if (isDouble())
+ d = dbl;
+ else
+ d = __qmljs_to_number(*this, ctx);
+
+ const double D32 = 4294967296.0;
+ const double D31 = D32 / 2.0;
+
+ if ((d >= -D31 && d < D31))
+ return static_cast<int>(d);
+
+ return Value::toInt32(__qmljs_to_number(*this, ctx));
+}
+
+inline unsigned int Value::toUInt32(ExecutionContext *ctx) {
+ if (isConvertibleToInt())
+ return (unsigned) int_32;
+ double d;
+ if (isDouble())
+ d = dbl;
+ else
+ d = __qmljs_to_number(*this, ctx);
+
+ const double D32 = 4294967296.0;
+ if (dbl >= 0 && dbl < D32)
+ return static_cast<uint>(dbl);
+ return toUInt32(d);
+}
+
} // namespace VM
} // namespace QQmlJS